scdate 0.1.1 → 0.2.1

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