scdate 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -1,5 +1,1475 @@
1
- # scdate
1
+ # scDate
2
2
 
3
- Time zone free readable dates and times
3
+ **Date and time library for dealing with schedules.**
4
4
 
5
- _This package is in active pre-release development so there may be breaking changed until v1.0 is released._
5
+ [![github license](https://img.shields.io/github/license/ericvera/scdate.svg?style=flat-square)](https://github.com/ericvera/scdate/blob/master/LICENSE)
6
+ [![npm version](https://img.shields.io/npm/v/scdate.svg?style=flat-square)](https://npmjs.org/package/scdate)
7
+
8
+ Features:
9
+
10
+ - Supports dates, times, time stamps, and active weekdays
11
+ - Time zone required for operations only when relevant
12
+ - Serializable to simple ISO formatted strings
13
+
14
+ ## Design Decisions
15
+
16
+ ### ISO formatted values
17
+
18
+ A subset of [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) is used as the valid format for SDate, STime, and STimestamp. This was done to make the values human readable.
19
+
20
+ ### No seconds in time components
21
+
22
+ The library was designed with schedules in mind that do not require second or smaller granularity as such STime and STimestamp only provide minute granularity.
23
+
24
+ ## Time zones
25
+
26
+ For a list of valid time zones run `Intl.supportedValuesOf('timeZone')` in your environment.
27
+
28
+ # API Documentation
29
+
30
+ The following documentation is automatically generated from the code.
31
+
32
+ <!-- TSDOC_START -->
33
+
34
+ ## :toolbox: Functions
35
+
36
+ - [sDate](#gear-sdate)
37
+ - [getDateToday](#gear-getdatetoday)
38
+ - [getNextDateByWeekday](#gear-getnextdatebyweekday)
39
+ - [getPreviousDateByWeekday](#gear-getpreviousdatebyweekday)
40
+ - [getDateForFirstDayOfMonth](#gear-getdateforfirstdayofmonth)
41
+ - [getDateForLastDayOfMonth](#gear-getdateforlastdayofmonth)
42
+ - [getYearFromDate](#gear-getyearfromdate)
43
+ - [getMonthFromDate](#gear-getmonthfromdate)
44
+ - [getDateFromDate](#gear-getdatefromdate)
45
+ - [getWeekdayFromDate](#gear-getweekdayfromdate)
46
+ - [getTimeZonedDateFromDate](#gear-gettimezoneddatefromdate)
47
+ - [getDaysBetweenDates](#gear-getdaysbetweendates)
48
+ - [getFullDateString](#gear-getfulldatestring)
49
+ - [getShortDateString](#gear-getshortdatestring)
50
+ - [addDaysToDate](#gear-adddaystodate)
51
+ - [addMonthsToDate](#gear-addmonthstodate)
52
+ - [addYearsToDate](#gear-addyearstodate)
53
+ - [isSameDate](#gear-issamedate)
54
+ - [isBeforeDate](#gear-isbeforedate)
55
+ - [isSameDateOrBefore](#gear-issamedateorbefore)
56
+ - [isAfterDate](#gear-isafterdate)
57
+ - [isSameDateOrAfter](#gear-issamedateorafter)
58
+ - [isDateToday](#gear-isdatetoday)
59
+ - [areDatesInSameMonth](#gear-aredatesinsamemonth)
60
+ - [isDateInCurrentMonth](#gear-isdateincurrentmonth)
61
+ - [areDatesInSameYear](#gear-aredatesinsameyear)
62
+ - [isDateInCurrentYear](#gear-isdateincurrentyear)
63
+ - [sTime](#gear-stime)
64
+ - [getTimeNow](#gear-gettimenow)
65
+ - [getTimeAtMidnight](#gear-gettimeatmidnight)
66
+ - [getTimeFromMinutes](#gear-gettimefromminutes)
67
+ - [getHoursFromTime](#gear-gethoursfromtime)
68
+ - [get12HoursHoursStringFromTime](#gear-get12hourshoursstringfromtime)
69
+ - [getMinutesFromTime](#gear-getminutesfromtime)
70
+ - [getMinutesStringFromTime](#gear-getminutesstringfromtime)
71
+ - [get12HourTimeString](#gear-get12hourtimestring)
72
+ - [getTimeInMinutes](#gear-gettimeinminutes)
73
+ - [addMinutesToTime](#gear-addminutestotime)
74
+ - [isSameTime](#gear-issametime)
75
+ - [isAfterTime](#gear-isaftertime)
76
+ - [isSameTimeOrAfter](#gear-issametimeorafter)
77
+ - [isBeforeTime](#gear-isbeforetime)
78
+ - [isSameTimeOrBefore](#gear-issametimeorbefore)
79
+ - [isTimePM](#gear-istimepm)
80
+ - [sTimestamp](#gear-stimestamp)
81
+ - [getTimestampFromUTCMilliseconds](#gear-gettimestampfromutcmilliseconds)
82
+ - [getTimestampNow](#gear-gettimestampnow)
83
+ - [getTimestampFromDateAndTime](#gear-gettimestampfromdateandtime)
84
+ - [getTimeZonedDateFromTimestamp](#gear-gettimezoneddatefromtimestamp)
85
+ - [getSecondsToTimestamp](#gear-getsecondstotimestamp)
86
+ - [getDateFromTimestamp](#gear-getdatefromtimestamp)
87
+ - [getTimeFromTimestamp](#gear-gettimefromtimestamp)
88
+ - [getShortTimestampString](#gear-getshorttimestampstring)
89
+ - [addDaysToTimestamp](#gear-adddaystotimestamp)
90
+ - [addMinutesToTimestamp](#gear-addminutestotimestamp)
91
+ - [isSameTimestamp](#gear-issametimestamp)
92
+ - [isBeforeTimestamp](#gear-isbeforetimestamp)
93
+ - [isSameTimestampOrBefore](#gear-issametimestamporbefore)
94
+ - [isAfterTimestamp](#gear-isaftertimestamp)
95
+ - [isSameTimestampOrAfter](#gear-issametimestamporafter)
96
+ - [sWeekdays](#gear-sweekdays)
97
+ - [getWeekdaysFromWeekdayFlags](#gear-getweekdaysfromweekdayflags)
98
+ - [getWeekdaysWithAllIncluded](#gear-getweekdayswithallincluded)
99
+ - [getWeekdaysWithNoneIncluded](#gear-getweekdayswithnoneincluded)
100
+ - [shiftWeekdaysForward](#gear-shiftweekdaysforward)
101
+ - [filterWeekdaysForDates](#gear-filterweekdaysfordates)
102
+ - [addWeekdayToWeekdays](#gear-addweekdaytoweekdays)
103
+ - [doesWeekdaysIncludeWeekday](#gear-doesweekdaysincludeweekday)
104
+ - [doesWeekdaysHaveOverlapWithWeekdays](#gear-doesweekdayshaveoverlapwithweekdays)
105
+
106
+ ### :gear: sDate
107
+
108
+ Returns a new SDate instance.
109
+
110
+ | Function | Type |
111
+ | -------- | ---------------------------------- |
112
+ | `sDate` | `(date: string or SDate) => SDate` |
113
+
114
+ Parameters:
115
+
116
+ - `date`: An instance of SDate or a string in the YYYY-MM-DD format.
117
+
118
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L36)
119
+
120
+ ### :gear: getDateToday
121
+
122
+ Returns a new SDate instance with the current date in the given time zone.
123
+
124
+ | Function | Type |
125
+ | -------------- | ----------------------------- |
126
+ | `getDateToday` | `(timeZone: string) => SDate` |
127
+
128
+ Parameters:
129
+
130
+ - `timeZone`: The time zone to get the current date for. See
131
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
132
+
133
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L54)
134
+
135
+ ### :gear: getNextDateByWeekday
136
+
137
+ Returns a new SDate instance set to the next date after the provided date
138
+ that match the given weekday.
139
+
140
+ | Function | Type |
141
+ | ---------------------- | ---------------------------------------------------- |
142
+ | `getNextDateByWeekday` | `(date: string or SDate, weekday: Weekday) => SDate` |
143
+
144
+ Parameters:
145
+
146
+ - `date`: The date to start from (not included). It can be an SDate or a
147
+ string in the YYYY-MM-DD format.
148
+ - `weekday`: The weekday to find the next date for.
149
+
150
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L68)
151
+
152
+ ### :gear: getPreviousDateByWeekday
153
+
154
+ Returns a new SDate instance set to date that is before the provided date and
155
+ matches the given weekday.
156
+
157
+ | Function | Type |
158
+ | -------------------------- | ---------------------------------------------------- |
159
+ | `getPreviousDateByWeekday` | `(date: string or SDate, weekday: Weekday) => SDate` |
160
+
161
+ Parameters:
162
+
163
+ - `date`: The date to start from (not included).
164
+ - `weekday`: The weekday to find the previous date for. It can be an SDate
165
+ or a string in the YYYY-MM-DD format.
166
+
167
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L97)
168
+
169
+ ### :gear: getDateForFirstDayOfMonth
170
+
171
+ Returns a new SDate instance set to the first day of the month for the
172
+ provided date.
173
+
174
+ | Function | Type |
175
+ | --------------------------- | ---------------------------------- |
176
+ | `getDateForFirstDayOfMonth` | `(date: string or SDate) => SDate` |
177
+
178
+ Parameters:
179
+
180
+ - `date`: The date to get the first day of the month for. It can be an
181
+ SDate or a string in the YYYY-MM-DD format.
182
+
183
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L125)
184
+
185
+ ### :gear: getDateForLastDayOfMonth
186
+
187
+ Returns a new SDate instance set to the last day of the month for the
188
+ provided date.
189
+
190
+ | Function | Type |
191
+ | -------------------------- | ---------------------------------- |
192
+ | `getDateForLastDayOfMonth` | `(date: string or SDate) => SDate` |
193
+
194
+ Parameters:
195
+
196
+ - `date`: The date to get the last day of the month for. It can be an SDate
197
+ or a string in the YYYY-MM-DD format.
198
+
199
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L140)
200
+
201
+ ### :gear: getYearFromDate
202
+
203
+ Returns the year from the given date.
204
+
205
+ | Function | Type |
206
+ | ----------------- | ----------------------------------- |
207
+ | `getYearFromDate` | `(date: string or SDate) => number` |
208
+
209
+ Parameters:
210
+
211
+ - `date`: The date to get the year from. It can be an SDate or a string in
212
+ the YYYY-MM-DD format.
213
+
214
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L159)
215
+
216
+ ### :gear: getMonthFromDate
217
+
218
+ Returns the month from the given date. Returns a 0-index value (i.e. Janary
219
+ is 0 and December is 11) to match the result from native Date object.
220
+
221
+ | Function | Type |
222
+ | ------------------ | ----------------------------------- |
223
+ | `getMonthFromDate` | `(date: string or SDate) => number` |
224
+
225
+ Parameters:
226
+
227
+ - `date`: The date to get the month from. It can be an SDate or a string in
228
+ the YYYY-MM-DD format.
229
+
230
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L172)
231
+
232
+ ### :gear: getDateFromDate
233
+
234
+ Returns the day of the month from the given date.
235
+
236
+ | Function | Type |
237
+ | ----------------- | ----------------------------------- |
238
+ | `getDateFromDate` | `(date: string or SDate) => number` |
239
+
240
+ Parameters:
241
+
242
+ - `date`: The date to get the day from. It can be an SDate or a string in
243
+ the YYYY-MM-DD format.
244
+
245
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L184)
246
+
247
+ ### :gear: getWeekdayFromDate
248
+
249
+ Returns the day of the week from the given date (Sunday to Saturday / 0 to
250
+ 6).
251
+
252
+ | Function | Type |
253
+ | -------------------- | ----------------------------------- |
254
+ | `getWeekdayFromDate` | `(date: string or SDate) => number` |
255
+
256
+ Parameters:
257
+
258
+ - `date`: The date to get the weekday from. It can be an SDate or a string
259
+ in the YYYY-MM-DD format.
260
+
261
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L197)
262
+
263
+ ### :gear: getTimeZonedDateFromDate
264
+
265
+ Returns a native Date adjusted so that the local time of that date matches
266
+ the local time at the specified time zone.
267
+
268
+ | Function | Type |
269
+ | -------------------------- | --------------------------------------------------- |
270
+ | `getTimeZonedDateFromDate` | `(date: string or SDate, timeZone: string) => Date` |
271
+
272
+ Parameters:
273
+
274
+ - `date`: The date to get the time zoned date from. It can be an SDate or a
275
+ string in the YYYY-MM-DD format.
276
+ - `timeZone`: The time zone to adjust the date to. See
277
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
278
+
279
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L213)
280
+
281
+ ### :gear: getDaysBetweenDates
282
+
283
+ Returns the number of days between the first date to the second date. The
284
+ value is positive if the first date is before the second date, and negative
285
+ if the first date is after the second date. This accounts for calendar days
286
+ and not full 24-hour periods which could be different due to daylight saving
287
+ adjustments.
288
+
289
+ | Function | Type |
290
+ | --------------------- | ------------------------------------------------------------ |
291
+ | `getDaysBetweenDates` | `(date1: string or SDate, date2: string or SDate) => number` |
292
+
293
+ Parameters:
294
+
295
+ - `date1`: The first date to get the days between. It can be an SDate or a
296
+ string in the YYYY-MM-DD format.
297
+ - `date2`: The second date to get the days between. It can be an SDate or a
298
+ string in the YYYY-MM-DD format.
299
+
300
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L238)
301
+
302
+ ### :gear: getFullDateString
303
+
304
+ Returns a string representation that includes all of the date components of
305
+ the given date formatted according to the given locale.
306
+
307
+ | Function | Type |
308
+ | ------------------- | ------------------------------------------------------------ |
309
+ | `getFullDateString` | `(date: string or SDate, locale: LocalesArgument) => string` |
310
+
311
+ Parameters:
312
+
313
+ - `date`: The date to get the full string representation for. It can be an
314
+ SDate or a string in the YYYY-MM-DD format.
315
+ - `locale`: The locale to use for the string representation.
316
+
317
+ Examples:
318
+
319
+ ```ts
320
+ getFullDateString('2021-02-05', 'es')
321
+ //=> 'viernes, 5 de febrero de 2021'
322
+ ```
323
+
324
+ ```ts
325
+ getFullDateString('2021-02-05', 'en')
326
+ //=> 'Friday, February 5, 2021'
327
+ ```
328
+
329
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L271)
330
+
331
+ ### :gear: getShortDateString
332
+
333
+ Get the short string representation of the given date in the given locale.
334
+
335
+ | Function | Type |
336
+ | -------------------- | ---------------------------------------------------------------------------------------------------------------- |
337
+ | `getShortDateString` | `(date: string or SDate, timeZone: string, locale: LocalesArgument, options: SDateShortStringOptions) => string` |
338
+
339
+ Parameters:
340
+
341
+ - `date`: The date to get the short string representation for. It can be an
342
+ SDate or a string in the YYYY-MM-DD format.
343
+ - `timeZone`: The time zone used to determine if in the current year. See
344
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
345
+ - `locale`: The locale to use for the string representation.
346
+ - `options`: The options to customize the short string representation.
347
+
348
+ Examples:
349
+
350
+ ```ts
351
+ getShortDateString('2021-02-05', TestLocalTimeZone, 'en', {
352
+ onTodayText,
353
+ includeWeekday: false,
354
+ }),
355
+ //=> 'Feb 5' (year is not shown when in the current year)
356
+ ```
357
+
358
+ ```ts
359
+ getShortDateString('2021-02-05', TestLocalTimeZone, 'es', {
360
+ onTodayText,
361
+ includeWeekday: true,
362
+ })
363
+ //=> 'vie, 5 feb 21' (year when not in current year)
364
+ ```
365
+
366
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L312)
367
+
368
+ ### :gear: addDaysToDate
369
+
370
+ Returns a new SDates instance with the date resulting from adding the given
371
+ number of days to the given date. Because it adds calendar days rather than
372
+ 24-hour days, this operation is not affected by time zones.
373
+
374
+ | Function | Type |
375
+ | --------------- | ------------------------------------------------ |
376
+ | `addDaysToDate` | `(date: string or SDate, days: number) => SDate` |
377
+
378
+ Parameters:
379
+
380
+ - `date`: The date to add days to. It can be an SDate or a string in the
381
+ YYYY-MM-DD format.
382
+ - `days`: The number of days to add to the date.
383
+
384
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L349)
385
+
386
+ ### :gear: addMonthsToDate
387
+
388
+ Returns a new SDate instance with the date resulting from adding the given
389
+ number of months to the given date. Because it just adds to the month
390
+ component of the date, this operation is not affected by time zones.
391
+
392
+ | Function | Type |
393
+ | ----------------- | -------------------------------------------------- |
394
+ | `addMonthsToDate` | `(date: string or SDate, months: number) => SDate` |
395
+
396
+ Parameters:
397
+
398
+ - `date`: The date to add months to. It can be an SDate or a string in the
399
+ YYYY-MM-DD format.
400
+ - `months`: The number of months to add to the date.
401
+
402
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L367)
403
+
404
+ ### :gear: addYearsToDate
405
+
406
+ Returns a new SDate instance with the date resulting from adding the given
407
+ number of years to the given date. Because this only adds to the year
408
+ component of the date, this method is not affected by leap years.
409
+
410
+ | Function | Type |
411
+ | ---------------- | ------------------------------------------------- |
412
+ | `addYearsToDate` | `(date: string or SDate, years: number) => SDate` |
413
+
414
+ Parameters:
415
+
416
+ - `date`: The date to add years to. It can be an SDate or a string in the
417
+ YYYY-MM-DD format.
418
+ - `years`: The number of years to add to the date.
419
+
420
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L388)
421
+
422
+ ### :gear: isSameDate
423
+
424
+ Returns true when the two given dates represent the same day and false
425
+ otherwise.
426
+
427
+ | Function | Type |
428
+ | ------------ | ------------------------------------------------------------- |
429
+ | `isSameDate` | `(date1: string or SDate, date2: string or SDate) => boolean` |
430
+
431
+ Parameters:
432
+
433
+ - `date1`: The first date to compare. It can be an SDate or a string in the
434
+ YYYY-MM-DD format.
435
+ - `date2`: The second date to compare. It can be an SDate or a string in
436
+ the YYYY-MM-DD format.
437
+
438
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L410)
439
+
440
+ ### :gear: isBeforeDate
441
+
442
+ Returns true when the first date represents a date before the second date and
443
+ false otherwise.
444
+
445
+ | Function | Type |
446
+ | -------------- | ------------------------------------------------------------- |
447
+ | `isBeforeDate` | `(date1: string or SDate, date2: string or SDate) => boolean` |
448
+
449
+ Parameters:
450
+
451
+ - `date1`: The first date to compare. It can be an SDate or a string in the
452
+ YYYY-MM-DD format.
453
+ - `date2`: The second date to compare. It can be an SDate or a string in
454
+ the YYYY-MM-DD format.
455
+
456
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L429)
457
+
458
+ ### :gear: isSameDateOrBefore
459
+
460
+ Returns true when the first date represents a date that happens on the same
461
+ date or before the second date and false otherwise.
462
+
463
+ | Function | Type |
464
+ | -------------------- | ------------------------------------------------------------- |
465
+ | `isSameDateOrBefore` | `(date1: string or SDate, date2: string or SDate) => boolean` |
466
+
467
+ Parameters:
468
+
469
+ - `date1`: The first date to compare. It can be an SDate or a string in the
470
+ YYYY-MM-DD format.
471
+ - `date2`: The second date to compare. It can be an SDate or a string in the
472
+ the YYYY-MM-DD format.
473
+
474
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L448)
475
+
476
+ ### :gear: isAfterDate
477
+
478
+ Returns true when the first date represents a date that happens after the
479
+ second date and false otherwise.
480
+
481
+ | Function | Type |
482
+ | ------------- | ------------------------------------------------------------- |
483
+ | `isAfterDate` | `(date1: string or SDate, date2: string or SDate) => boolean` |
484
+
485
+ Parameters:
486
+
487
+ - `date1`: The first date to compare. It can be an SDate or a string in the
488
+ YYYY-MM-DD format.
489
+ - `date2`: The second date to compare. It can be an SDate or a string in the
490
+ the YYYY-MM-DD format.
491
+
492
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L467)
493
+
494
+ ### :gear: isSameDateOrAfter
495
+
496
+ Returns true when the first date represents a date that happens on the same
497
+ date or after the second date and false otherwise.
498
+
499
+ | Function | Type |
500
+ | ------------------- | ------------------------------------------------------------- |
501
+ | `isSameDateOrAfter` | `(date1: string or SDate, date2: string or SDate) => boolean` |
502
+
503
+ Parameters:
504
+
505
+ - `date1`: The first date to compare. It can be an SDate or a string in the
506
+ YYYY-MM-DD format.
507
+ - `date2`: The second date to compare. It can be an SDate or a string in the
508
+ the YYYY-MM-DD format.
509
+
510
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L486)
511
+
512
+ ### :gear: isDateToday
513
+
514
+ Returns true when the date is today and false otherwise.
515
+
516
+ | Function | Type |
517
+ | ------------- | ------------------------------------------------------ |
518
+ | `isDateToday` | `(date: string or SDate, timeZone: string) => boolean` |
519
+
520
+ Parameters:
521
+
522
+ - `date`: The date to check if it is today. It can be an SDate or a string
523
+ in the YYYY-MM-DD format.
524
+ - `timeZone`: The time zone to check if the date is today. See
525
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
526
+
527
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L504)
528
+
529
+ ### :gear: areDatesInSameMonth
530
+
531
+ Returns true when the month on the first date is the same as the month on the
532
+ second date. It also checks that the year is the same. Returns false
533
+ otherwise.
534
+
535
+ | Function | Type |
536
+ | --------------------- | ------------------------------------------------------------- |
537
+ | `areDatesInSameMonth` | `(date1: string or SDate, date2: string or SDate) => boolean` |
538
+
539
+ Parameters:
540
+
541
+ - `date1`: The first date to compare. It can be an SDate or a string in the
542
+ YYYY-MM-DD format.
543
+ - `date2`: The second date to compare. It can be an SDate or a string in
544
+ the YYYY-MM-DD format.
545
+
546
+ Examples:
547
+
548
+ ```ts
549
+ areDatesInSameMonth('2021-02-05', '2021-02-15')
550
+ //=> true
551
+ ```
552
+
553
+ ```ts
554
+ areDatesInSameMonth('2022-02-05', '2023-02-15')
555
+ //=> false (different years)
556
+ ```
557
+
558
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L535)
559
+
560
+ ### :gear: isDateInCurrentMonth
561
+
562
+ Returns true when the date represents a date in the current month and year.
563
+ Returns false otherwise.
564
+
565
+ | Function | Type |
566
+ | ---------------------- | ------------------------------------------------------ |
567
+ | `isDateInCurrentMonth` | `(date: string or SDate, timeZone: string) => boolean` |
568
+
569
+ Parameters:
570
+
571
+ - `date`: The date to check if it is in the current month. It can be an
572
+ SDate or a string in the YYYY-MM-DD format.
573
+ - `timeZone`: The time zone to check if the date is in the current month.
574
+ See `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
575
+
576
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L557)
577
+
578
+ ### :gear: areDatesInSameYear
579
+
580
+ Returns true when the year of the first date is the same as the year on the
581
+ second date. Returns false otherwise.
582
+
583
+ | Function | Type |
584
+ | -------------------- | ------------------------------------------------------------- |
585
+ | `areDatesInSameYear` | `(date1: string or SDate, date2: string or SDate) => boolean` |
586
+
587
+ Parameters:
588
+
589
+ - `date1`: The first date to compare. It can be an SDate or a string in the
590
+ YYYY-MM-DD format.
591
+ - `date2`: The second date to compare. It can be an SDate or a string in
592
+ the YYYY-MM-DD format.
593
+
594
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L575)
595
+
596
+ ### :gear: isDateInCurrentYear
597
+
598
+ Returns true when the year component of the date matches the current year in
599
+ the given time zone. Returns false otherwise.
600
+
601
+ | Function | Type |
602
+ | --------------------- | ------------------------------------------------------ |
603
+ | `isDateInCurrentYear` | `(date: string or SDate, timeZone: string) => boolean` |
604
+
605
+ Parameters:
606
+
607
+ - `date`: The date to check if it is in the current year. It can be an
608
+ SDate or a string in the YYYY-MM-DD format.
609
+ - `timeZone`: The time zone to check if the date is in the current year.
610
+ See `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
611
+
612
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sDate.ts#L596)
613
+
614
+ ### :gear: sTime
615
+
616
+ Returns a new STime instance.
617
+
618
+ | Function | Type |
619
+ | -------- | ---------------------------------- |
620
+ | `sTime` | `(time: string or STime) => STime` |
621
+
622
+ Parameters:
623
+
624
+ - `time`: And instance of STime or a string in the format 'HH:MM'.
625
+
626
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L19)
627
+
628
+ ### :gear: getTimeNow
629
+
630
+ Returns a new STime instance with the current time in the given time zone.
631
+
632
+ | Function | Type |
633
+ | ------------ | ----------------------------- |
634
+ | `getTimeNow` | `(timeZone: string) => STime` |
635
+
636
+ Parameters:
637
+
638
+ - `timeZone`: The time zone to get the current time in. See
639
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
640
+
641
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L37)
642
+
643
+ ### :gear: getTimeAtMidnight
644
+
645
+ Returns a new STime instance with the time at midnight (00:00).
646
+
647
+ | Function | Type |
648
+ | ------------------- | ------------- |
649
+ | `getTimeAtMidnight` | `() => STime` |
650
+
651
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L46)
652
+
653
+ ### :gear: getTimeFromMinutes
654
+
655
+ Returns a new STime instance with the time resulting from adding the given
656
+ number of minutes to midnight (00:00).
657
+
658
+ | Function | Type |
659
+ | -------------------- | ---------------------------------- |
660
+ | `getTimeFromMinutes` | `(timeInMinutes: number) => STime` |
661
+
662
+ Parameters:
663
+
664
+ - `timeInMinutes`: The number of minutes to add to midnight.
665
+
666
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L54)
667
+
668
+ ### :gear: getHoursFromTime
669
+
670
+ Returns the hours from the given time.
671
+
672
+ | Function | Type |
673
+ | ------------------ | ----------------------------------- |
674
+ | `getHoursFromTime` | `(time: string or STime) => number` |
675
+
676
+ Parameters:
677
+
678
+ - `time`: The time to get the hours from. It can be an STime or a string
679
+ in the HH:MM format.
680
+
681
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L70)
682
+
683
+ ### :gear: get12HoursHoursStringFromTime
684
+
685
+ Returns the hours from given time as a string (1 - 12).
686
+
687
+ | Function | Type |
688
+ | ------------------------------- | ----------------------------------- |
689
+ | `get12HoursHoursStringFromTime` | `(time: string or STime) => string` |
690
+
691
+ Parameters:
692
+
693
+ - `time`: The time to get the hours from. It can be an STime or a string
694
+ in the HH:MM format.
695
+
696
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L82)
697
+
698
+ ### :gear: getMinutesFromTime
699
+
700
+ Returns the minutes from the given time.
701
+
702
+ | Function | Type |
703
+ | -------------------- | ----------------------------------- |
704
+ | `getMinutesFromTime` | `(time: string or STime) => number` |
705
+
706
+ Parameters:
707
+
708
+ - `time`: The time to get the minutes from. It can be an STime or a string
709
+ in the HH:MM format.
710
+
711
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L97)
712
+
713
+ ### :gear: getMinutesStringFromTime
714
+
715
+ Returns the minutes from given time as a string (00-59).
716
+
717
+ | Function | Type |
718
+ | -------------------------- | ----------------------------------- |
719
+ | `getMinutesStringFromTime` | `(time: string or STime) => string` |
720
+
721
+ Parameters:
722
+
723
+ - `time`: The time to get the minutes from. It can be an STime or a string
724
+ in the HH:MM format.
725
+
726
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L109)
727
+
728
+ ### :gear: get12HourTimeString
729
+
730
+ Returns a string that represents the time in a 12-hour format (HH:MM AM/PM).
731
+
732
+ | Function | Type |
733
+ | --------------------- | ----------------------------------- |
734
+ | `get12HourTimeString` | `(time: string or STime) => string` |
735
+
736
+ Parameters:
737
+
738
+ - `time`: The time to get the string from. It can be an STime or a string
739
+ in the HH:MM format.
740
+
741
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L121)
742
+
743
+ ### :gear: getTimeInMinutes
744
+
745
+ Returns the time converted to minutes since midnight.
746
+
747
+ | Function | Type |
748
+ | ------------------ | ----------------------------------------------------------- |
749
+ | `getTimeInMinutes` | `(time: string or STime, midnightIs24?: boolean) => number` |
750
+
751
+ Parameters:
752
+
753
+ - `time`: The time to get the minutes from. It can be an STime or a string
754
+ in the HH:MM format.
755
+
756
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L135)
757
+
758
+ ### :gear: addMinutesToTime
759
+
760
+ Returns a new STime instance with the time resulting from adding the given
761
+ number of minutes to the given time. The time will wrap around a 24 hour
762
+ clock.
763
+
764
+ | Function | Type |
765
+ | ------------------ | --------------------------------------------------- |
766
+ | `addMinutesToTime` | `(time: string or STime, minutes: number) => STime` |
767
+
768
+ Parameters:
769
+
770
+ - `time`: The time to add the minutes to. It can be an STime or a string
771
+ in the HH:MM format.
772
+ - `minutes`: The number of minutes to add.
773
+
774
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L165)
775
+
776
+ ### :gear: isSameTime
777
+
778
+ Returns true when the two times are the same and false otherwise.
779
+
780
+ | Function | Type |
781
+ | ------------ | ------------------------------------------------------------- |
782
+ | `isSameTime` | `(time1: string or STime, time2: string or STime) => boolean` |
783
+
784
+ Parameters:
785
+
786
+ - `time1`: The first time to compare. It can be an STime or a string in the
787
+ HH:MM format.
788
+ - `time2`: The second time to compare. It can be an STime or a string in
789
+ the HH:MM format.
790
+
791
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L197)
792
+
793
+ ### :gear: isAfterTime
794
+
795
+ Returns true when first time represents a time that happens after the second
796
+ time. Returns false otherwise.
797
+
798
+ | Function | Type |
799
+ | ------------- | ------------------------------------------------------------- |
800
+ | `isAfterTime` | `(time1: string or STime, time2: string or STime) => boolean` |
801
+
802
+ Parameters:
803
+
804
+ - `time1`: The first time to compare. It can be an STime or a string in the
805
+ HH:MM format.
806
+ - `time2`: The second time to compare. It can be an STime or a string in
807
+ the HH:MM format.
808
+
809
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L216)
810
+
811
+ ### :gear: isSameTimeOrAfter
812
+
813
+ Returns true when first time represents a time that happens after or at the
814
+ same time as the second time. Returns false otherwise.
815
+
816
+ | Function | Type |
817
+ | ------------------- | ------------------------------------------------------------- |
818
+ | `isSameTimeOrAfter` | `(time1: string or STime, time2: string or STime) => boolean` |
819
+
820
+ Parameters:
821
+
822
+ - `time1`: The first time to compare. It can be an STime or a string in the
823
+ HH:MM format.
824
+ - `time2`: The second time to compare. It can be an STime or a string in
825
+ the HH:MM format.
826
+
827
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L235)
828
+
829
+ ### :gear: isBeforeTime
830
+
831
+ Returns true when first time represents a time that happens before the
832
+ second time. Returns false otherwise.
833
+
834
+ | Function | Type |
835
+ | -------------- | ------------------------------------------------------------- |
836
+ | `isBeforeTime` | `(time1: string or STime, time2: string or STime) => boolean` |
837
+
838
+ Parameters:
839
+
840
+ - `time1`: The first time to compare. It can be an STime or a string in the
841
+ HH:MM format.
842
+ - `time2`: The second time to compare. It can be an STime or a string in
843
+ the HH:MM format.
844
+
845
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L254)
846
+
847
+ ### :gear: isSameTimeOrBefore
848
+
849
+ Returns true when first time represents a time that happens before or at the
850
+ same time as the second time. Returns false otherwise.
851
+
852
+ | Function | Type |
853
+ | -------------------- | ------------------------------------------------------------- |
854
+ | `isSameTimeOrBefore` | `(time1: string or STime, time2: string or STime) => boolean` |
855
+
856
+ Parameters:
857
+
858
+ - `time1`: The first time to compare. It can be an STime or a string in the
859
+ HH:MM format.
860
+ - `time2`: The second time to compare. It can be an STime or a string in
861
+ the HH:MM format.
862
+
863
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L273)
864
+
865
+ ### :gear: isTimePM
866
+
867
+ Returns true when the given time is at or after noon (12:00) and false
868
+ otherwise.
869
+
870
+ | Function | Type |
871
+ | ---------- | ------------------------------------ |
872
+ | `isTimePM` | `(time: string or STime) => boolean` |
873
+
874
+ Parameters:
875
+
876
+ - `time`: The time to check. It can be an STime or a string in the HH:MM
877
+ format.
878
+
879
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTime.ts#L290)
880
+
881
+ ### :gear: sTimestamp
882
+
883
+ Returns a new STimestamp instance.
884
+
885
+ | Function | Type |
886
+ | ------------ | ------------------------------------------------- |
887
+ | `sTimestamp` | `(timestamp: string or STimestamp) => STimestamp` |
888
+
889
+ Parameters:
890
+
891
+ - `timestamp`: An instance of STimestamp or a string in the
892
+ YYYY-MM-DDTHH:MM format.
893
+
894
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L36)
895
+
896
+ ### :gear: getTimestampFromUTCMilliseconds
897
+
898
+ Returns a new STimestamp instance set to the date and time that results from
899
+ converting the given number of milliseconds since the Unix epoch to the given
900
+ time zone.
901
+
902
+ | Function | Type |
903
+ | --------------------------------- | ----------------------------------------------------------------- |
904
+ | `getTimestampFromUTCMilliseconds` | `(utcDateInMilliseconds: number, timeZone: string) => STimestamp` |
905
+
906
+ Parameters:
907
+
908
+ - `utcDateInMilliseconds`: The number of milliseconds since the Unix epoch.
909
+ - `timeZone`: The time zone to use when creating the timestamp. See
910
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
911
+
912
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L57)
913
+
914
+ ### :gear: getTimestampNow
915
+
916
+ Returns a new STimestamp instance set to the current date and time in the
917
+ given time zone.
918
+
919
+ | Function | Type |
920
+ | ----------------- | ---------------------------------- |
921
+ | `getTimestampNow` | `(timeZone: string) => STimestamp` |
922
+
923
+ Parameters:
924
+
925
+ - `timeZone`: The time zone to use when creating the timestamp. See
926
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
927
+
928
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L73)
929
+
930
+ ### :gear: getTimestampFromDateAndTime
931
+
932
+ Returns a new STimestamp instance set to the date and time that results from
933
+ combining the given date and time.
934
+
935
+ | Function | Type |
936
+ | ----------------------------- | -------------------------------------------------------------- |
937
+ | `getTimestampFromDateAndTime` | `(date: string or SDate, time: string or STime) => STimestamp` |
938
+
939
+ Parameters:
940
+
941
+ - `date`: The date to use when creating the timestamp. It can be an SDate
942
+ or a string in the YYYY-MM-DD format.
943
+ - `time`: The time to use when creating the timestamp. It can be an STime
944
+ or a string in the HH:MM format.
945
+
946
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L86)
947
+
948
+ ### :gear: getTimeZonedDateFromTimestamp
949
+
950
+ Returns a native Date adjusted so that the local time of that date matches
951
+ the local timestamp at the specified time zone.
952
+
953
+ | Function | Type |
954
+ | ------------------------------- | ------------------------------------------------------------- |
955
+ | `getTimeZonedDateFromTimestamp` | `(timestamp: string or STimestamp, timeZone: string) => Date` |
956
+
957
+ Parameters:
958
+
959
+ - `date`: The date to get the time zoned date from. It can be an SDate or a
960
+ string in the YYYY-MM-DD format.
961
+ - `timeZone`: The time zone to adjust the date to. See
962
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
963
+
964
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L109)
965
+
966
+ ### :gear: getSecondsToTimestamp
967
+
968
+ Returns the number of seconds from now to the given timestamp. If the
969
+ timestamp is in the future, the number of seconds will be positive. If the
970
+ timestamp is in the past, the number of seconds will be negative.
971
+
972
+ Daylight Saving Notes:
973
+
974
+ The following notes use `America/New_York` as the time zone to explain how
975
+ Daylight Savings is handled, but it works the same across time zones on their
976
+ respective Daylight Saving schedules as defined by Intl API.
977
+
978
+ Notice that when looking at a watch (that adjusts for Daylight Saving
979
+ automatically) on 2024-03-10 (the day Daylight Savings goes into effect and
980
+ the time moves forward one hour) the times between 02:00 and 02:59 never
981
+ happen as the watch goes from 01:59 to 03:00. In the case of 2024-11-03 (the
982
+ day the time zone goes back to Standard Time), the times between 01:00 and
983
+ 01:59 happen twice as the first time the watch hits 02:00 it goes back to
984
+ 01:00.
985
+
986
+ To account for time zone changes, this method converts the timestamp to UTC
987
+ milliseconds (for both the current time and the expected timestamp) before
988
+ calculating the difference in seconds. This works as expected for all times,
989
+ but the expectation for the transition times (those that don't happen on a
990
+ watch that automatically adjusts or that happen twice) it can work in
991
+ unexpected ways.
992
+
993
+ For example, trying to calculate the number of seconds to 2024-03-10T02:00
994
+ (the start of Daylight Saving Time) at 2024-03-10T01:59 (still in Standard
995
+ Time) will result in -3540 seconds (59 minutes in the past). A similar
996
+ situation happens when the time zone transitions from Daylight Saving Time to
997
+ Standard Time as can be derived from the table below.
998
+
999
+ In 'America/New_York'
1000
+
1001
+ Transition to Eastern Daylight Time (EDT) in 2024
1002
+ | Time Zone | T1 | T2 | T3 |
1003
+ |------------------|-----------------------|------------------------|-----------------------|
1004
+ | America/New_York | 2024-03-10T01:59(EST) | 2024-03-10T02:00(EDT) | 2024-03-10T03:00(EST) |
1005
+ | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 | 2024-03-10T07:00 |
1006
+
1007
+ Transition to Eastern Standard Time (EST) in 2024
1008
+ | Time Zone | T1 | T2 | T3 |
1009
+ |------------------|-----------------------|------------------------|-----------------------|
1010
+ | America/New_York | 2024-11-03T01:59(EDT) | 2024-11-03T02:00(EST) | 2024-11-03T03:00(EST) |
1011
+ | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 | 2024-11-03T08:00 |
1012
+
1013
+ | Function | Type |
1014
+ | ----------------------- | --------------------------------------------------------------- |
1015
+ | `getSecondsToTimestamp` | `(timestamp: string or STimestamp, timeZone: string) => number` |
1016
+
1017
+ Parameters:
1018
+
1019
+ - `timestamp`: The timestamp to get the seconds to. It can be an STimestamp
1020
+ or a string in the YYYY-MM-DDTHH:MM format.
1021
+ - `timeZone`: The time zone to use when creating the timestamp. See
1022
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
1023
+
1024
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L174)
1025
+
1026
+ ### :gear: getDateFromTimestamp
1027
+
1028
+ Returns a new SDate instance set to the date part of the given timestamp.
1029
+
1030
+ | Function | Type |
1031
+ | ---------------------- | -------------------------------------------- |
1032
+ | `getDateFromTimestamp` | `(timestamp: string or STimestamp) => SDate` |
1033
+
1034
+ Parameters:
1035
+
1036
+ - `timestamp`: The timestamp to get the date from. It can be an STimestamp
1037
+ or a string in the YYYY-MM-DDTHH:MM format.
1038
+
1039
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L197)
1040
+
1041
+ ### :gear: getTimeFromTimestamp
1042
+
1043
+ Returns a new STime instance set to the time part of the given timestamp.
1044
+
1045
+ | Function | Type |
1046
+ | ---------------------- | -------------------------------------------- |
1047
+ | `getTimeFromTimestamp` | `(timestamp: string or STimestamp) => STime` |
1048
+
1049
+ Parameters:
1050
+
1051
+ - `timestamp`: The timestamp to get the time from. It can be an STimestamp
1052
+ or a string in the YYYY-MM-DDTHH:MM format.
1053
+
1054
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L209)
1055
+
1056
+ ### :gear: getShortTimestampString
1057
+
1058
+ Returns a string representation that includes a minimum set of components
1059
+ from the given timestamp. This is a combination of the the results of
1060
+ the `getShortDateString` method, and `get12HourTimeString`.
1061
+
1062
+ | Function | Type |
1063
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
1064
+ | `getShortTimestampString` | `(timestamp: string or STimestamp, timeZone: string, locale: LocalesArgument, options: STimestampShortStringOptions) => string` |
1065
+
1066
+ Parameters:
1067
+
1068
+ - `timestamp`: The timestamp to get the short string from. It can be an
1069
+ STimestamp or a string in the YYYY-MM-DDTHH:MM format.
1070
+ - `timeZone`: The time zone to use when creating the short string. See
1071
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
1072
+ - `locale`: The locale to use for the string representation.
1073
+ - `options`: An object with options for the short string representation.
1074
+
1075
+ Examples:
1076
+
1077
+ ```ts
1078
+ // Example when the timestamp is today
1079
+ getShortTimestampString('2021-08-10T08:00', 'America/Puerto_Rico', 'en', {
1080
+ includeWeekday: true,
1081
+ onTodayAtText: () => 'Today at',
1082
+ })
1083
+ //=> 'Today at 8:00 AM'
1084
+ ```
1085
+
1086
+ ```ts
1087
+ // Example when the timestamp is not today
1088
+ getShortTimestampString('2022-09-11T08:00', 'America/Puerto_Rico', 'es', {
1089
+ includeWeekday: true,
1090
+ onTodayAtText: () => 'Hoy a las',
1091
+ })
1092
+ //=> 'dom, 11 sept 22 8:00 AM'
1093
+ ```
1094
+
1095
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L247)
1096
+
1097
+ ### :gear: addDaysToTimestamp
1098
+
1099
+ Returns a new STimestamp instance resulting from adding the given number of
1100
+ calendar days to the given timestamp. Because it adds calendar days rather
1101
+ than 24-hour days, this operation is not affected by time zones.
1102
+
1103
+ | Function | Type |
1104
+ | -------------------- | --------------------------------------------------------------- |
1105
+ | `addDaysToTimestamp` | `(timestamp: string or STimestamp, days: number) => STimestamp` |
1106
+
1107
+ Parameters:
1108
+
1109
+ - `timestamp`: The timestamp to add days to. It can be an STimestamp or a
1110
+ string in the YYYY-MM-DDTHH:MM format.
1111
+ - `days`: The number of days to add to the timestamp.
1112
+
1113
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L279)
1114
+
1115
+ ### :gear: addMinutesToTimestamp
1116
+
1117
+ Returns a new STimestamp instance resulting from adding the given number of
1118
+ minutes to the given timestamp.
1119
+
1120
+ Daylight Saving Time Notes:
1121
+
1122
+ The following notes use `America/New_York` as the time zone to explain how
1123
+ Daylight Savings is handled, but it works the same across time zones on their
1124
+ respective Daylight Saving schedules as defined by Intl API.
1125
+
1126
+ Notice that when looking at a watch (that adjusts for Daylight Saving
1127
+ automatically) on 2024-03-10 (the day Daylight Savings goes into effect and
1128
+ the time moves forward one hour) the times between 02:00 and 02:59 never
1129
+ happen as the watch goes from 01:59 to 03:00. In the case of 2024-11-03 (the
1130
+ day the time zone goes back to Standard Time), the times between 01:00 and
1131
+ 01:59 happen twice as the first time the watch hits 02:00 it goes back to
1132
+ 01:00.
1133
+
1134
+ To account for time zone changes, this method converts the timestamp to UTC
1135
+ milliseconds before adding the specified minutes. This works as expected for
1136
+ all times, but the expectation for the transition times (those that don't
1137
+ happen on a watch that automatically adjusts or that happen twice) it can
1138
+ work in unexpected ways.
1139
+
1140
+ Time is converted from the given time zone to
1141
+ UTC before the minutes are added, and then converted back to the specified
1142
+ time zone. This results in the resulting time being adjusted for daylight saving time
1143
+ changes. (e.g. Adding 60 minutes to 2024-03-10T01:59 in America/New_York will
1144
+ result in 2024-03-10T03:59 as time move forward one hour for daylight saving
1145
+ time at 2024-03-10T02:00.)
1146
+
1147
+ For example, adding one minute to 2024-03-10T01:59 will result in
1148
+ 2024-03-10T03:00 as expected. However, trying to add one minute to
1149
+ 2024-03-10T02:00 (a time that technically does not exist on a watch that
1150
+ automatically adjusts for Daylight Saving) will result in 2024-03-10T01:01.
1151
+ This is because 2024-03-10T02:00 is converted to 2024-03-10T06:00 UTC (due
1152
+ to timezone offset being -4 starting from 02:00 local time) and one minute
1153
+ later would be 2024-03-10T06:01 UTC which would be 2024-03-10T01:01 in
1154
+ `America/New_York`. A similar situation happens when the time zone
1155
+ transitions from Daylight Saving Time to Standard Time as can be derived from
1156
+ the table below.
1157
+
1158
+ In 'America/New_York'
1159
+
1160
+ Transition to Eastern Daylight Time (EDT) in 2024
1161
+ | Time Zone | T1 | T2 | T3 |
1162
+ |------------------|-----------------------|------------------------|-----------------------|
1163
+ | America/New_York | 2024-03-10T01:59(EST) | 2024-03-10T02:00(EDT) | 2024-03-10T03:00(EST) |
1164
+ | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 | 2024-03-10T07:00 |
1165
+
1166
+ Transition to Eastern Standard Time (EST) in 2024
1167
+ | Time Zone | T1 | T2 | T3 |
1168
+ |------------------|-----------------------|------------------------|-----------------------|
1169
+ | America/New_York | 2024-11-03T01:59(EDT) | 2024-11-03T02:00(EST) | 2024-11-03T03:00(EST) |
1170
+ | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 | 2024-11-03T08:00 |
1171
+
1172
+ | Function | Type |
1173
+ | ----------------------- | ------------------------------------------------------------------------------------ |
1174
+ | `addMinutesToTimestamp` | `(timestamp: string or STimestamp, minutes: number, timeZone: string) => STimestamp` |
1175
+
1176
+ Parameters:
1177
+
1178
+ - `timestamp`: The timestamp to add minutes to. It can be an STimestamp or
1179
+ a string in the YYYY-MM-DDTHH:MM format.
1180
+ - `minutes`: The number of minutes to add to the timestamp.
1181
+ - `timeZone`: The time zone to use when creating the timestamp. See
1182
+ `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
1183
+
1184
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L353)
1185
+
1186
+ ### :gear: isSameTimestamp
1187
+
1188
+ Returns true if the two timestamps represent the same date and time. Returns
1189
+ false otherwise.
1190
+
1191
+ | Function | Type |
1192
+ | ----------------- | --------------------------------------------------------------------------------- |
1193
+ | `isSameTimestamp` | `(timestamp1: string or STimestamp, timestamp2: string or STimestamp) => boolean` |
1194
+
1195
+ Parameters:
1196
+
1197
+ - `timestamp1`: The first timestamp to compare. It can be an STimestamp or
1198
+ a string in the YYYY-MM-DDTHH:MM format.
1199
+ - `timestamp2`: The second timestamp to compare. It can be an STimestamp or
1200
+ a string in the YYYY-MM-DDTHH:MM format.
1201
+
1202
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L385)
1203
+
1204
+ ### :gear: isBeforeTimestamp
1205
+
1206
+ Returns true if the first timestamp represents a date and time that happens
1207
+ before the second timestamp. Returns false otherwise.
1208
+
1209
+ | Function | Type |
1210
+ | ------------------- | --------------------------------------------------------------------------------- |
1211
+ | `isBeforeTimestamp` | `(timestamp1: string or STimestamp, timestamp2: string or STimestamp) => boolean` |
1212
+
1213
+ Parameters:
1214
+
1215
+ - `timestamp1`: The first timestamp to compare. It can be an STimestamp or
1216
+ a string in the YYYY-MM-DDTHH:MM format.
1217
+ - `timestamp2`: The second timestamp to compare. It can be an STimestamp or
1218
+ a string in the YYYY-MM-DDTHH:MM format.
1219
+
1220
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L404)
1221
+
1222
+ ### :gear: isSameTimestampOrBefore
1223
+
1224
+ Returns true if the first timestamp represents a date and time that happens
1225
+ on or before the second timestamp. Returns false otherwise.
1226
+
1227
+ | Function | Type |
1228
+ | ------------------------- | --------------------------------------------------------------------------------- |
1229
+ | `isSameTimestampOrBefore` | `(timestamp1: string or STimestamp, timestamp2: string or STimestamp) => boolean` |
1230
+
1231
+ Parameters:
1232
+
1233
+ - `timestamp1`: The first timestamp to compare. It can be an STimestamp or
1234
+ a string in the YYYY-MM-DDTHH:MM format.
1235
+ - `timestamp2`: The second timestamp to compare. It can be an STimestamp or
1236
+ a string in the YYYY-MM-DDTHH:MM format.
1237
+
1238
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L423)
1239
+
1240
+ ### :gear: isAfterTimestamp
1241
+
1242
+ Returns true if the first timestamp represents a date and time that happens
1243
+ after the second timestamp. Returns false otherwise.
1244
+
1245
+ | Function | Type |
1246
+ | ------------------ | --------------------------------------------------------------------------------- |
1247
+ | `isAfterTimestamp` | `(timestamp1: string or STimestamp, timestamp2: string or STimestamp) => boolean` |
1248
+
1249
+ Parameters:
1250
+
1251
+ - `timestamp1`: The first timestamp to compare. It can be an STimestamp or
1252
+ a string in the YYYY-MM-DDTHH:MM format.
1253
+ - `timestamp2`: The second timestamp to compare. It can be an STimestamp or
1254
+ a string in the YYYY-MM-DDTHH:MM format.
1255
+
1256
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L442)
1257
+
1258
+ ### :gear: isSameTimestampOrAfter
1259
+
1260
+ Returns true if the first timestamp represents a date and time that happens
1261
+ on or after the second timestamp. Returns false otherwise.
1262
+
1263
+ | Function | Type |
1264
+ | ------------------------ | --------------------------------------------------------------------------------- |
1265
+ | `isSameTimestampOrAfter` | `(timestamp1: string or STimestamp, timestamp2: string or STimestamp) => boolean` |
1266
+
1267
+ Parameters:
1268
+
1269
+ - `timestamp1`: The first timestamp to compare. It can be an STimestamp or
1270
+ a string in the YYYY-MM-DDTHH:MM format.
1271
+ - `timestamp2`: The second timestamp to compare. It can be an STimestamp or
1272
+ a string in the YYYY-MM-DDTHH:MM format.
1273
+
1274
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sTimestamp.ts#L461)
1275
+
1276
+ ### :gear: sWeekdays
1277
+
1278
+ Returns a new SWeekdays instance.
1279
+
1280
+ | Function | Type |
1281
+ | ----------- | ---------------------------------------------- |
1282
+ | `sWeekdays` | `(weekdays: string or SWeekdays) => SWeekdays` |
1283
+
1284
+ Parameters:
1285
+
1286
+ - `weekdays`: An instance of SWeekdays that will be returned or a string in
1287
+ the SMTWTFS format. Each character in the string represents a weekday
1288
+ starting on Sunday and ending on Saturday using the first letter of the
1289
+ English word for the week day. If the weekday is excluded, the position is
1290
+ filled with a '-' character.
1291
+
1292
+ Examples:
1293
+
1294
+ ```ts
1295
+ sWeekdays('SM----S')
1296
+ // Returns an instance of SWeekdays with the weekdays Sunday, Monday, and
1297
+ // Saturday included while the rest are excluded.
1298
+ ```
1299
+
1300
+ ```ts
1301
+ sWeekdays('SMTWTFS')
1302
+ // Returns an instance of SWeekdays with all weekdays included.
1303
+ ```
1304
+
1305
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L47)
1306
+
1307
+ ### :gear: getWeekdaysFromWeekdayFlags
1308
+
1309
+ Returns a new SWeekdays instance with all provided weekdays included. The
1310
+ provided weekdays can be any combination of the Weekday enum values.
1311
+
1312
+ | Function | Type |
1313
+ | ----------------------------- | ---------------------------------- |
1314
+ | `getWeekdaysFromWeekdayFlags` | `(weekdays: Weekday) => SWeekdays` |
1315
+
1316
+ Parameters:
1317
+
1318
+ - `weekdays`: A combination of the Weekday enum values.
1319
+
1320
+ Examples:
1321
+
1322
+ ```ts
1323
+ getWeekdaysFromWeekdayFlags(Weekday.Monday | Weekday.Wednesday | Weekday.Friday)
1324
+ // Returns an instance of SWeekdays with the weekdays Monday, Wednesday, and
1325
+ // Friday included while the rest are excluded.
1326
+ ```
1327
+
1328
+ ```ts
1329
+ getWeekdaysFromWeekdayFlags(Weekday.Tuesday)
1330
+ // Returns an instance of SWeekdays with the weekday Tuesday included while
1331
+ // the rest are excluded.
1332
+ ```
1333
+
1334
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L79)
1335
+
1336
+ ### :gear: getWeekdaysWithAllIncluded
1337
+
1338
+ Returns a new SWeekdays instance with all weekdays included.
1339
+
1340
+ | Function | Type |
1341
+ | ---------------------------- | ----------------- |
1342
+ | `getWeekdaysWithAllIncluded` | `() => SWeekdays` |
1343
+
1344
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L96)
1345
+
1346
+ ### :gear: getWeekdaysWithNoneIncluded
1347
+
1348
+ Returns a new SWeekdays instance with no weekdays included.
1349
+
1350
+ | Function | Type |
1351
+ | ----------------------------- | ----------------- |
1352
+ | `getWeekdaysWithNoneIncluded` | `() => SWeekdays` |
1353
+
1354
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L103)
1355
+
1356
+ ### :gear: shiftWeekdaysForward
1357
+
1358
+ Returns a new SWeekdays instance with the weekdays shifted forward by one
1359
+ day.
1360
+
1361
+ | Function | Type |
1362
+ | ---------------------- | ---------------------------------------------- |
1363
+ | `shiftWeekdaysForward` | `(weekdays: string or SWeekdays) => SWeekdays` |
1364
+
1365
+ Parameters:
1366
+
1367
+ - `weekdays`: The weekdays to shift forward. It can be an SWeekdays or a
1368
+ string in the SMTWTFS format.
1369
+
1370
+ Examples:
1371
+
1372
+ ```ts
1373
+ shiftWeekdaysForward('SM----S')
1374
+ // Returns an instance of SWeekdays with the weekdays shifted forward by one
1375
+ // day. 'SM----S' becomes 'SMT----'.
1376
+ ```
1377
+
1378
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L125)
1379
+
1380
+ ### :gear: filterWeekdaysForDates
1381
+
1382
+ Returns a new SWeekdays instance where only the weekdays that are within the
1383
+ provided date range are included.
1384
+
1385
+ | Function | Type |
1386
+ | ------------------------ | -------------------------------------------------------------------------------------------------- |
1387
+ | `filterWeekdaysForDates` | `(weekdays: string or SWeekdays, fromDate: string or SDate, toDate: string or SDate) => SWeekdays` |
1388
+
1389
+ Parameters:
1390
+
1391
+ - `weekdays`: The weekdays to filter. It can be an SWeekdays or a string in
1392
+ the SMTWTFS format.
1393
+ - `fromDate`: The start date of the range. It can be an SDate or a string
1394
+ in the YYYY-MM-DD format.
1395
+ - `toDate`: The end date of the range. It can be an SDate or a string in
1396
+ the YYYY-MM-DD format.
1397
+
1398
+ Examples:
1399
+
1400
+ ```ts
1401
+ filterWeekdaysForDates('SMTWTFS', '2020-03-05', '2020-03-05')
1402
+ // Returns an instance of SWeekdays with only Thursday included.
1403
+ ```
1404
+
1405
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L162)
1406
+
1407
+ ### :gear: addWeekdayToWeekdays
1408
+
1409
+ Returns a new SWeekdays instance with the provided weekday added to the
1410
+ current set of weekdays.
1411
+
1412
+ | Function | Type |
1413
+ | ---------------------- | --------------------------------------------------------------------- |
1414
+ | `addWeekdayToWeekdays` | `(weekdays: string or SWeekdays, weekdayToAdd: Weekday) => SWeekdays` |
1415
+
1416
+ Parameters:
1417
+
1418
+ - `weekdays`: The weekdays to add the weekday to. It can be an SWeekdays or
1419
+ a string in the SMTWTFS format.
1420
+ - `weekdayToAdd`: The weekday to add.
1421
+
1422
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L209)
1423
+
1424
+ ### :gear: doesWeekdaysIncludeWeekday
1425
+
1426
+ Returns true if the provided weekdays include the provided weekday. Returns
1427
+ false otherwise.
1428
+
1429
+ | Function | Type |
1430
+ | ---------------------------- | -------------------------------------------------------------- |
1431
+ | `doesWeekdaysIncludeWeekday` | `(weekdays: string or SWeekdays, weekday: Weekday) => boolean` |
1432
+
1433
+ Parameters:
1434
+
1435
+ - `weekdays`: The weekdays to check. It can be an SWeekdays or a string in
1436
+ the SMTWTFS format.
1437
+ - `weekday`: The weekday to check.
1438
+
1439
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L234)
1440
+
1441
+ ### :gear: doesWeekdaysHaveOverlapWithWeekdays
1442
+
1443
+ Returns true if any of the included weekdays in weekdays1 is also included in
1444
+ weekdays2. Returns false otherwise.
1445
+
1446
+ | Function | Type |
1447
+ | ------------------------------------- | ----------------------------------------------------------------------------- |
1448
+ | `doesWeekdaysHaveOverlapWithWeekdays` | `(weekdays1: string or SWeekdays, weekdays2: string or SWeekdays) => boolean` |
1449
+
1450
+ Parameters:
1451
+
1452
+ - `weekdays1`: The first set of weekdays to compare. It can be an SWeekdays
1453
+ or a string in the SMTWTFS format.
1454
+ - `weekdays2`: The second set of weekdays to compare. It can be an
1455
+ SWeekdays or a string in the SMTWTFS format.
1456
+
1457
+ [:link: Source](https://github.com/ericvera/scdate/tree/main/src/sWeekdays.ts#L253)
1458
+
1459
+ ## :nut_and_bolt: Enum
1460
+
1461
+ - [Weekday](#gear-weekday)
1462
+
1463
+ ### :gear: Weekday
1464
+
1465
+ | Property | Type | Description |
1466
+ | -------- | ---- | ----------- |
1467
+ | `Sun` | `1` | |
1468
+ | `Mon` | `2` | |
1469
+ | `Tue` | `4` | |
1470
+ | `Wed` | `8` | |
1471
+ | `Thu` | `16` | |
1472
+ | `Fri` | `32` | |
1473
+ | `Sat` | `64` | |
1474
+
1475
+ <!-- TSDOC_END -->