MCPcopy Create free account
hub / github.com/coder/coder / buildDefaultPresets

Function buildDefaultPresets

site/src/components/DateRangePicker/DateRangePicker.tsx:30–78  ·  view source on GitHub ↗
(now?: Date)

Source from the content-addressed store, hash-verified

28}
29
30const buildDefaultPresets = (now?: Date): DateRangePreset[] => {
31 const getCurrentTime = () => dayjs(now ?? new Date());
32 return [
33 {
34 label: "Today",
35 range: () => {
36 const currentTime = getCurrentTime();
37 return { from: currentTime.toDate(), to: currentTime.toDate() };
38 },
39 },
40 {
41 label: "Yesterday",
42 range: () => {
43 const d = getCurrentTime().subtract(1, "day").toDate();
44 return { from: d, to: d };
45 },
46 },
47 {
48 label: "Last 7 days",
49 range: () => {
50 const currentTime = getCurrentTime();
51 return {
52 from: currentTime.subtract(6, "day").toDate(),
53 to: currentTime.toDate(),
54 };
55 },
56 },
57 {
58 label: "Last 14 days",
59 range: () => {
60 const currentTime = getCurrentTime();
61 return {
62 from: currentTime.subtract(13, "day").toDate(),
63 to: currentTime.toDate(),
64 };
65 },
66 },
67 {
68 label: "Last 30 days",
69 range: () => {
70 const currentTime = getCurrentTime();
71 return {
72 from: currentTime.subtract(29, "day").toDate(),
73 to: currentTime.toDate(),
74 };
75 },
76 },
77 ];
78};
79
80interface DateRangePickerProps {
81 value: DateRangeValue;

Callers 1

DateRangePickerFunction · 0.85

Calls 1

getCurrentTimeFunction · 0.85

Tested by

no test coverage detected