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
31 lines (27 loc) · 1006 Bytes
/
date.ts
File metadata and controls
31 lines (27 loc) · 1006 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
31
import i18n from '../plugins/i18n';
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: i18n.global.t('today.message'), range: TodayRange },
{ label: i18n.global.t('week.message'), range: ThisWeekRange },
{ label: i18n.global.t('month.message'), range: ThisMonthRange },
{
label: i18n.global.t('lastMonth.message'),
range: LatMonthRange,
},
];
}