forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.ts
More file actions
30 lines (26 loc) · 889 Bytes
/
date.ts
File metadata and controls
30 lines (26 loc) · 889 Bytes
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 { endOfMonth, endOfWeek, startOfMonth, startOfWeek, subMonths } from 'date-fns';
import startOfToday from 'date-fns/startOfToday';
export function todayLocalDate() {
return new Date().toLocaleDateString('en-US');
}
export function getToday(): number {
return startOfToday().getTime();
}
export const TodayRange = [new Date(), new Date()];
export const ThisWeekRange = [startOfWeek(new Date()), endOfWeek(new Date())];
export const ThisMonthRange = [startOfMonth(new Date()), endOfMonth(new Date())];
export const LatMonthRange = [
startOfMonth(subMonths(new Date(), 1)),
endOfMonth(subMonths(new Date(), 1)),
];
export function ranges() {
return [
{ label: 'Today', range: TodayRange },
{ label: 'This week', range: ThisWeekRange },
{ label: 'This month', range: ThisMonthRange },
{
label: 'Last month',
range: LatMonthRange,
},
];
}