-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.utils.ts
30 lines (27 loc) · 1.16 KB
/
date.utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import moment from "moment"
export const secondsElapsedInPercent = (time: number): number => {
const now = moment(); //todays date
const end = moment(time * 1000 + 60 * 1000); // another date
const duration = moment.duration(end.diff(now));
const secondsLeft = duration.asSeconds();
const elapsed = 60 - (secondsLeft < 0 ? 0 : secondsLeft)
console.log('DateUtils', elapsed / 60)
return elapsed / 60
}
export const secondsElapsed = (time: number): number => {
const now = moment(); //todays date
const end = moment(time * 1000 + 60 * 1000); // another date
const duration = moment.duration(end.diff(now));
const secondsLeft = duration.asSeconds();
return 60 - (secondsLeft < 0 ? 0 : secondsLeft)
}
export const balanceElapsedInPercent = (time: number, total: number): number => {
const now = moment(); //todays date
const end = moment(time * 1000 + 60 * 1000); // another date
const duration = moment.duration(end.diff(now));
const secondsLeft = duration.asSeconds();
const elapsed = 60 - (secondsLeft < 0 ? 0 : secondsLeft)
console.log(now, end, elapsed)
const perSecond = total / 60
return (total - ((60 - elapsed) * perSecond)) / total
}