mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-09-13 22:32:26 +03:00
initial commit
This commit is contained in:
commit
026f835a87
176 changed files with 10613 additions and 0 deletions
21
src/util/common.js
Normal file
21
src/util/common.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
export function bytesToSize(bytes) {
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
if (bytes === 0) return 'n/a';
|
||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
|
||||
if (i === 0) return `${bytes} ${sizes[i]}`;
|
||||
return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
export function diffMinutes(dt2, dt1) {
|
||||
let diff = (dt2.getTime() - dt1.getTime()) / 1000;
|
||||
diff /= 60;
|
||||
return Math.abs(Math.round(diff));
|
||||
}
|
||||
|
||||
export function isNotInSameDay(dt2, dt1) {
|
||||
return (
|
||||
dt2.getDay() !== dt1.getDay()
|
||||
|| dt2.getMonth() !== dt1.getMonth()
|
||||
|| dt2.getYear() !== dt1.getYear()
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue