playbook_ui 12.39.0.pre.alpha.salesbookmismatchingdate1114 → 13.0.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: 53e1efed14125432de973864540db434bd15d7ca728af5bfd7facb459c42f3a5
4
- data.tar.gz: 8ea21f9bdf376162e82ab98a9d14b3f186e8438d81a979faa663ffad1f3b57f7
3
+ metadata.gz: 68b8019423c98f0b17cb991be96ff5eaf31f5ec127a81e1079f1d30d89bf2f8a
4
+ data.tar.gz: 266d1ba7ec9735ab40b632b590b448742429e780ef5635f92bd9e74b0e0fc6df
5
5
  SHA512:
6
- metadata.gz: 5b78591f4053df9f189134735a3689c5e010f823220d0217c65f222240a1aed961f8cdb79df3f91e771f7336717031dfd2594064388e3f9478549d0281f78724
7
- data.tar.gz: 93d06173adcc6db7672b2580de009a31d530c0135802524b0d5514d09939737230c38dd845f47c862a9be503eb6c42916372498afc5481d54f7c2afe495f6644
6
+ metadata.gz: b2a9a36c332c8f6cf8ced66861d01e6bccaf17d6ace709c3c1e3a180f89a145d8d4d98beecf8ba52cbdde6d41129238df73b0c364e9997ae4f225587a6d85c11
7
+ data.tar.gz: 4f42ad5ca624705aa6139ebf6b698ede8350fe94dd30fafbce662a433c6a898fd16ee47d22710ca648999c4bbd4ef9457458acc44c9c35f0d22823e84276d2bd
@@ -1,16 +1,26 @@
1
1
  /* eslint-disable no-console */
2
2
  import React from 'react'
3
- import moment from 'moment'
4
3
  import { fireEvent, render, screen, waitFor, within } from '../utilities/test-utils'
5
4
 
6
5
  import DatePicker from './_date_picker'
6
+ import DateTime from "../pb_kit/dateTime.ts"
7
7
  import { getTimezoneText } from './plugins/timeSelect'
8
8
 
9
-
10
-
11
9
  jest.setSystemTime(new Date('01/01/2020'));
12
10
  const DEFAULT_DATE = new Date()
