scdate 2.0.2 → 2.1.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/dist/constants.d.ts +5 -0
- package/dist/constants.js +13 -0
- package/dist/internal/constants.d.ts +0 -2
- package/dist/internal/constants.js +0 -10
- package/dist/internal/weekdays.js +1 -1
- package/dist/sDate.d.ts +35 -32
- package/dist/sDate.js +39 -34
- package/dist/sTimestamp.d.ts +46 -23
- package/dist/sTimestamp.js +46 -23
- package/dist/sWeekdays.d.ts +83 -3
- package/dist/sWeekdays.js +99 -4
- package/package.json +14 -35
- package/LICENSE +0 -21
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -8,3 +8,16 @@ export var Weekday;
|
|
|
8
8
|
Weekday[Weekday["Fri"] = 32] = "Fri";
|
|
9
9
|
Weekday[Weekday["Sat"] = 64] = "Sat";
|
|
10
10
|
})(Weekday || (Weekday = {}));
|
|
11
|
+
/**
|
|
12
|
+
* Maps weekday index (0-6) to Weekday enum value.
|
|
13
|
+
* 0 = Sunday, 1 = Monday, ..., 6 = Saturday
|
|
14
|
+
*/
|
|
15
|
+
export const DayToWeekday = [
|
|
16
|
+
Weekday.Sun,
|
|
17
|
+
Weekday.Mon,
|
|
18
|
+
Weekday.Tue,
|
|
19
|
+
Weekday.Wed,
|
|
20
|
+
Weekday.Thu,
|
|
21
|
+
Weekday.Fri,
|
|
22
|
+
Weekday.Sat,
|
|
23
|
+
];
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { Weekday } from '../constants.js';
|
|
2
|
-
export const DayToWeekday = [
|
|
3
|
-
Weekday.Sun,
|
|
4
|
-
Weekday.Mon,
|
|
5
|
-
Weekday.Tue,
|
|
6
|
-
Weekday.Wed,
|
|
7
|
-
Weekday.Thu,
|
|
8
|
-
Weekday.Fri,
|
|
9
|
-
Weekday.Sat,
|
|
10
|
-
];
|
|
11
1
|
export const DaysInWeek = 7;
|
|
12
2
|
export const MinutesInDay = 1440;
|
|
13
3
|
export const MinutesInHour = 60;
|
package/dist/sDate.d.ts
CHANGED
|
@@ -91,11 +91,11 @@ export declare const getDateFromDate: (date: string | SDate) => number;
|
|
|
91
91
|
*/
|
|
92
92
|
export declare const getWeekdayFromDate: (date: string | SDate) => number;
|
|
93
93
|
/**
|
|
94
|
-
* Returns the number of milliseconds since the Unix epoch (January 1,
|
|
95
|
-
* for the given date in the specified time zone.
|
|
94
|
+
* Returns the number of milliseconds since the Unix epoch (January 1,
|
|
95
|
+
* 1970, 00:00:00 UTC) for the given date in the specified time zone.
|
|
96
96
|
*
|
|
97
|
-
* @param date The date to convert to UTC milliseconds. It can be an
|
|
98
|
-
* in the YYYY-MM-DD format.
|
|
97
|
+
* @param date The date to convert to UTC milliseconds. It can be an
|
|
98
|
+
* SDate or a string in the YYYY-MM-DD format.
|
|
99
99
|
* @param timeZone The time zone to use when converting the date. See
|
|
100
100
|
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
101
101
|
*/
|
|
@@ -191,18 +191,21 @@ export declare const addDaysToDate: (date: string | SDate, days: number) => SDat
|
|
|
191
191
|
* number of months to the given date. Because it just adds to the month
|
|
192
192
|
* component of the date, this operation is not affected by time zones.
|
|
193
193
|
*
|
|
194
|
-
* When the original date's day exceeds the number of days in the
|
|
195
|
-
* the function will automatically clamp to the last day of
|
|
196
|
-
* rather than rolling over to the next month. For
|
|
197
|
-
* January 31 will result in February 28/29
|
|
194
|
+
* When the original date's day exceeds the number of days in the
|
|
195
|
+
* target month, the function will automatically clamp to the last day of
|
|
196
|
+
* the target month rather than rolling over to the next month. For
|
|
197
|
+
* example, adding 1 month to January 31 will result in February 28/29
|
|
198
|
+
* (depending on leap year), not March 3.
|
|
198
199
|
*
|
|
199
|
-
* @param date The date to add months to. It can be an SDate or a
|
|
200
|
-
* YYYY-MM-DD format.
|
|
200
|
+
* @param date The date to add months to. It can be an SDate or a
|
|
201
|
+
* string in the YYYY-MM-DD format.
|
|
201
202
|
* @param months The number of months to add to the date.
|
|
202
|
-
* @param options Additional options for controlling the behavior of the
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
203
|
+
* @param options Additional options for controlling the behavior of the
|
|
204
|
+
* function.
|
|
205
|
+
* @param options.capToCommonDate When true, if the original date is the
|
|
206
|
+
* 29th, 30th, or 31st, the result will be capped to the 28th of the
|
|
207
|
+
* month (the last date common to all months) rather than the last day of
|
|
208
|
+
* the target month.
|
|
206
209
|
* This ensures consistent date handling across all months.
|
|
207
210
|
*
|
|
208
211
|
* @example
|
|
@@ -266,33 +269,33 @@ export declare const isSameDate: (date1: string | SDate, date2: string | SDate)
|
|
|
266
269
|
*/
|
|
267
270
|
export declare const isBeforeDate: (date1: string | SDate, date2: string | SDate) => boolean;
|
|
268
271
|
/**
|
|
269
|
-
* Returns true when the first date represents a date that happens on the
|
|
270
|
-
* date or before the second date and false otherwise.
|
|
272
|
+
* Returns true when the first date represents a date that happens on the
|
|
273
|
+
* same date or before the second date and false otherwise.
|
|
271
274
|
*
|
|
272
|
-
* @param date1 The first date to compare. It can be an SDate or a
|
|
273
|
-
* YYYY-MM-DD format.
|
|
274
|
-
* @param date2 The second date to compare. It can be an SDate or a
|
|
275
|
-
* the YYYY-MM-DD format.
|
|
275
|
+
* @param date1 The first date to compare. It can be an SDate or a
|
|
276
|
+
* string in the YYYY-MM-DD format.
|
|
277
|
+
* @param date2 The second date to compare. It can be an SDate or a
|
|
278
|
+
* string in the YYYY-MM-DD format.
|
|
276
279
|
*/
|
|
277
280
|
export declare const isSameDateOrBefore: (date1: string | SDate, date2: string | SDate) => boolean;
|
|
278
281
|
/**
|
|
279
|
-
* Returns true when the first date represents a date that happens after
|
|
280
|
-
* second date and false otherwise.
|
|
282
|
+
* Returns true when the first date represents a date that happens after
|
|
283
|
+
* the second date and false otherwise.
|
|
281
284
|
*
|
|
282
|
-
* @param date1 The first date to compare. It can be an SDate or a
|
|
283
|
-
* YYYY-MM-DD format.
|
|
284
|
-
* @param date2 The second date to compare. It can be an SDate or a
|
|
285
|
-
* the YYYY-MM-DD format.
|
|
285
|
+
* @param date1 The first date to compare. It can be an SDate or a
|
|
286
|
+
* string in the YYYY-MM-DD format.
|
|
287
|
+
* @param date2 The second date to compare. It can be an SDate or a
|
|
288
|
+
* string in the YYYY-MM-DD format.
|
|
286
289
|
*/
|
|
287
290
|
export declare const isAfterDate: (date1: string | SDate, date2: string | SDate) => boolean;
|
|
288
291
|
/**
|
|
289
|
-
* Returns true when the first date represents a date that happens on the
|
|
290
|
-
* date or after the second date and false otherwise.
|
|
292
|
+
* Returns true when the first date represents a date that happens on the
|
|
293
|
+
* same date or after the second date and false otherwise.
|
|
291
294
|
*
|
|
292
|
-
* @param date1 The first date to compare. It can be an SDate or a
|
|
293
|
-
* YYYY-MM-DD format.
|
|
294
|
-
* @param date2 The second date to compare. It can be an SDate or a
|
|
295
|
-
* the YYYY-MM-DD format.
|
|
295
|
+
* @param date1 The first date to compare. It can be an SDate or a
|
|
296
|
+
* string in the YYYY-MM-DD format.
|
|
297
|
+
* @param date2 The second date to compare. It can be an SDate or a
|
|
298
|
+
* string in the YYYY-MM-DD format.
|
|
296
299
|
*/
|
|
297
300
|
export declare const isSameDateOrAfter: (date1: string | SDate, date2: string | SDate) => boolean;
|
|
298
301
|
/**
|
package/dist/sDate.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { UTCDateMini } from '@date-fns/utc';
|
|
2
2
|
import { getTimezoneOffset } from 'date-fns-tz';
|
|
3
|
+
import { DayToWeekday } from './constants.js';
|
|
3
4
|
import { SDate } from './internal/SDate.js';
|
|
4
|
-
import {
|
|
5
|
+
import { DaysInWeek, MillisecondsInDay } from './internal/constants.js';
|
|
5
6
|
import { getDateAsUTCDateMini, getISODateFromISODate, getISODateFromZonedDate, getISOMonthFromISODate, getISOYearFromISODate, } from './internal/date.js';
|
|
6
7
|
import { getAtIndex } from './internal/utils.js';
|
|
7
8
|
import { getIndexForWeekday } from './internal/weekdays.js';
|
|
@@ -145,11 +146,11 @@ export const getWeekdayFromDate = (date) => {
|
|
|
145
146
|
return getAtIndex(DayToWeekday, nativeDate.getDay());
|
|
146
147
|
};
|
|
147
148
|
/**
|
|
148
|
-
* Returns the number of milliseconds since the Unix epoch (January 1,
|
|
149
|
-
* for the given date in the specified time zone.
|
|
149
|
+
* Returns the number of milliseconds since the Unix epoch (January 1,
|
|
150
|
+
* 1970, 00:00:00 UTC) for the given date in the specified time zone.
|
|
150
151
|
*
|
|
151
|
-
* @param date The date to convert to UTC milliseconds. It can be an
|
|
152
|
-
* in the YYYY-MM-DD format.
|
|
152
|
+
* @param date The date to convert to UTC milliseconds. It can be an
|
|
153
|
+
* SDate or a string in the YYYY-MM-DD format.
|
|
153
154
|
* @param timeZone The time zone to use when converting the date. See
|
|
154
155
|
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
155
156
|
*/
|
|
@@ -290,18 +291,21 @@ export const addDaysToDate = (date, days) => {
|
|
|
290
291
|
* number of months to the given date. Because it just adds to the month
|
|
291
292
|
* component of the date, this operation is not affected by time zones.
|
|
292
293
|
*
|
|
293
|
-
* When the original date's day exceeds the number of days in the
|
|
294
|
-
* the function will automatically clamp to the last day of
|
|
295
|
-
* rather than rolling over to the next month. For
|
|
296
|
-
* January 31 will result in February 28/29
|
|
294
|
+
* When the original date's day exceeds the number of days in the
|
|
295
|
+
* target month, the function will automatically clamp to the last day of
|
|
296
|
+
* the target month rather than rolling over to the next month. For
|
|
297
|
+
* example, adding 1 month to January 31 will result in February 28/29
|
|
298
|
+
* (depending on leap year), not March 3.
|
|
297
299
|
*
|
|
298
|
-
* @param date The date to add months to. It can be an SDate or a
|
|
299
|
-
* YYYY-MM-DD format.
|
|
300
|
+
* @param date The date to add months to. It can be an SDate or a
|
|
301
|
+
* string in the YYYY-MM-DD format.
|
|
300
302
|
* @param months The number of months to add to the date.
|
|
301
|
-
* @param options Additional options for controlling the behavior of the
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
303
|
+
* @param options Additional options for controlling the behavior of the
|
|
304
|
+
* function.
|
|
305
|
+
* @param options.capToCommonDate When true, if the original date is the
|
|
306
|
+
* 29th, 30th, or 31st, the result will be capped to the 28th of the
|
|
307
|
+
* month (the last date common to all months) rather than the last day of
|
|
308
|
+
* the target month.
|
|
305
309
|
* This ensures consistent date handling across all months.
|
|
306
310
|
*
|
|
307
311
|
* @example
|
|
@@ -337,7 +341,8 @@ export const addMonthsToDate = (date, months, options) => {
|
|
|
337
341
|
nativeDate.setDate(1);
|
|
338
342
|
// Then set the new month
|
|
339
343
|
nativeDate.setMonth(currentMonth + months);
|
|
340
|
-
// If capToCommonDate is true and the original day is greater than
|
|
344
|
+
// If capToCommonDate is true and the original day is greater than
|
|
345
|
+
// 28, cap to 28
|
|
341
346
|
if (options?.capToCommonDate && currentDay > 28) {
|
|
342
347
|
nativeDate.setDate(28);
|
|
343
348
|
}
|
|
@@ -396,13 +401,13 @@ export const isBeforeDate = (date1, date2) => {
|
|
|
396
401
|
return sDate1.date < sDate2.date;
|
|
397
402
|
};
|
|
398
403
|
/**
|
|
399
|
-
* Returns true when the first date represents a date that happens on the
|
|
400
|
-
* date or before the second date and false otherwise.
|
|
404
|
+
* Returns true when the first date represents a date that happens on the
|
|
405
|
+
* same date or before the second date and false otherwise.
|
|
401
406
|
*
|
|
402
|
-
* @param date1 The first date to compare. It can be an SDate or a
|
|
403
|
-
* YYYY-MM-DD format.
|
|
404
|
-
* @param date2 The second date to compare. It can be an SDate or a
|
|
405
|
-
* the YYYY-MM-DD format.
|
|
407
|
+
* @param date1 The first date to compare. It can be an SDate or a
|
|
408
|
+
* string in the YYYY-MM-DD format.
|
|
409
|
+
* @param date2 The second date to compare. It can be an SDate or a
|
|
410
|
+
* string in the YYYY-MM-DD format.
|
|
406
411
|
*/
|
|
407
412
|
export const isSameDateOrBefore = (date1, date2) => {
|
|
408
413
|
const sDate1 = sDate(date1);
|
|
@@ -410,13 +415,13 @@ export const isSameDateOrBefore = (date1, date2) => {
|
|
|
410
415
|
return sDate1.date <= sDate2.date;
|
|
411
416
|
};
|
|
412
417
|
/**
|
|
413
|
-
* Returns true when the first date represents a date that happens after
|
|
414
|
-
* second date and false otherwise.
|
|
418
|
+
* Returns true when the first date represents a date that happens after
|
|
419
|
+
* the second date and false otherwise.
|
|
415
420
|
*
|
|
416
|
-
* @param date1 The first date to compare. It can be an SDate or a
|
|
417
|
-
* YYYY-MM-DD format.
|
|
418
|
-
* @param date2 The second date to compare. It can be an SDate or a
|
|
419
|
-
* the YYYY-MM-DD format.
|
|
421
|
+
* @param date1 The first date to compare. It can be an SDate or a
|
|
422
|
+
* string in the YYYY-MM-DD format.
|
|
423
|
+
* @param date2 The second date to compare. It can be an SDate or a
|
|
424
|
+
* string in the YYYY-MM-DD format.
|
|
420
425
|
*/
|
|
421
426
|
export const isAfterDate = (date1, date2) => {
|
|
422
427
|
const sDate1 = sDate(date1);
|
|
@@ -424,13 +429,13 @@ export const isAfterDate = (date1, date2) => {
|
|
|
424
429
|
return sDate1.date > sDate2.date;
|
|
425
430
|
};
|
|
426
431
|
/**
|
|
427
|
-
* Returns true when the first date represents a date that happens on the
|
|
428
|
-
* date or after the second date and false otherwise.
|
|
432
|
+
* Returns true when the first date represents a date that happens on the
|
|
433
|
+
* same date or after the second date and false otherwise.
|
|
429
434
|
*
|
|
430
|
-
* @param date1 The first date to compare. It can be an SDate or a
|
|
431
|
-
* YYYY-MM-DD format.
|
|
432
|
-
* @param date2 The second date to compare. It can be an SDate or a
|
|
433
|
-
* the YYYY-MM-DD format.
|
|
435
|
+
* @param date1 The first date to compare. It can be an SDate or a
|
|
436
|
+
* string in the YYYY-MM-DD format.
|
|
437
|
+
* @param date2 The second date to compare. It can be an SDate or a
|
|
438
|
+
* string in the YYYY-MM-DD format.
|
|
434
439
|
*/
|
|
435
440
|
export const isSameDateOrAfter = (date1, date2) => {
|
|
436
441
|
const sDate1 = sDate(date1);
|
package/dist/sTimestamp.d.ts
CHANGED
|
@@ -50,13 +50,16 @@ export declare const getTimestampFromDateAndTime: (date: string | SDate, time: s
|
|
|
50
50
|
* --- Getters ---
|
|
51
51
|
*/
|
|
52
52
|
/**
|
|
53
|
-
* Returns the number of milliseconds since the Unix epoch
|
|
54
|
-
* for the given timestamp in the
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
53
|
+
* Returns the number of milliseconds since the Unix epoch
|
|
54
|
+
* (January 1, 1970, 00:00:00 UTC) for the given timestamp in the
|
|
55
|
+
* specified time zone.
|
|
56
|
+
*
|
|
57
|
+
* @param timestamp The timestamp to convert to UTC milliseconds.
|
|
58
|
+
* It can be an STimestamp or a string in the YYYY-MM-DDTHH:MM
|
|
59
|
+
* format.
|
|
60
|
+
* @param timeZone The time zone to use when converting the
|
|
61
|
+
* timestamp. See `Intl.supportedValuesOf('timeZone')` for a list
|
|
62
|
+
* of valid time zones.
|
|
60
63
|
*/
|
|
61
64
|
export declare const getUTCMillisecondsFromTimestamp: (timestamp: string | STimestamp, timeZone: string) => number;
|
|
62
65
|
/**
|
|
@@ -104,16 +107,26 @@ export declare const getTimeZonedDateFromTimestamp: (timestamp: string | STimest
|
|
|
104
107
|
* In 'America/New_York'
|
|
105
108
|
*
|
|
106
109
|
* Transition to Eastern Daylight Time (EDT) in 2024
|
|
107
|
-
* | Time Zone | T1
|
|
108
|
-
*
|
|
109
|
-
* | America/New_York | 2024-03-10T01:
|
|
110
|
-
* | UTC | 2024-03-10T06:59
|
|
110
|
+
* | Time Zone | T1 | T2 |
|
|
111
|
+
* |------------------|---------------------|---------------------|
|
|
112
|
+
* | America/New_York | 2024-03-10T01:59EST | 2024-03-10T02:00EDT |
|
|
113
|
+
* | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 |
|
|
114
|
+
*
|
|
115
|
+
* | Time Zone | T3 |
|
|
116
|
+
* |------------------|---------------------|
|
|
117
|
+
* | America/New_York | 2024-03-10T03:00EST |
|
|
118
|
+
* | UTC | 2024-03-10T07:00 |
|
|
111
119
|
*
|
|
112
120
|
* Transition to Eastern Standard Time (EST) in 2024
|
|
113
|
-
* | Time Zone | T1
|
|
114
|
-
*
|
|
115
|
-
* | America/New_York | 2024-11-03T01:
|
|
116
|
-
* | UTC | 2024-11-03T05:59
|
|
121
|
+
* | Time Zone | T1 | T2 |
|
|
122
|
+
* |------------------|---------------------|---------------------|
|
|
123
|
+
* | America/New_York | 2024-11-03T01:59EDT | 2024-11-03T02:00EST |
|
|
124
|
+
* | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 |
|
|
125
|
+
*
|
|
126
|
+
* | Time Zone | T3 |
|
|
127
|
+
* |------------------|---------------------|
|
|
128
|
+
* | America/New_York | 2024-11-03T03:00EST |
|
|
129
|
+
* | UTC | 2024-11-03T08:00 |
|
|
117
130
|
*
|
|
118
131
|
* @param timestamp The timestamp to get the seconds to. It can be an STimestamp
|
|
119
132
|
* or a string in the YYYY-MM-DDTHH:MM format.
|
|
@@ -226,16 +239,26 @@ export declare const addDaysToTimestamp: (timestamp: string | STimestamp, days:
|
|
|
226
239
|
* In 'America/New_York'
|
|
227
240
|
*
|
|
228
241
|
* Transition to Eastern Daylight Time (EDT) in 2024
|
|
229
|
-
* | Time Zone | T1
|
|
230
|
-
*
|
|
231
|
-
* | America/New_York | 2024-03-10T01:
|
|
232
|
-
* | UTC | 2024-03-10T06:59
|
|
242
|
+
* | Time Zone | T1 | T2 |
|
|
243
|
+
* |------------------|---------------------|---------------------|
|
|
244
|
+
* | America/New_York | 2024-03-10T01:59EST | 2024-03-10T02:00EDT |
|
|
245
|
+
* | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 |
|
|
246
|
+
*
|
|
247
|
+
* | Time Zone | T3 |
|
|
248
|
+
* |------------------|---------------------|
|
|
249
|
+
* | America/New_York | 2024-03-10T03:00EST |
|
|
250
|
+
* | UTC | 2024-03-10T07:00 |
|
|
233
251
|
*
|
|
234
252
|
* Transition to Eastern Standard Time (EST) in 2024
|
|
235
|
-
* | Time Zone | T1
|
|
236
|
-
*
|
|
237
|
-
* | America/New_York | 2024-11-03T01:
|
|
238
|
-
* | UTC | 2024-11-03T05:59
|
|
253
|
+
* | Time Zone | T1 | T2 |
|
|
254
|
+
* |------------------|---------------------|---------------------|
|
|
255
|
+
* | America/New_York | 2024-11-03T01:59EDT | 2024-11-03T02:00EST |
|
|
256
|
+
* | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 |
|
|
257
|
+
*
|
|
258
|
+
* | Time Zone | T3 |
|
|
259
|
+
* |------------------|---------------------|
|
|
260
|
+
* | America/New_York | 2024-11-03T03:00EST |
|
|
261
|
+
* | UTC | 2024-11-03T08:00 |
|
|
239
262
|
*
|
|
240
263
|
* @param timestamp The timestamp to add minutes to. It can be an STimestamp or
|
|
241
264
|
* a string in the YYYY-MM-DDTHH:MM format.
|
package/dist/sTimestamp.js
CHANGED
|
@@ -64,13 +64,16 @@ export const getTimestampFromDateAndTime = (date, time) => {
|
|
|
64
64
|
* --- Getters ---
|
|
65
65
|
*/
|
|
66
66
|
/**
|
|
67
|
-
* Returns the number of milliseconds since the Unix epoch
|
|
68
|
-
* for the given timestamp in the
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
67
|
+
* Returns the number of milliseconds since the Unix epoch
|
|
68
|
+
* (January 1, 1970, 00:00:00 UTC) for the given timestamp in the
|
|
69
|
+
* specified time zone.
|
|
70
|
+
*
|
|
71
|
+
* @param timestamp The timestamp to convert to UTC milliseconds.
|
|
72
|
+
* It can be an STimestamp or a string in the YYYY-MM-DDTHH:MM
|
|
73
|
+
* format.
|
|
74
|
+
* @param timeZone The time zone to use when converting the
|
|
75
|
+
* timestamp. See `Intl.supportedValuesOf('timeZone')` for a list
|
|
76
|
+
* of valid time zones.
|
|
74
77
|
*/
|
|
75
78
|
export const getUTCMillisecondsFromTimestamp = (timestamp, timeZone) => {
|
|
76
79
|
const sTimestampValue = sTimestamp(timestamp);
|
|
@@ -130,16 +133,26 @@ export const getTimeZonedDateFromTimestamp = (timestamp, timeZone) => {
|
|
|
130
133
|
* In 'America/New_York'
|
|
131
134
|
*
|
|
132
135
|
* Transition to Eastern Daylight Time (EDT) in 2024
|
|
133
|
-
* | Time Zone | T1
|
|
134
|
-
*
|
|
135
|
-
* | America/New_York | 2024-03-10T01:
|
|
136
|
-
* | UTC | 2024-03-10T06:59
|
|
136
|
+
* | Time Zone | T1 | T2 |
|
|
137
|
+
* |------------------|---------------------|---------------------|
|
|
138
|
+
* | America/New_York | 2024-03-10T01:59EST | 2024-03-10T02:00EDT |
|
|
139
|
+
* | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 |
|
|
140
|
+
*
|
|
141
|
+
* | Time Zone | T3 |
|
|
142
|
+
* |------------------|---------------------|
|
|
143
|
+
* | America/New_York | 2024-03-10T03:00EST |
|
|
144
|
+
* | UTC | 2024-03-10T07:00 |
|
|
137
145
|
*
|
|
138
146
|
* Transition to Eastern Standard Time (EST) in 2024
|
|
139
|
-
* | Time Zone | T1
|
|
140
|
-
*
|
|
141
|
-
* | America/New_York | 2024-11-03T01:
|
|
142
|
-
* | UTC | 2024-11-03T05:59
|
|
147
|
+
* | Time Zone | T1 | T2 |
|
|
148
|
+
* |------------------|---------------------|---------------------|
|
|
149
|
+
* | America/New_York | 2024-11-03T01:59EDT | 2024-11-03T02:00EST |
|
|
150
|
+
* | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 |
|
|
151
|
+
*
|
|
152
|
+
* | Time Zone | T3 |
|
|
153
|
+
* |------------------|---------------------|
|
|
154
|
+
* | America/New_York | 2024-11-03T03:00EST |
|
|
155
|
+
* | UTC | 2024-11-03T08:00 |
|
|
143
156
|
*
|
|
144
157
|
* @param timestamp The timestamp to get the seconds to. It can be an STimestamp
|
|
145
158
|
* or a string in the YYYY-MM-DDTHH:MM format.
|
|
@@ -278,16 +291,26 @@ export const addDaysToTimestamp = (timestamp, days) => {
|
|
|
278
291
|
* In 'America/New_York'
|
|
279
292
|
*
|
|
280
293
|
* Transition to Eastern Daylight Time (EDT) in 2024
|
|
281
|
-
* | Time Zone | T1
|
|
282
|
-
*
|
|
283
|
-
* | America/New_York | 2024-03-10T01:
|
|
284
|
-
* | UTC | 2024-03-10T06:59
|
|
294
|
+
* | Time Zone | T1 | T2 |
|
|
295
|
+
* |------------------|---------------------|---------------------|
|
|
296
|
+
* | America/New_York | 2024-03-10T01:59EST | 2024-03-10T02:00EDT |
|
|
297
|
+
* | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 |
|
|
298
|
+
*
|
|
299
|
+
* | Time Zone | T3 |
|
|
300
|
+
* |------------------|---------------------|
|
|
301
|
+
* | America/New_York | 2024-03-10T03:00EST |
|
|
302
|
+
* | UTC | 2024-03-10T07:00 |
|
|
285
303
|
*
|
|
286
304
|
* Transition to Eastern Standard Time (EST) in 2024
|
|
287
|
-
* | Time Zone | T1
|
|
288
|
-
*
|
|
289
|
-
* | America/New_York | 2024-11-03T01:
|
|
290
|
-
* | UTC | 2024-11-03T05:59
|
|
305
|
+
* | Time Zone | T1 | T2 |
|
|
306
|
+
* |------------------|---------------------|---------------------|
|
|
307
|
+
* | America/New_York | 2024-11-03T01:59EDT | 2024-11-03T02:00EST |
|
|
308
|
+
* | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 |
|
|
309
|
+
*
|
|
310
|
+
* | Time Zone | T3 |
|
|
311
|
+
* |------------------|---------------------|
|
|
312
|
+
* | America/New_York | 2024-11-03T03:00EST |
|
|
313
|
+
* | UTC | 2024-11-03T08:00 |
|
|
291
314
|
*
|
|
292
315
|
* @param timestamp The timestamp to add minutes to. It can be an STimestamp or
|
|
293
316
|
* a string in the YYYY-MM-DDTHH:MM format.
|
package/dist/sWeekdays.d.ts
CHANGED
|
@@ -38,9 +38,11 @@ export declare const sWeekdays: (weekdays: string | SWeekdays) => SWeekdays;
|
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
|
-
* getWeekdaysFromWeekdayFlags(
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* getWeekdaysFromWeekdayFlags(
|
|
42
|
+
* Weekday.Monday | Weekday.Wednesday | Weekday.Friday
|
|
43
|
+
* )
|
|
44
|
+
* // Returns an instance of SWeekdays with the weekdays Monday,
|
|
45
|
+
* // Wednesday, and Friday included while the rest are excluded.
|
|
44
46
|
* ```
|
|
45
47
|
*
|
|
46
48
|
* @example
|
|
@@ -62,6 +64,42 @@ export declare const getWeekdaysWithNoneIncluded: () => SWeekdays;
|
|
|
62
64
|
/**
|
|
63
65
|
* --- Operations ---
|
|
64
66
|
*/
|
|
67
|
+
/**
|
|
68
|
+
* Returns the previous weekday (the day before the provided weekday).
|
|
69
|
+
*
|
|
70
|
+
* @param weekday The weekday to get the previous weekday for.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* getPreviousWeekday(Weekday.Mon)
|
|
75
|
+
* // Returns Weekday.Sun
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* getPreviousWeekday(Weekday.Sun)
|
|
81
|
+
* // Returns Weekday.Sat
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare const getPreviousWeekday: (weekday: Weekday) => Weekday;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the next weekday (the day after the provided weekday).
|
|
87
|
+
*
|
|
88
|
+
* @param weekday The weekday to get the next weekday for.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* getNextWeekday(Weekday.Mon)
|
|
93
|
+
* // Returns Weekday.Tue
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* getNextWeekday(Weekday.Sat)
|
|
99
|
+
* // Returns Weekday.Sun
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare const getNextWeekday: (weekday: Weekday) => Weekday;
|
|
65
103
|
/**
|
|
66
104
|
* Returns a new SWeekdays instance with the weekdays shifted forward by one
|
|
67
105
|
* day.
|
|
@@ -126,3 +164,45 @@ export declare const doesWeekdaysIncludeWeekday: (weekdays: string | SWeekdays,
|
|
|
126
164
|
* SWeekdays or a string in the SMTWTFS format.
|
|
127
165
|
*/
|
|
128
166
|
export declare const doesWeekdaysHaveOverlapWithWeekdays: (weekdays1: string | SWeekdays, weekdays2: string | SWeekdays) => boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Returns true if the two weekdays patterns are equal (have the same days
|
|
169
|
+
* included). Returns false otherwise.
|
|
170
|
+
*
|
|
171
|
+
* @param weekdays1 The first weekdays pattern to compare. It can be an
|
|
172
|
+
* SWeekdays or a string in the SMTWTFS format.
|
|
173
|
+
* @param weekdays2 The second weekdays pattern to compare. It can be an
|
|
174
|
+
* SWeekdays or a string in the SMTWTFS format.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* areWeekdaysEqual('SMTWTFS', 'SMTWTFS')
|
|
179
|
+
* // Returns true
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* areWeekdaysEqual('SM----S', '-MTWTF-')
|
|
185
|
+
* // Returns false
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export declare const areWeekdaysEqual: (weekdays1: string | SWeekdays, weekdays2: string | SWeekdays) => boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Returns true if the weekdays pattern has no days selected (i.e., '-------').
|
|
191
|
+
* Returns false otherwise.
|
|
192
|
+
*
|
|
193
|
+
* @param weekdays The weekdays pattern to check. It can be an SWeekdays or a
|
|
194
|
+
* string in the SMTWTFS format.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* isWeekdaysEmpty('-------')
|
|
199
|
+
* // Returns true
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* isWeekdaysEmpty('S------')
|
|
205
|
+
* // Returns false (Sunday is included)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare const isWeekdaysEmpty: (weekdays: string | SWeekdays) => boolean;
|
package/dist/sWeekdays.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* --- Factory ---
|
|
3
3
|
*/
|
|
4
|
+
import { DayToWeekday } from './constants.js';
|
|
4
5
|
import { SWeekdays } from './internal/SWeekdays.js';
|
|
5
|
-
import {
|
|
6
|
+
import { DaysInWeek } from './internal/constants.js';
|
|
6
7
|
import { getAtIndex, hasFlag } from './internal/utils.js';
|
|
7
8
|
import { getIndexForWeekday } from './internal/weekdays.js';
|
|
8
9
|
import { addDaysToDate, getDaysBetweenDates, getWeekdayFromDate, isAfterDate, isSameDateOrBefore, sDate, } from './sDate.js';
|
|
@@ -49,9 +50,11 @@ export const sWeekdays = (weekdays) => {
|
|
|
49
50
|
*
|
|
50
51
|
* @example
|
|
51
52
|
* ```ts
|
|
52
|
-
* getWeekdaysFromWeekdayFlags(
|
|
53
|
-
*
|
|
54
|
-
*
|
|
53
|
+
* getWeekdaysFromWeekdayFlags(
|
|
54
|
+
* Weekday.Monday | Weekday.Wednesday | Weekday.Friday
|
|
55
|
+
* )
|
|
56
|
+
* // Returns an instance of SWeekdays with the weekdays Monday,
|
|
57
|
+
* // Wednesday, and Friday included while the rest are excluded.
|
|
55
58
|
* ```
|
|
56
59
|
*
|
|
57
60
|
* @example
|
|
@@ -86,6 +89,50 @@ export const getWeekdaysWithNoneIncluded = () => {
|
|
|
86
89
|
/**
|
|
87
90
|
* --- Operations ---
|
|
88
91
|
*/
|
|
92
|
+
/**
|
|
93
|
+
* Returns the previous weekday (the day before the provided weekday).
|
|
94
|
+
*
|
|
95
|
+
* @param weekday The weekday to get the previous weekday for.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* getPreviousWeekday(Weekday.Mon)
|
|
100
|
+
* // Returns Weekday.Sun
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* getPreviousWeekday(Weekday.Sun)
|
|
106
|
+
* // Returns Weekday.Sat
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export const getPreviousWeekday = (weekday) => {
|
|
110
|
+
const weekdayIndex = getIndexForWeekday(weekday);
|
|
111
|
+
const previousIndex = (weekdayIndex + DaysInWeek - 1) % DaysInWeek;
|
|
112
|
+
return getAtIndex(DayToWeekday, previousIndex);
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Returns the next weekday (the day after the provided weekday).
|
|
116
|
+
*
|
|
117
|
+
* @param weekday The weekday to get the next weekday for.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* getNextWeekday(Weekday.Mon)
|
|
122
|
+
* // Returns Weekday.Tue
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* getNextWeekday(Weekday.Sat)
|
|
128
|
+
* // Returns Weekday.Sun
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export const getNextWeekday = (weekday) => {
|
|
132
|
+
const weekdayIndex = getIndexForWeekday(weekday);
|
|
133
|
+
const nextIndex = (weekdayIndex + 1) % DaysInWeek;
|
|
134
|
+
return getAtIndex(DayToWeekday, nextIndex);
|
|
135
|
+
};
|
|
89
136
|
/**
|
|
90
137
|
* Returns a new SWeekdays instance with the weekdays shifted forward by one
|
|
91
138
|
* day.
|
|
@@ -204,3 +251,51 @@ export const doesWeekdaysHaveOverlapWithWeekdays = (weekdays1, weekdays2) => {
|
|
|
204
251
|
}
|
|
205
252
|
return false;
|
|
206
253
|
};
|
|
254
|
+
/**
|
|
255
|
+
* Returns true if the two weekdays patterns are equal (have the same days
|
|
256
|
+
* included). Returns false otherwise.
|
|
257
|
+
*
|
|
258
|
+
* @param weekdays1 The first weekdays pattern to compare. It can be an
|
|
259
|
+
* SWeekdays or a string in the SMTWTFS format.
|
|
260
|
+
* @param weekdays2 The second weekdays pattern to compare. It can be an
|
|
261
|
+
* SWeekdays or a string in the SMTWTFS format.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* areWeekdaysEqual('SMTWTFS', 'SMTWTFS')
|
|
266
|
+
* // Returns true
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* areWeekdaysEqual('SM----S', '-MTWTF-')
|
|
272
|
+
* // Returns false
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export const areWeekdaysEqual = (weekdays1, weekdays2) => {
|
|
276
|
+
const sWeekdays1 = sWeekdays(weekdays1);
|
|
277
|
+
const sWeekdays2 = sWeekdays(weekdays2);
|
|
278
|
+
return sWeekdays1.weekdays === sWeekdays2.weekdays;
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* Returns true if the weekdays pattern has no days selected (i.e., '-------').
|
|
282
|
+
* Returns false otherwise.
|
|
283
|
+
*
|
|
284
|
+
* @param weekdays The weekdays pattern to check. It can be an SWeekdays or a
|
|
285
|
+
* string in the SMTWTFS format.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* isWeekdaysEmpty('-------')
|
|
290
|
+
* // Returns true
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* isWeekdaysEmpty('S------')
|
|
296
|
+
* // Returns false (Sunday is included)
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
export const isWeekdaysEmpty = (weekdays) => {
|
|
300
|
+
return areWeekdaysEqual(weekdays, getWeekdaysWithNoneIncluded());
|
|
301
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scdate",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js"
|
|
@@ -12,21 +12,12 @@
|
|
|
12
12
|
],
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=22"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc --build",
|
|
19
|
-
"build:clean": "yarn build --clean && rimraf dist && rimraf *.tgz",
|
|
20
19
|
"lint": "eslint .",
|
|
21
|
-
"test": "vitest run"
|
|
22
|
-
"test:utc": "TZ=Etc/Universal yarn test",
|
|
23
|
-
"test:watch": "vitest",
|
|
24
|
-
"test:utc:watch": "TZ=Etc/Universal yarn test:watch",
|
|
25
|
-
"smoke": "yarn build && yarn lint && yarn test:utc",
|
|
26
|
-
"-- PRE-COMMIT HOOKS --": "",
|
|
27
|
-
"localAfterInstall": "husky || true",
|
|
28
|
-
"prepublishOnly": "pinst --disable",
|
|
29
|
-
"postpublish": "pinst --enable"
|
|
20
|
+
"test": "vitest run"
|
|
30
21
|
},
|
|
31
22
|
"dependencies": {
|
|
32
23
|
"@date-fns/utc": "^2.1.1",
|
|
@@ -34,23 +25,13 @@
|
|
|
34
25
|
"date-fns-tz": "^3.2.0"
|
|
35
26
|
},
|
|
36
27
|
"devDependencies": {
|
|
37
|
-
"@eslint/js": "^9.
|
|
38
|
-
"@tsconfig/strictest": "^2.0.
|
|
39
|
-
"@types/node": "^24.
|
|
40
|
-
"eslint": "^9.
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"prettier": "^3.6.2",
|
|
45
|
-
"rimraf": "^6.0.1",
|
|
46
|
-
"typescript": "^5.9.2",
|
|
47
|
-
"typescript-eslint": "^8.40.0",
|
|
48
|
-
"vitest": "^3.2.4"
|
|
49
|
-
},
|
|
50
|
-
"prettier": {
|
|
51
|
-
"tabWidth": 2,
|
|
52
|
-
"semi": false,
|
|
53
|
-
"singleQuote": true
|
|
28
|
+
"@eslint/js": "^9.39.1",
|
|
29
|
+
"@tsconfig/strictest": "^2.0.8",
|
|
30
|
+
"@types/node": "^24.10.1",
|
|
31
|
+
"eslint": "^9.39.1",
|
|
32
|
+
"typescript": "^5.9.3",
|
|
33
|
+
"typescript-eslint": "^8.47.0",
|
|
34
|
+
"vitest": "^4.0.13"
|
|
54
35
|
},
|
|
55
36
|
"repository": {
|
|
56
37
|
"type": "git",
|
|
@@ -66,9 +47,7 @@
|
|
|
66
47
|
"timestamp"
|
|
67
48
|
],
|
|
68
49
|
"license": "MIT",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"packageManager": "yarn@4.9.2"
|
|
74
|
-
}
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Eric Vera
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|