playbook_ui 12.39.0.pre.alpha.salesbookmismatchingdate1117 → 12.39.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6650ac3fb53a1c1a6d57ea4d4c08d61741e60c7aedd7149994b5f6a239a669e5
4
- data.tar.gz: 0b0a15f6fe4e1d400bc78b5b74638c3ac6be8c9ef0804773edde1a3711fef286
3
+ metadata.gz: 4474115903d0053dd049ba1fce7b6d33f1be8490a518e49a9422acf83427a6b0
4
+ data.tar.gz: 3b6259cc14efe5dbcc98c8cd23ca8d8befa087e6c1751c8062f4aa97b946b1aa
5
5
  SHA512:
6
- metadata.gz: 5eb5a4c90549d5f7f4dafb4455ff212573749b54c9734b09daa79a6a2d924587b820a8883fc6e340e31571515b935476e872344207b6e88b7be4f98ac1f25815
7
- data.tar.gz: 8986120162f91c579c0574dd70ef13fb0bc190b687548edd456b33e2d9ff4447c9b122bf431719376390a2dc49e21d6c8714c4b53da362204b908b01ccd2b3d0
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
- Date.prototype.formatDate = function () {
21
- return formatDate(this)
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(DateTime.getYearStartDate(new Date()).formatDate() + " to " + DateTime.getYearEndDate(new Date()).formatDate())
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(DateTime.getYearStartDate(new Date()).formatDate() + " to " + new Date().formatDate())
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 DateTime from '../../pb_kit/dateTime';
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 today = new Date()
27
- const yesterday = DateTime.getYesterdayDate(new Date())
28
-
29
- const thisWeekStartDate = DateTime.getFirstDayOfWeek(new Date())
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': [today, today],
52
- 'Yesterday': [yesterday, yesterday],
53
- 'This week': [thisWeekStartDate, thisWeekEndDate],
54
- 'This month': [thisMonthStartDate, thisMonthEndDate],
55
- 'This quarter': [thisQuarterStartDate, thisQuarterEndDate],
56
- 'This year': [thisYearStartDate, thisYearEndDate],
57
- 'Last week': [lastWeekStartDate, lastWeekEndDate],
58
- 'Last month': [lastMonthStartDate, lastMonthEndDate],
59
- 'Last quarter': [lastQuarterStartDate, lastQuarterEndDate],
60
- 'Last year': [lastYearStartDate, lastYearEndDate]
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
- * @param {string} label
75
- * @returns HTML Element
76
- */
67
+ * @param {string} label
68
+ * @returns HTML Element
69
+ */
77
70
 
78
- // function for creating the range buttons in the nav
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 button prop
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 calendar is in a ready state
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 = new Date(range[0]);
127
- const end = new Date(range[1]);
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
- if (timeZone) {
40
- const date = new Date(formatDate(newDate).toLocaleString(undefined, { timeZone }));
41
- return date.getDate()
42
- } else {
43
- const date = formatDate(newDate)
44
- return date.getDate()
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.getDay()]
48
+ return ABBR_DAYS[date.getUTCDay()]
51
49
  }
52
50
 
53
51
  export const toWeekday = (newDate: Date | string): string => {
54
- const date = formatDate(newDate)
55
- return days[date.getDay()]
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
- if (timeZone) {
60
- const date = new Date(formatDate(newDate).toLocaleString(undefined, { timeZone }));
61
- return months[date.getMonth()]
62
- } else {
63
- const date = formatDate(newDate)
64
- return months[date.getMonth()]
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.getMonth() + 1
68
+ return date.getUTCMonth() +1
71
69
  }
72
70
 
73
71
  export const toYear = (newDate: Date | string, timeZone?: string): number => {
74
- if (timeZone) {
75
- const date = new Date(formatDate(newDate).toLocaleString(undefined, { timeZone }));
76
- return date.getFullYear()
77
- } else {
78
- const date = formatDate(newDate)
79
- return date.getFullYear()
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
- const date = formatDate(newDate)
95
-
96
- if (timeZone) {
97
- return date.toLocaleString(undefined, { timeZone, hour12: true }).slice(-2).charAt(0).toLocaleLowerCase();
98
- } else {
99
- return date.toLocaleString(undefined, { hour12: true }).slice(-2).charAt(0).toLocaleLowerCase();
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
- const date = formatDate(newDate)
105
-
106
- if (timeZone) {
107
- return date.toLocaleString(undefined, { timeZone, timeZoneName: "short" }).split(' ')[3];
108
- } else {
109
- return date.toLocaleString(undefined, { timeZoneName: "short" }).split(' ')[3];
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
- const date = formatDate(newDate)
120
- return date.toISOString()
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`; // 730+ days
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 / MILLISECONDS_IN_A_MONTH)} months ago`}, // 60-319 days
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
  }
@@ -68,7 +68,7 @@ const Time = (props: TimeProps) => {
68
68
  )
69
69
  )}
70
70
 
71
- <time dateTime={date.toLocaleString()}>
71
+ <time dateTime={date.toString()}>
72
72
  <span>
73
73
  {unstyled
74
74
  ? (