13
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
+
17
+ return `${month}/${day}/${year}`
18
+ }
19
+
20
+ Date.prototype.formatDate = function () {
21
+ return formatDate(this)
22
+ }
23
+
14
24
  describe('DatePicker Kit', () => {
15
25
  beforeEach(() => {
16
26
  jest.spyOn(console, 'error').mockImplementation(() => { });
@@ -158,6 +168,7 @@ describe('DatePicker Kit', () => {
158
168
  expect(input).toHaveValue('01/01/2020 at 12:00 PM')
159
169
  })
160
170
  })
171
+
161
172
  test('shows DatePicker QuickPick dropdown and adds correct date to input', async () => {
162
173
  const testId = 'datepicker-quick-pick'
163
174
  render(
@@ -197,10 +208,10 @@ describe('DatePicker Kit', () => {
197
208
  )
198
209
 
199
210
  await waitFor(() => {
200
- expect(input).toHaveValue(moment().startOf('year').format('MM/DD/YYYY') + " to " + moment().endOf('year').format('MM/DD/YYYY'))
211
+ expect(input).toHaveValue(DateTime.getYearStartDate(new Date()).formatDate() + " to " + DateTime.getYearEndDate(new Date()).formatDate())
201
212
  })
202
-
203
213
  })
214
+
204
215
  test('shows DatePicker QuickPick ranges ending today', async () => {
205
216
  const testId = 'datepicker-quick-pick-ends-today'
206
217
  render(
@@ -225,7 +236,7 @@ describe('DatePicker Kit', () => {
225
236
  cancelable: true,
226
237
  }),
227
238
  )
228
-
239
+
229
240
  const thisYear = within(kit).getByText('This year')
230
241
 
231
242
  fireEvent(
@@ -237,8 +248,7 @@ describe('DatePicker Kit', () => {
237
248
  )
238
249
 
239
250
  await waitFor(() => {
240
- expect(input).toHaveValue(moment().startOf('year').format('MM/DD/YYYY') + " to " + moment().format('MM/DD/YYYY'))
251
+ expect(input).toHaveValue(DateTime.getYearStartDate(new Date()).formatDate() + " to " + new Date().formatDate())
241
252
  })
242
-
243
253
  })
244
254
  })
@@ -1,4 +1,4 @@
1
- import moment from 'moment'
1
+ import DateTime from '../../pb_kit/dateTime';
2
2
 
3
3
  type FpTypes = {
4
4
  setDate: (arg0: any, arg1: boolean) => void,
@@ -23,37 +23,44 @@ let activeLabel = ""
23
23
 
24
24
  const quickPickPlugin = (thisRangesEndToday: boolean) => {
25
25
  return function (fp: FpTypes & any): any {
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()
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())
30
48
 
31
49
  // variable that holds the ranges available
32
50
  const ranges = {
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
- ]
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]
55
61
  }
56
- //creating the ul element for the nav dropdown and giving it classnames
62
+
63
+ // creating the ul element for the nav dropdown and giving it classnames
57
64
  const rangesNav = document.createElement('ul');
58
65
 
59
66
  // creating the pluginData object that will hold the properties of this plugin
@@ -64,11 +71,11 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
64
71
  };
65
72
 
66
73
  /**
67
- * @param {string} label
68
- * @returns HTML Element
69
- */
74
+ * @param {string} label
75
+ * @returns HTML Element
76
+ */
70
77
 
71
- //function for creating the range buttons in the nav
78
+ // function for creating the range buttons in the nav
72
79
  const addRangeButton = (label: string) => {
73
80
 
74
81
  // creating new elements to mimick selectable card component
@@ -88,7 +95,7 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
88
95
  // append the li item to the ul rangeNav prop
89
96
  pluginData.rangesNav.appendChild(item);
90
97
 
91
- // return the ranges buton prop
98
+ // return the ranges button prop
92
99
  return pluginData.rangesButtons[label];
93
100
  };
94
101
 
@@ -98,7 +105,7 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
98
105
  if (current) {
99
106
  current.classList.remove('active');
100
107
  }
101
-
108
+
102
109
  if (selectedDates.length > 0 && activeLabel) {
103
110
  pluginData.rangesButtons[activeLabel].classList.add('active');
104
111
  }
@@ -109,16 +116,15 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
109
116
  selectedDates[1].toDateString() === pluginData.ranges[activeLabel][1].toDateString()
110
117
  }
111
118
 
112
-
113
119
  return {
114
- // onReady is a hook from flatpickr that runs when calender is in a ready state
120
+ // onReady is a hook from flatpickr that runs when calendar is in a ready state
115
121
  onReady(selectedDates: Array<Date>) {
116
122
  // 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
117
123
  for (const [label, range] of Object.entries(pluginData.ranges)) {
118
124
  addRangeButton(label).addEventListener('click', function () {
119
125
 
120
- const start = moment(range[0]).toDate();
121
- const end = moment(range[1]).toDate();
126
+ const start = new Date(range[0]);
127
+ const end = new Date(range[1]);
122
128
 
123
129
  if (!start) {
124
130
  fp.clear();
@@ -170,4 +176,4 @@ const quickPickPlugin = (thisRangesEndToday: boolean) => {
170
176
  };
171
177
  }
172
178
 
173
- export default quickPickPlugin;
179
+ 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
72
  if (timeZone) {
75
- const date = new Date(formatDate(newDate).toLocaleString(undefined, { timeZone }));
76
- return date.getFullYear()
73
+ const date = new Date(newDate.toLocaleString(undefined, { timeZone }));
74
+ return date.getUTCFullYear()
77
75
  } else {
78
- const date = formatDate(newDate)
79
- return date.getFullYear()
76
+ const date = new Date(newDate)
77
+ return date.getUTCFullYear()
80
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,12 +111,11 @@ 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 => {
124
-
125
119
  const startDate = formatDate(newDate).getTime()
126
120
  const endDate = new Date().getTime()
127
121
  const elapsedTime = endDate - startDate
@@ -159,6 +153,193 @@ export const toCustomFormat = (newDate: Date | string, format = 'month_day'): st
159
153
  }
160
154
  }
161
155
 
156
+ // For quickPick.tsx
157
+ // Yesterday
158
+ export const getYesterdayDate = (newDate: Date | string): Date => {
159
+ const today = formatDate(newDate)
160
+ const yesterday = new Date()
161
+ yesterday.setDate(today.getDate() - 1)
162
+
163
+ return yesterday
164
+ }
165
+
166
+ // Weeks
167
+ export const getFirstDayOfWeek = (newDate: Date | string): Date => {
168
+ const today = formatDate(newDate)
169
+ const dayOfWeek = today.getDay()
170
+ // Replicate Moment.js: Start of week (Monday) has a time of 00:00:00
171
+ const firstDayOfWeek = new Date(today.setHours(0, 0, 0))
172
+ const isSunday = dayOfWeek === 0
173
+
174
+ const daysToSubtract = isSunday ? 6 : (dayOfWeek - 1)
175
+ firstDayOfWeek.setDate(today.getDate() - daysToSubtract)
176
+
177
+ return firstDayOfWeek
178
+ }
179
+
180
+ export const getLastDayOfWeek = (newDate: Date | string): Date => {
181
+ const today = formatDate(newDate)
182
+ const dayOfWeek = today.getDay()
183
+ // Replicate Moment.js: End of week (Sunday) has a time of 23:59:59
184
+ const lastDayOfWeek = new Date(today.setHours(23, 59, 59, 0))
185
+ const isSunday = dayOfWeek === 0
186
+
187
+ const daysToAdd = isSunday ? 0 : (7 - dayOfWeek)
188
+ lastDayOfWeek.setDate(today.getDate() + daysToAdd)
189
+
190
+ return lastDayOfWeek
191
+ }
192
+
193
+ export const getPreviousWeekStartDate = (newDate: Date | string): Date => {
194
+ const firstDayOfWeek = getFirstDayOfWeek(newDate)
195
+ const firstDayOfPreviousWeek = new Date(
196
+ firstDayOfWeek.getFullYear(),
197
+ firstDayOfWeek.getMonth(),
198
+ firstDayOfWeek.getDate() - 7
199
+ )
200
+
201
+ return firstDayOfPreviousWeek
202
+ }
203
+
204
+ export const getPreviousWeekEndDate = (newDate: Date | string): Date => {
205
+ const lastDayOfWeek = getLastDayOfWeek(newDate)
206
+ const lastDayOfPreviousWeek = new Date(
207
+ lastDayOfWeek.getFullYear(),
208
+ lastDayOfWeek.getMonth(),
209
+ lastDayOfWeek.getDate() - 7,
210
+ lastDayOfWeek.getHours(),
211
+ lastDayOfWeek.getMinutes(),
212
+ lastDayOfWeek.getSeconds()
213
+ )
214
+
215
+ return lastDayOfPreviousWeek
216
+ }
217
+
218
+ // Months
219
+ export const getMonthStartDate = (newDate: Date | string): Date => {
220
+ const date = formatDate(newDate)
221
+ const firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1)
222
+
223
+ return firstDayOfMonth
224
+ }
225
+
226
+ export const getMonthEndDate = (newDate: Date | string): Date => {
227
+ const date = formatDate(newDate)
228
+ // Replicate Moment.js: End of month has a time of 23:59:59
229
+ const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59)
230
+
231
+ return lastDayOfMonth
232
+ }
233
+
234
+ export const getPreviousMonthStartDate = (newDate: Date | string): Date => {
235
+ const firstDayOfMonth = getMonthStartDate(newDate)
236
+ const firstDayOfPreviousMonth = new Date(
237
+ firstDayOfMonth.getFullYear(),
238
+ firstDayOfMonth.getMonth() - 1,
239
+ firstDayOfMonth.getDate()
240
+ )
241
+
242
+ return firstDayOfPreviousMonth
243
+ }
244
+
245
+ export const getPreviousMonthEndDate = (newDate: Date | string): Date => {
246
+ const lastDayOfMonth = getMonthEndDate(newDate)
247
+ const lastDayOfPreviousMonth = new Date(
248
+ lastDayOfMonth.getFullYear(),
249
+ lastDayOfMonth.getMonth() - 1,
250
+ lastDayOfMonth.getDate(),
251
+ lastDayOfMonth.getHours(),
252
+ lastDayOfMonth.getMinutes(),
253
+ lastDayOfMonth.getSeconds()
254
+ )
255
+
256
+ return lastDayOfPreviousMonth
257
+ }
258
+
259
+ // Quarters
260
+ export const getQuarterStartDate = (newDate: Date | string): Date => {
261
+ const date = formatDate(newDate)
262
+ const quarter = Math.floor(date.getMonth() / 3)
263
+ const startOfQuarter = new Date(date.getFullYear(), quarter * 3, 1)
264
+
265
+ return startOfQuarter
266
+ }
267
+
268
+ export const getQuarterEndDate = (newDate: Date | string): Date => {
269
+ const date = formatDate(newDate)
270
+ const quarter = Math.floor(date.getMonth() / 3)
271
+ const startOfNextQuarter = new Date(date.getFullYear(), (quarter + 1) * 3, 1)
272
+ // Replicate Moment.js: End of quarter has a time of 23:59:59
273
+ const endOfQuarter = new Date(startOfNextQuarter.getTime() - 1)
274
+
275
+ return endOfQuarter
276
+ }
277
+
278
+ export const getPreviousQuarterStartDate = (newDate: Date | string): Date => {
279
+ const startOfQuarter = getQuarterStartDate(newDate)
280
+ const firstDayOfPreviousQuarter = new Date(
281
+ startOfQuarter.getFullYear(),
282
+ startOfQuarter.getMonth() - 3,
283
+ startOfQuarter.getDate()
284
+ )
285
+
286
+ return firstDayOfPreviousQuarter
287
+ }
288
+
289
+ export const getPreviousQuarterEndDate = (newDate: Date | string): Date => {
290
+ const endOfQuarter = getQuarterEndDate(newDate)
291
+ const lastDayOfPreviousQuarter = new Date(
292
+ endOfQuarter.getFullYear(),
293
+ endOfQuarter.getMonth() - 3,
294
+ endOfQuarter.getDate(),
295
+ endOfQuarter.getHours(),
296
+ endOfQuarter.getMinutes(),
297
+ endOfQuarter.getSeconds()
298
+ )
299
+
300
+ return lastDayOfPreviousQuarter
301
+ }
302
+
303
+ // Years
304
+ export const getYearStartDate = (newDate: Date | string): Date => {
305
+ const date = formatDate(newDate)
306
+ const startOfYear = new Date(date.getFullYear(), 0, 1)
307
+
308
+ return startOfYear
309
+ }
310
+
311
+ export const getYearEndDate = (newDate: Date | string): Date => {
312
+ const date = formatDate(newDate)
313
+ const endOfYear = new Date(date.getFullYear(), 11, 31, 23, 59, 59)
314
+
315
+ return endOfYear
316
+ }
317
+
318
+ export const getPreviousYearStartDate = (newDate: Date | string): Date => {
319
+ const startOfYear = getYearStartDate(newDate)
320
+ const firstDayOfPreviousYear = new Date(
321
+ startOfYear.getFullYear() - 1,
322
+ startOfYear.getMonth(),
323
+ startOfYear.getDate()
324
+ )
325
+
326
+ return firstDayOfPreviousYear
327
+ }
328
+
329
+ export const getPreviousYearEndDate = (newDate: Date | string): Date => {
330
+ const endOfYear = getYearEndDate(newDate)
331
+ const lastDayOfPreviousYear = new Date(
332
+ endOfYear.getFullYear() - 1,
333
+ endOfYear.getMonth(),
334
+ endOfYear.getDate(),
335
+ endOfYear.getHours(),
336
+ endOfYear.getMinutes(),
337
+ endOfYear.getSeconds()
338
+ )
339
+
340
+ return lastDayOfPreviousYear
341
+ }
342
+
162
343
  export default {
163
344
  toMinute,
164
345
  toHour,
@@ -175,4 +356,21 @@ export default {
175
356
  toIso,
176
357
  fromNow,
177
358
  toCustomFormat,
359
+ getYesterdayDate,
360
+ getFirstDayOfWeek,
361
+ getLastDayOfWeek,
362
+ getPreviousWeekStartDate,
363
+ getPreviousWeekEndDate,
364
+ getMonthStartDate,
365
+ getMonthEndDate,
366
+ getPreviousMonthStartDate,
367
+ getPreviousMonthEndDate,
368
+ getQuarterStartDate,
369
+ getQuarterEndDate,
370
+ getPreviousQuarterStartDate,
371
+ getPreviousQuarterEndDate,
372
+ getYearStartDate,
373
+ getYearEndDate,
374
+ getPreviousYearStartDate,
375
+ getPreviousYearEndDate
178
376
  }
@@ -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
  ? (