playbook_ui 12.39.0.pre.alpha.salesbookmismatchingdate1117 → 12.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +8 -18
- data/app/pb_kits/playbook/pb_date_picker/plugins/quickPick.tsx +39 -45
- data/app/pb_kits/playbook/pb_kit/dateTime.ts +42 -252
- data/app/pb_kits/playbook/pb_time/_time.tsx +1 -1
- data/dist/playbook-rails.js +279 -7
- data/lib/playbook/version.rb +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4474115903d0053dd049ba1fce7b6d33f1be8490a518e49a9422acf83427a6b0
|
4
|
+
data.tar.gz: 3b6259cc14efe5dbcc98c8cd23ca8d8befa087e6c1751c8062f4aa97b946b1aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be41e2bcd1e5eee5501a8142c22a6326f980baa0e9e6f939ee67330f56d478ccf92b390e4a59261a37daf69898611f6e30905e2a733efcc17115f2b03a2b22c1
|
7
|
+
data.tar.gz: 4630db5119496f55cf137a925dd54a989947fd9ae914d5574c4014082f9ff2f99bb2141e7ac73564ec5c5487cde472c796f09ffd61e1d6ddf7511ed6ed64e1d2
|
@@ -1,25 +1,15 @@
|
|
1
1
|
/* eslint-disable no-console */
|
2
2
|
import React from 'react'
|
3
|
+
import moment from 'moment'
|
3
4
|
import { fireEvent, render, screen, waitFor, within } from '../utilities/test-utils'
|
4
5
|
|
5
6
|
import DatePicker from './_date_picker'
|
6
|
-
import DateTime from "../pb_kit/dateTime.ts"
|
7
7
|
import { getTimezoneText } from './plugins/timeSelect'
|
8
8
|
|
9
|
-
jest.setSystemTime(new Date('01/01/2020'));
|
10
|
-
const DEFAULT_DATE = new Date()
|
11
|
-
|
12
|
-
const formatDate = (date) => {
|
13
|
-
const month = (date.getMonth() + 1).toString().padStart(2, "0")
|
14
|
-
const day = (date.getDate()).toString().padStart(2, "0")
|
15
|
-
const year = date.getFullYear()
|
16
9
|
|
17
|
-
return `${month}/${day}/${year}`
|
18
|
-
}
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
}
|
11
|
+
jest.setSystemTime(new Date('01/01/2020'));
|
12
|
+
const DEFAULT_DATE = new Date()
|
23
13
|
|
24
14
|
describe('DatePicker Kit', () => {
|
25
15
|
beforeEach(() => {
|
@@ -168,7 +158,6 @@ describe('DatePicker Kit', () => {
|
|
168
158
|
expect(input).toHaveValue('01/01/2020 at 12:00 PM')
|
169
159
|
})
|
170
160
|
})
|
171
|
-
|
172
161
|
test('shows DatePicker QuickPick dropdown and adds correct date to input', async () => {
|
173
162
|
const testId = 'datepicker-quick-pick'
|
174
163
|
render(
|
@@ -208,10 +197,10 @@ describe('DatePicker Kit', () => {
|
|
208
197
|
)
|
209
198
|
|
210
199
|
await waitFor(() => {
|
211
|
-
expect(input).toHaveValue(
|
200
|
+
expect(input).toHaveValue(moment().startOf('year').format('MM/DD/YYYY') + " to " + moment().endOf('year').format('MM/DD/YYYY'))
|
212
201
|
})
|
213
|
-
})
|
214
202
|
|
203
|
+
})
|
215
204
|
test('shows DatePicker QuickPick ranges ending today', async () => {
|
216
205
|
const testId = 'datepicker-quick-pick-ends-today'
|
217
206
|
render(
|
@@ -236,7 +225,7 @@ describe('DatePicker Kit', () => {
|
|
236
225
|
cancelable: true,
|
237
226
|
}),
|
238
227
|
)
|
239
|
-
|
228
|
+
|
240
229
|
const thisYear = within(kit).getByText('This year')
|
241
230
|
|
242
231
|
fireEvent(
|
@@ -248,7 +237,8 @@ describe('DatePicker Kit', () => {
|
|
248
237
|
)
|
249
238
|
|
250
239
|
await waitFor(() => {
|
251
|
-
expect(input).toHaveValue(
|
240
|
+
expect(input).toHaveValue(moment().startOf('year').format('MM/DD/YYYY') + " to " + moment().format('MM/DD/YYYY'))
|
252
241
|
})
|
242
|
+
|
253
243
|
})
|
254
244
|
})
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import moment from 'moment'
|
2
2
|
|
3
3
|
type FpTypes = {
|
4
4
|
setDate: (arg0: any, arg1: boolean) => void,
|
@@ -23,44 +23,37 @@ let activeLabel = ""
|
|
23
23
|
|
24
24
|
const quickPickPlugin = (thisRangesEndToday: boolean) => {
|
25
25
|
return function (fp: FpTypes & any): any {
|
26
|
-
const
|
27
|
-
const
|
28
|
-
|
29
|
-
const
|
30
|
-
const thisWeekEndDate = thisRangesEndToday ? new Date() : DateTime.getLastDayOfWeek(new Date())
|
31
|
-
const lastWeekStartDate = DateTime.getPreviousWeekStartDate(new Date())
|
32
|
-
const lastWeekEndDate = DateTime.getPreviousWeekEndDate(new Date())
|
33
|
-
|
34
|
-
const thisMonthStartDate = DateTime.getMonthStartDate(new Date())
|
35
|
-
const thisMonthEndDate = thisRangesEndToday ? new Date() : DateTime.getMonthEndDate(new Date())
|
36
|
-
const lastMonthStartDate = DateTime.getPreviousMonthStartDate(new Date())
|
37
|
-
const lastMonthEndDate = DateTime.getPreviousMonthEndDate(new Date())
|
38
|
-
|
39
|
-
const thisQuarterStartDate = DateTime.getQuarterStartDate(new Date())
|
40
|
-
const thisQuarterEndDate = thisRangesEndToday ? new Date() : DateTime.getQuarterEndDate(new Date())
|
41
|
-
const lastQuarterStartDate = DateTime.getPreviousQuarterStartDate(new Date())
|
42
|
-
const lastQuarterEndDate = DateTime.getPreviousQuarterEndDate(new Date())
|
43
|
-
|
44
|
-
const thisYearStartDate = DateTime.getYearStartDate(new Date())
|
45
|
-
const thisYearEndDate = thisRangesEndToday ? new Date() : DateTime.getYearEndDate(new Date())
|
46
|
-
const lastYearStartDate = DateTime.getPreviousYearStartDate(new Date())
|
47
|
-
const lastYearEndDate = DateTime.getPreviousYearEndDate(new Date())
|
26
|
+
const thisWeekEndDate = thisRangesEndToday ? new Date() : moment().endOf('isoWeek').toDate()
|
27
|
+
const thisMonthEndDate = thisRangesEndToday ? new Date() : moment().endOf('month').toDate()
|
28
|
+
const thisQuarterEndDate = thisRangesEndToday ? new Date() : moment().endOf('quarter').toDate()
|
29
|
+
const thisYearEndDate = thisRangesEndToday ? new Date() : moment().endOf('year').toDate()
|
48
30
|
|
49
31
|
// variable that holds the ranges available
|
50
32
|
const ranges = {
|
51
|
-
'Today': [
|
52
|
-
'Yesterday': [
|
53
|
-
'This week': [
|
54
|
-
'This month': [
|
55
|
-
'This quarter': [
|
56
|
-
'This year': [
|
57
|
-
'Last week': [
|
58
|
-
|
59
|
-
|
60
|
-
|
33
|
+
'Today': [new Date(), new Date()],
|
34
|
+
'Yesterday': [moment().subtract(1, 'days').toDate(), moment().subtract(1, 'days').toDate()],
|
35
|
+
'This week': [moment().startOf('isoWeek').toDate(), thisWeekEndDate],
|
36
|
+
'This month': [moment().startOf('month').toDate(), thisMonthEndDate],
|
37
|
+
'This quarter': [moment().startOf('quarter').toDate(), thisQuarterEndDate],
|
38
|
+
'This year': [moment().startOf('year').toDate(), thisYearEndDate],
|
39
|
+
'Last week': [
|
40
|
+
moment().subtract(1, 'week').startOf('isoWeek').toDate(),
|
41
|
+
moment().subtract(1, 'week').endOf('isoWeek').toDate()
|
42
|
+
],
|
43
|
+
'Last month': [
|
44
|
+
moment().subtract(1, 'month').startOf('month').toDate(),
|
45
|
+
moment().subtract(1, 'month').endOf('month').toDate()
|
46
|
+
],
|
47
|
+
'Last quarter': [
|
48
|
+
moment().subtract(1, 'quarter').startOf('quarter').toDate(),
|
49
|
+
moment().subtract(1, 'quarter').endOf('quarter').toDate()
|
50
|
+
],
|
51
|
+
'Last year': [
|
52
|
+
moment().subtract(1, 'year').startOf('year').toDate(),
|
53
|
+
moment().subtract(1, 'year').endOf('year').toDate()
|
54
|
+
]
|
61
55
|
}
|
62
|
-
|
63
|
-
// creating the ul element for the nav dropdown and giving it classnames
|
56
|
+
//creating the ul element for the nav dropdown and giving it classnames
|
64
57
|
const rangesNav = document.createElement('ul');
|
65
58
|
|
66
59
|
// creating the pluginData object that will hold the properties of this plugin
|
@@ -71,11 +64,11 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
|
|
71
64
|
};
|
72
65
|
|
73
66
|
/**
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
* @param {string} label
|
68
|
+
* @returns HTML Element
|
69
|
+
*/
|
77
70
|
|
78
|
-
//
|
71
|
+
//function for creating the range buttons in the nav
|
79
72
|
const addRangeButton = (label: string) => {
|
80
73
|
|
81
74
|
// creating new elements to mimick selectable card component
|
@@ -95,7 +88,7 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
|
|
95
88
|
// append the li item to the ul rangeNav prop
|
96
89
|
pluginData.rangesNav.appendChild(item);
|
97
90
|
|
98
|
-
// return the ranges
|
91
|
+
// return the ranges buton prop
|
99
92
|
return pluginData.rangesButtons[label];
|
100
93
|
};
|
101
94
|
|
@@ -105,7 +98,7 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
|
|
105
98
|
if (current) {
|
106
99
|
current.classList.remove('active');
|
107
100
|
}
|
108
|
-
|
101
|
+
|
109
102
|
if (selectedDates.length > 0 && activeLabel) {
|
110
103
|
pluginData.rangesButtons[activeLabel].classList.add('active');
|
111
104
|
}
|
@@ -116,15 +109,16 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
|
|
116
109
|
selectedDates[1].toDateString() === pluginData.ranges[activeLabel][1].toDateString()
|
117
110
|
}
|
118
111
|
|
112
|
+
|
119
113
|
return {
|
120
|
-
// onReady is a hook from flatpickr that runs when
|
114
|
+
// onReady is a hook from flatpickr that runs when calender is in a ready state
|
121
115
|
onReady(selectedDates: Array<Date>) {
|
122
116
|
// loop through the ranges and create an anchor tag for each range and add an event listener to set the date when user clicks on a date range
|
123
117
|
for (const [label, range] of Object.entries(pluginData.ranges)) {
|
124
118
|
addRangeButton(label).addEventListener('click', function () {
|
125
119
|
|
126
|
-
const start =
|
127
|
-
const end =
|
120
|
+
const start = moment(range[0]).toDate();
|
121
|
+
const end = moment(range[1]).toDate();
|
128
122
|
|
129
123
|
if (!start) {
|
130
124
|
fp.clear();
|
@@ -176,4 +170,4 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
|
|
176
170
|
};
|
177
171
|
}
|
178
172
|
|
179
|
-
export default quickPickPlugin;
|
173
|
+
export default quickPickPlugin;
|
@@ -17,7 +17,6 @@ const formatDate = (newDate: Date | string) => {
|
|
17
17
|
|
18
18
|
export const toMinute = (newDate: Date | string, timeZone?: string): string => {
|
19
19
|
const date = formatDate(newDate)
|
20
|
-
|
21
20
|
if (timeZone) {
|
22
21
|
return date.toLocaleTimeString(undefined, { timeZone, hour: "2-digit", minute: "2-digit" }).slice(3, 5);
|
23
22
|
} else {
|
@@ -27,7 +26,6 @@ export const toMinute = (newDate: Date | string, timeZone?: string): string => {
|
|
27
26
|
|
28
27
|
export const toHour = (newDate: Date | string, timeZone?: string): string => {
|
29
28
|
const date = formatDate(newDate)
|
30
|
-
|
31
29
|
if (timeZone) {
|
32
30
|
return date.toLocaleTimeString(undefined, { timeZone, hour: "numeric" }).split(' ')[0];
|
33
31
|
} else {
|
@@ -36,53 +34,52 @@ export const toHour = (newDate: Date | string, timeZone?: string): string => {
|
|
36
34
|
}
|
37
35
|
|
38
36
|
export const toDay = (newDate: Date | string, timeZone?: string): number => {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
if (timeZone) {
|
38
|
+
const date = new Date(formatDate(newDate).toLocaleString(undefined, { timeZone }));
|
39
|
+
return date.getDate()
|
40
|
+
} else {
|
41
|
+
const date = formatDate(newDate)
|
42
|
+
return date.getDate()
|
43
|
+
}
|
46
44
|
}
|
47
45
|
|
48
46
|
export const toDayAbbr = (newDate: Date | string): string => {
|
49
47
|
const date = formatDate(newDate)
|
50
|
-
return ABBR_DAYS[date.
|
48
|
+
return ABBR_DAYS[date.getUTCDay()]
|
51
49
|
}
|
52
50
|
|
53
51
|
export const toWeekday = (newDate: Date | string): string => {
|
54
|
-
|
55
|
-
|
52
|
+
const date = formatDate(newDate)
|
53
|
+
return days[date.getUTCDay()]
|
56
54
|
}
|
57
55
|
|
58
56
|
export const toMonth = (newDate: Date | string, timeZone?: string): string => {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
57
|
+
if (timeZone) {
|
58
|
+
const date = new Date(formatDate(newDate).toLocaleString(undefined, { timeZone }));
|
59
|
+
return months[date.getUTCMonth()]
|
60
|
+
} else {
|
61
|
+
const date = formatDate(newDate)
|
62
|
+
return months[date.getUTCMonth()]
|
63
|
+
}
|
66
64
|
}
|
67
65
|
|
68
66
|
export const toMonthNum = (newDate: Date | string): number => {
|
69
67
|
const date = formatDate(newDate)
|
70
|
-
return date.
|
68
|
+
return date.getUTCMonth() +1
|
71
69
|
}
|
72
70
|
|
73
71
|
export const toYear = (newDate: Date | string, timeZone?: string): number => {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
if (timeZone) {
|
73
|
+
const date = new Date(newDate.toLocaleString(undefined, { timeZone }));
|
74
|
+
return date.getUTCFullYear()
|
75
|
+
} else {
|
76
|
+
const date = new Date(newDate)
|
77
|
+
return date.getUTCFullYear()
|
78
|
+
}
|
81
79
|
}
|
82
80
|
|
83
81
|
export const toTime = (newDate: Date | string, timeZone?: string): string => {
|
84
82
|
const date = formatDate(newDate)
|
85
|
-
|
86
83
|
if (timeZone) {
|
87
84
|
return date.toLocaleTimeString(undefined, { timeZone, timeStyle: "short" }).split(' ')[0];
|
88
85
|
} else {
|
@@ -91,23 +88,21 @@ export const toTime = (newDate: Date | string, timeZone?: string): string => {
|
|
91
88
|
}
|
92
89
|
|
93
90
|
export const toMeridiem = (newDate: Date | string, timeZone?: string): string => {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
91
|
+
const date = formatDate(newDate)
|
92
|
+
if (timeZone) {
|
93
|
+
return date.toLocaleString(undefined, { timeZone, hour12: true }).slice(-2).charAt(0).toLocaleLowerCase();
|
94
|
+
} else {
|
95
|
+
return date.toLocaleString(undefined, { hour12: true }).slice(-2).charAt(0).toLocaleLowerCase();
|
96
|
+
}
|
101
97
|
}
|
102
98
|
|
103
99
|
export const toTimeZone = (newDate: Date | string, timeZone?: string): string => {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
}
|
100
|
+
const date = formatDate(newDate)
|
101
|
+
if (timeZone) {
|
102
|
+
return date.toLocaleString(undefined, { timeZone, timeZoneName: "short" }).split(' ')[3];
|
103
|
+
} else {
|
104
|
+
return date.toLocaleString(undefined, { timeZoneName: "short" }).split(' ')[3];
|
105
|
+
}
|
111
106
|
}
|
112
107
|
|
113
108
|
export const toTimeWithMeridiem = (newDate: Date | string, timeZone: string): string => {
|
@@ -116,17 +111,16 @@ export const toTimeWithMeridiem = (newDate: Date | string, timeZone: string): st
|
|
116
111
|
}
|
117
112
|
|
118
113
|
export const toIso = (newDate: Date | string): string => {
|
119
|
-
|
120
|
-
|
114
|
+
const date = formatDate(newDate)
|
115
|
+
return date.toISOString()
|
121
116
|
}
|
122
117
|
|
123
118
|
export const fromNow = (newDate: Date | string): string => {
|
119
|
+
|
124
120
|
const startDate = formatDate(newDate).getTime()
|
125
121
|
const endDate = new Date().getTime()
|
126
122
|
const elapsedTime = endDate - startDate
|
127
|
-
let elapsedTimeString = `${Math.round(elapsedTime / (365.25 * 24 * 60 * 60 * 1000))} years ago
|
128
|
-
|
129
|
-
const MILLISECONDS_IN_A_MONTH = 30.44 * 24 * 60 * 60 * 1000
|
123
|
+
let elapsedTimeString = `${Math.round(elapsedTime / (365.25 * 24 * 60 * 60 * 1000))} years ago.`; // 730+ days
|
130
124
|
|
131
125
|
const elapsedTimeData = [
|
132
126
|
{ min: 0, max: 44999, value: "a few seconds ago" }, // 0-44 seconds
|
@@ -137,7 +131,7 @@ export const fromNow = (newDate: Date | string): string => {
|
|
137
131
|
{ min: 75700000, max: 172899999, value: "a day ago" }, // 22-48 hours
|
138
132
|
{ min: 172900000, max: 2169999999, value: `${Math.round(elapsedTime / 86400000)} days ago`}, // 2-25 days
|
139
133
|
{ min: 2170000000, max: 5184999999, value: "a month ago"}, // 26-60 days
|
140
|
-
{ min: 5185000000, max: 27561699999, value: `${Math.round(elapsedTime /
|
134
|
+
{ min: 5185000000, max: 27561699999, value: `${Math.round(elapsedTime / 30.44 * 24 * 60 * 60 * 1000)} months ago`}, // 60-319 days
|
141
135
|
{ min: 27561700000, max: 63072999999, value: "a year ago"}, // 320-730 days
|
142
136
|
];
|
143
137
|
|
@@ -160,193 +154,6 @@ export const toCustomFormat = (newDate: Date | string, format = 'month_day'): st
|
|
160
154
|
}
|
161
155
|
}
|
162
156
|
|
163
|
-
// For quickPick.tsx
|
164
|
-
// Yesterday
|
165
|
-
export const getYesterdayDate = (newDate: Date | string): Date => {
|
166
|
-
const today = formatDate(newDate)
|
167
|
-
const yesterday = new Date()
|
168
|
-
yesterday.setDate(today.getDate() - 1)
|
169
|
-
|
170
|
-
return yesterday
|
171
|
-
}
|
172
|
-
|
173
|
-
// Weeks
|
174
|
-
export const getFirstDayOfWeek = (newDate: Date | string): Date => {
|
175
|
-
const today = formatDate(newDate)
|
176
|
-
const dayOfWeek = today.getDay()
|
177
|
-
// Replicate Moment.js: Start of week (Monday) has a time of 00:00:00
|
178
|
-
const firstDayOfWeek = new Date(today.setHours(0, 0, 0))
|
179
|
-
const isSunday = dayOfWeek === 0
|
180
|
-
|
181
|
-
const daysToSubtract = isSunday ? 6 : (dayOfWeek - 1)
|
182
|
-
firstDayOfWeek.setDate(today.getDate() - daysToSubtract)
|
183
|
-
|
184
|
-
return firstDayOfWeek
|
185
|
-
}
|
186
|
-
|
187
|
-
export const getLastDayOfWeek = (newDate: Date | string): Date => {
|
188
|
-
const today = formatDate(newDate)
|
189
|
-
const dayOfWeek = today.getDay()
|
190
|
-
// Replicate Moment.js: End of week (Sunday) has a time of 23:59:59
|
191
|
-
const lastDayOfWeek = new Date(today.setHours(23, 59, 59, 0))
|
192
|
-
const isSunday = dayOfWeek === 0
|
193
|
-
|
194
|
-
const daysToAdd = isSunday ? 0 : (7 - dayOfWeek)
|
195
|
-
lastDayOfWeek.setDate(today.getDate() + daysToAdd)
|
196
|
-
|
197
|
-
return lastDayOfWeek
|
198
|
-
}
|
199
|
-
|
200
|
-
export const getPreviousWeekStartDate = (newDate: Date | string): Date => {
|
201
|
-
const firstDayOfWeek = getFirstDayOfWeek(newDate)
|
202
|
-
const firstDayOfPreviousWeek = new Date(
|
203
|
-
firstDayOfWeek.getFullYear(),
|
204
|
-
firstDayOfWeek.getMonth(),
|
205
|
-
firstDayOfWeek.getDate() - 7
|
206
|
-
)
|
207
|
-
|
208
|
-
return firstDayOfPreviousWeek
|
209
|
-
}
|
210
|
-
|
211
|
-
export const getPreviousWeekEndDate = (newDate: Date | string): Date => {
|
212
|
-
const lastDayOfWeek = getLastDayOfWeek(newDate)
|
213
|
-
const lastDayOfPreviousWeek = new Date(
|
214
|
-
lastDayOfWeek.getFullYear(),
|
215
|
-
lastDayOfWeek.getMonth(),
|
216
|
-
lastDayOfWeek.getDate() - 7,
|
217
|
-
lastDayOfWeek.getHours(),
|
218
|
-
lastDayOfWeek.getMinutes(),
|
219
|
-
lastDayOfWeek.getSeconds()
|
220
|
-
)
|
221
|
-
|
222
|
-
return lastDayOfPreviousWeek
|
223
|
-
}
|
224
|
-
|
225
|
-
// Months
|
226
|
-
export const getMonthStartDate = (newDate: Date | string): Date => {
|
227
|
-
const date = formatDate(newDate)
|
228
|
-
const firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1)
|
229
|
-
|
230
|
-
return firstDayOfMonth
|
231
|
-
}
|
232
|
-
|
233
|
-
export const getMonthEndDate = (newDate: Date | string): Date => {
|
234
|
-
const date = formatDate(newDate)
|
235
|
-
// Replicate Moment.js: End of month has a time of 23:59:59
|
236
|
-
const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59)
|
237
|
-
|
238
|
-
return lastDayOfMonth
|
239
|
-
}
|
240
|
-
|
241
|
-
export const getPreviousMonthStartDate = (newDate: Date | string): Date => {
|
242
|
-
const firstDayOfMonth = getMonthStartDate(newDate)
|
243
|
-
const firstDayOfPreviousMonth = new Date(
|
244
|
-
firstDayOfMonth.getFullYear(),
|
245
|
-
firstDayOfMonth.getMonth() - 1,
|
246
|
-
firstDayOfMonth.getDate()
|
247
|
-
)
|
248
|
-
|
249
|
-
return firstDayOfPreviousMonth
|
250
|
-
}
|
251
|
-
|
252
|
-
export const getPreviousMonthEndDate = (newDate: Date | string): Date => {
|
253
|
-
const lastDayOfMonth = getMonthEndDate(newDate)
|
254
|
-
const lastDayOfPreviousMonth = new Date(
|
255
|
-
lastDayOfMonth.getFullYear(),
|
256
|
-
lastDayOfMonth.getMonth() - 1,
|
257
|
-
lastDayOfMonth.getDate(),
|
258
|
-
lastDayOfMonth.getHours(),
|
259
|
-
lastDayOfMonth.getMinutes(),
|
260
|
-
lastDayOfMonth.getSeconds()
|
261
|
-
)
|
262
|
-
|
263
|
-
return lastDayOfPreviousMonth
|
264
|
-
}
|
265
|
-
|
266
|
-
// Quarters
|
267
|
-
export const getQuarterStartDate = (newDate: Date | string): Date => {
|
268
|
-
const date = formatDate(newDate)
|
269
|
-
const quarter = Math.floor(date.getMonth() / 3)
|
270
|
-
const startOfQuarter = new Date(date.getFullYear(), quarter * 3, 1)
|
271
|
-
|
272
|
-
return startOfQuarter
|
273
|
-
}
|
274
|
-
|
275
|
-
export const getQuarterEndDate = (newDate: Date | string): Date => {
|
276
|
-
const date = formatDate(newDate)
|
277
|
-
const quarter = Math.floor(date.getMonth() / 3)
|
278
|
-
const startOfNextQuarter = new Date(date.getFullYear(), (quarter + 1) * 3, 1)
|
279
|
-
// Replicate Moment.js: End of quarter has a time of 23:59:59
|
280
|
-
const endOfQuarter = new Date(startOfNextQuarter.getTime() - 1)
|
281
|
-
|
282
|
-
return endOfQuarter
|
283
|
-
}
|
284
|
-
|
285
|
-
export const getPreviousQuarterStartDate = (newDate: Date | string): Date => {
|
286
|
-
const startOfQuarter = getQuarterStartDate(newDate)
|
287
|
-
const firstDayOfPreviousQuarter = new Date(
|
288
|
-
startOfQuarter.getFullYear(),
|
289
|
-
startOfQuarter.getMonth() - 3,
|
290
|
-
startOfQuarter.getDate()
|
291
|
-
)
|
292
|
-
|
293
|
-
return firstDayOfPreviousQuarter
|
294
|
-
}
|
295
|
-
|
296
|
-
export const getPreviousQuarterEndDate = (newDate: Date | string): Date => {
|
297
|
-
const endOfQuarter = getQuarterEndDate(newDate)
|
298
|
-
const lastDayOfPreviousQuarter = new Date(
|
299
|
-
endOfQuarter.getFullYear(),
|
300
|
-
endOfQuarter.getMonth() - 3,
|
301
|
-
endOfQuarter.getDate(),
|
302
|
-
endOfQuarter.getHours(),
|
303
|
-
endOfQuarter.getMinutes(),
|
304
|
-
endOfQuarter.getSeconds()
|
305
|
-
)
|
306
|
-
|
307
|
-
return lastDayOfPreviousQuarter
|
308
|
-
}
|
309
|
-
|
310
|
-
// Years
|
311
|
-
export const getYearStartDate = (newDate: Date | string): Date => {
|
312
|
-
const date = formatDate(newDate)
|
313
|
-
const startOfYear = new Date(date.getFullYear(), 0, 1)
|
314
|
-
|
315
|
-
return startOfYear
|
316
|
-
}
|
317
|
-
|
318
|
-
export const getYearEndDate = (newDate: Date | string): Date => {
|
319
|
-
const date = formatDate(newDate)
|
320
|
-
const endOfYear = new Date(date.getFullYear(), 11, 31, 23, 59, 59)
|
321
|
-
|
322
|
-
return endOfYear
|
323
|
-
}
|
324
|
-
|
325
|
-
export const getPreviousYearStartDate = (newDate: Date | string): Date => {
|
326
|
-
const startOfYear = getYearStartDate(newDate)
|
327
|
-
const firstDayOfPreviousYear = new Date(
|
328
|
-
startOfYear.getFullYear() - 1,
|
329
|
-
startOfYear.getMonth(),
|
330
|
-
startOfYear.getDate()
|
331
|
-
)
|
332
|
-
|
333
|
-
return firstDayOfPreviousYear
|
334
|
-
}
|
335
|
-
|
336
|
-
export const getPreviousYearEndDate = (newDate: Date | string): Date => {
|
337
|
-
const endOfYear = getYearEndDate(newDate)
|
338
|
-
const lastDayOfPreviousYear = new Date(
|
339
|
-
endOfYear.getFullYear() - 1,
|
340
|
-
endOfYear.getMonth(),
|
341
|
-
endOfYear.getDate(),
|
342
|
-
endOfYear.getHours(),
|
343
|
-
endOfYear.getMinutes(),
|
344
|
-
endOfYear.getSeconds()
|
345
|
-
)
|
346
|
-
|
347
|
-
return lastDayOfPreviousYear
|
348
|
-
}
|
349
|
-
|
350
157
|
export default {
|
351
158
|
toMinute,
|
352
159
|
toHour,
|
@@ -363,21 +170,4 @@ export default {
|
|
363
170
|
toIso,
|
364
171
|
fromNow,
|
365
172
|
toCustomFormat,
|
366
|
-
getYesterdayDate,
|
367
|
-
getFirstDayOfWeek,
|
368
|
-
getLastDayOfWeek,
|
369
|
-
getPreviousWeekStartDate,
|
370
|
-
getPreviousWeekEndDate,
|
371
|
-
getMonthStartDate,
|
372
|
-
getMonthEndDate,
|
373
|
-
getPreviousMonthStartDate,
|
374
|
-
getPreviousMonthEndDate,
|
375
|
-
getQuarterStartDate,
|
376
|
-
getQuarterEndDate,
|
377
|
-
getPreviousQuarterStartDate,
|
378
|
-
getPreviousQuarterEndDate,
|
379
|
-
getYearStartDate,
|
380
|
-
getYearEndDate,
|
381
|
-
getPreviousYearStartDate,
|
382
|
-
getPreviousYearEndDate
|
383
173
|
}
|