scdate 2.1.1 → 3.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/README.md CHANGED
@@ -29,7 +29,20 @@ yarn add scdate
29
29
  ## Basic Usage
30
30
 
31
31
  ```typescript
32
- import { sDate, sTime, sTimestamp, sWeekdays, Weekday } from 'scdate'
32
+ import {
33
+ sDate,
34
+ sTime,
35
+ sTimestamp,
36
+ sWeekdays,
37
+ Weekday,
38
+ getDateToday,
39
+ getNextDateByWeekday,
40
+ getTimeNow,
41
+ addMinutesToTime,
42
+ getTimestampNow,
43
+ getTimestampFromDateAndTime,
44
+ getWeekdaysFromWeekdayFlags,
45
+ } from 'scdate'
33
46
 
34
47
  // Working with dates
35
48
  const today = getDateToday('America/Puerto_Rico')
@@ -59,7 +72,7 @@ const businessDays = getWeekdaysFromWeekdayFlags(
59
72
  ```typescript
60
73
  // Creating dates
61
74
  const date1 = sDate('2023-12-25') // From ISO string
62
- const date2 = getDateToday('America/Puerto_Rico') // Current date in timezone
75
+ const date2 = getDateToday('America/Puerto_Rico') // Current date in time zone
63
76
  const date3 = getDateForFirstDayOfMonth(date1) // First day of month
64
77
  const date4 = getDateForLastDayOfMonth(date1) // Last day of month
65
78
 
@@ -81,7 +94,7 @@ const prevFriday = getPreviousDateByWeekday(date1, Weekday.Fri)
81
94
  // Date calculations
82
95
  const daysBetween = getDaysBetweenDates(date1, date2) // Days between dates (positive if date2 is later)
83
96
  const utcMs = getUTCMillisecondsFromDate(date1, 'America/Puerto_Rico') // Convert to UTC milliseconds
84
- const zonedDate = getTimeZonedDateFromDate(date1, 'America/Puerto_Rico') // Get timezone-adjusted Date
97
+ const zonedDate = getTimeZonedDateFromDate(date1, 'America/Puerto_Rico') // Get time-zone-adjusted Date
85
98
 
86
99
  // Date comparison
87
100
  const isEqual = isSameDate(date1, date2)
@@ -137,7 +150,7 @@ const shortDateStr = getShortDateString(date1, 'America/Puerto_Rico', 'en-US', {
137
150
  ```typescript
138
151
  // Creating times
139
152
  const time1 = sTime('14:30') // From ISO string
140
- const time2 = getTimeNow('America/Puerto_Rico') // Current time in timezone
153
+ const time2 = getTimeNow('America/Puerto_Rico') // Current time in time zone
141
154
  const time3 = getTimeAtMidnight() // 00:00
142
155
  const time4 = getTimeFromMinutes(60) // 01:00 (60 minutes after midnight)
143
156
 
@@ -182,7 +195,7 @@ const isPM = isTimePM(time1)
182
195
  ```typescript
183
196
  // Creating timestamps
184
197
  const ts1 = sTimestamp('2023-12-25T14:30') // From ISO string
185
- const ts2 = getTimestampNow('America/Puerto_Rico') // Current timestamp in timezone
198
+ const ts2 = getTimestampNow('America/Puerto_Rico') // Current timestamp in time zone
186
199
  const ts3 = getTimestampFromDateAndTime(date1, time1) // From date and time
187
200
  const ts4 = getTimestampFromUTCMilliseconds(
188
201
  1640444400000,
@@ -251,9 +264,15 @@ const filteredWeekdays = filterWeekdaysForDates(
251
264
  )
252
265
  const updatedWeekdays = addWeekdayToWeekdays(weekdays5, Weekday.Fri) // Add Friday to pattern
253
266
 
267
+ // Weekday navigation
268
+ const previousDay = getPreviousWeekday(Weekday.Mon) // Returns Weekday.Sun
269
+ const nextDay = getNextWeekday(Weekday.Mon) // Returns Weekday.Tue
270
+
254
271
  // Weekday queries
255
272
  const includesMonday = doesWeekdaysIncludeWeekday(weekdays2, Weekday.Mon)
256
273
  const hasOverlap = doesWeekdaysHaveOverlapWithWeekdays(weekdays2, weekdays3)
274
+ const areEqual = areWeekdaysEqual(weekdays1, weekdays4) // true (both all days)
275
+ const isEmpty = isWeekdaysEmpty(weekdays5) // true (no days)
257
276
  ```
258
277
 
259
278
  #### Important Behaviors and Edge Cases
@@ -292,7 +311,14 @@ scDate intentionally omits seconds and milliseconds from time representations. T
292
311
  - Simpler time representations lead to more intuitive API and usage patterns
293
312
  - Performance is optimized by avoiding unnecessary precision
294
313
 
295
- ## Time zones
314
+ ## Time Zones
315
+
316
+ ```typescript
317
+ import { isValidTimeZone } from 'scdate'
318
+
319
+ isValidTimeZone('America/New_York') // true
320
+ isValidTimeZone('Invalid/Timezone') // false
321
+ ```
296
322
 
297
323
  For a list of valid time zones run `Intl.supportedValuesOf('timeZone')` in your environment.
298
324
 
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Weekday flags for use with bitwise operations. Each value is a power of 2,
3
+ * allowing multiple days to be combined using the bitwise OR operator.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * // Combine weekdays with bitwise OR
8
+ * const weekendDays = Weekday.Sat | Weekday.Sun
9
+ *
10
+ * // Business days
11
+ * const businessDays =
12
+ * Weekday.Mon | Weekday.Tue | Weekday.Wed | Weekday.Thu | Weekday.Fri
13
+ * ```
14
+ */
1
15
  export declare enum Weekday {
2
16
  Sun = 1,
3
17
  Mon = 2,
package/dist/constants.js CHANGED
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Weekday flags for use with bitwise operations. Each value is a power of 2,
3
+ * allowing multiple days to be combined using the bitwise OR operator.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * // Combine weekdays with bitwise OR
8
+ * const weekendDays = Weekday.Sat | Weekday.Sun
9
+ *
10
+ * // Business days
11
+ * const businessDays =
12
+ * Weekday.Mon | Weekday.Tue | Weekday.Wed | Weekday.Thu | Weekday.Fri
13
+ * ```
14
+ */
1
15
  export var Weekday;
2
16
  (function (Weekday) {
3
17
  Weekday[Weekday["Sun"] = 1] = "Sun";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './constants.js';
2
+ export * from './isValidTimeZone.js';
2
3
  export * from './sDate.js';
3
4
  export * from './sTime.js';
4
5
  export * from './sTimestamp.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './constants.js';
2
+ export * from './isValidTimeZone.js';
2
3
  export * from './sDate.js';
3
4
  export * from './sTime.js';
4
5
  export * from './sTimestamp.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks if a string is a valid IANA time zone identifier.
3
+ *
4
+ * @param timeZone The string to validate as an IANA time zone identifier.
5
+ */
6
+ export declare const isValidTimeZone: (timeZone: string) => boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Checks if a string is a valid IANA time zone identifier.
3
+ *
4
+ * @param timeZone The string to validate as an IANA time zone identifier.
5
+ */
6
+ export const isValidTimeZone = (timeZone) => {
7
+ try {
8
+ const validTimeZones = Intl.supportedValuesOf('timeZone');
9
+ return validTimeZones.includes(timeZone);
10
+ }
11
+ catch {
12
+ return false;
13
+ }
14
+ };
package/dist/sDate.d.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  import { Weekday } from './constants.js';
2
2
  import { SDate } from './internal/SDate.js';
3
+ /**
4
+ * Options for customizing the short date string representation.
5
+ */
3
6
  export interface SDateShortStringOptions {
7
+ /** Whether to include the abbreviated weekday name in the output. */
4
8
  includeWeekday: boolean;
9
+ /**
10
+ * Called when the date is today. Return value is used as the display
11
+ * text.
12
+ */
5
13
  onTodayText: () => string;
6
14
  }
7
15
  /**
@@ -25,7 +33,7 @@ export declare const sDate: (date: string | SDate) => SDate;
25
33
  export declare const getDateToday: (timeZone: string) => SDate;
26
34
  /**
27
35
  * Returns a new SDate instance set to the next date after the provided date
28
- * that match the given weekday.
36
+ * that matches the given weekday.
29
37
  *
30
38
  * @param date The date to start from (not included). It can be an SDate or a
31
39
  * string in the YYYY-MM-DD format.
@@ -33,12 +41,12 @@ export declare const getDateToday: (timeZone: string) => SDate;
33
41
  */
34
42
  export declare const getNextDateByWeekday: (date: string | SDate, weekday: Weekday) => SDate;
35
43
  /**
36
- * Returns a new SDate instance set to date that is before the provided date and
37
- * matches the given weekday.
44
+ * Returns a new SDate instance set to the date that is before the provided date
45
+ * and matches the given weekday.
38
46
  *
39
- * @param date The date to start from (not included).
40
- * @param weekday The weekday to find the previous date for. It can be an SDate
41
- * or a string in the YYYY-MM-DD format.
47
+ * @param date The date to start from (not included). It can be an SDate or a
48
+ * string in the YYYY-MM-DD format.
49
+ * @param weekday The weekday to find the previous date for.
42
50
  */
43
51
  export declare const getPreviousDateByWeekday: (date: string | SDate, weekday: Weekday) => SDate;
44
52
  /**
@@ -53,8 +61,8 @@ export declare const getDateForFirstDayOfMonth: (date: string | SDate) => SDate;
53
61
  * Returns a new SDate instance set to the last day of the month for the
54
62
  * provided date.
55
63
  *
56
- * @param date The date to get the last day of the month for. It can be an SDate
57
- * or a string in the YYYY-MM-DD format.
64
+ * @param date The date to get the last day of the month for. It can be an
65
+ * SDate or a string in the YYYY-MM-DD format.
58
66
  */
59
67
  export declare const getDateForLastDayOfMonth: (date: string | SDate) => SDate;
60
68
  /**
@@ -63,31 +71,31 @@ export declare const getDateForLastDayOfMonth: (date: string | SDate) => SDate;
63
71
  /**
64
72
  * Returns the year from the given date.
65
73
  *
66
- * @param date The date to get the year from. It can be an SDate or a string in
67
- * the YYYY-MM-DD format.
74
+ * @param date The date to get the year from. It can be an SDate or a string
75
+ * in the YYYY-MM-DD format.
68
76
  */
69
77
  export declare const getYearFromDate: (date: string | SDate) => number;
70
78
  /**
71
- * Returns the month from the given date. Returns a 0-index value (i.e. Janary
79
+ * Returns the month from the given date. Returns a 0-index value (i.e. January
72
80
  * is 0 and December is 11) to match the result from native Date object.
73
81
  *
74
- * @param date The date to get the month from. It can be an SDate or a string in
75
- * the YYYY-MM-DD format.
82
+ * @param date The date to get the month from. It can be an SDate or a string
83
+ * in the YYYY-MM-DD format.
76
84
  */
77
85
  export declare const getMonthFromDate: (date: string | SDate) => number;
78
86
  /**
79
87
  * Returns the day of the month from the given date.
80
88
  *
81
- * @param date The date to get the day from. It can be an SDate or a string in
82
- * the YYYY-MM-DD format.
89
+ * @param date The date to get the day from. It can be an SDate or a string
90
+ * in the YYYY-MM-DD format.
83
91
  */
84
92
  export declare const getDateFromDate: (date: string | SDate) => number;
85
93
  /**
86
94
  * Returns the day of the week from the given date (Sunday to Saturday / 0 to
87
95
  * 6).
88
96
  *
89
- * @param date The date to get the weekday from. It can be an SDate or a string
90
- * in the YYYY-MM-DD format.
97
+ * @param date The date to get the weekday from. It can be an SDate or a
98
+ * string in the YYYY-MM-DD format.
91
99
  */
92
100
  export declare const getWeekdayFromDate: (date: string | SDate) => number;
93
101
  /**
@@ -104,8 +112,8 @@ export declare const getUTCMillisecondsFromDate: (date: string | SDate, timeZone
104
112
  * Returns a native Date adjusted so that the local time of that date matches
105
113
  * the local time at the specified time zone.
106
114
  *
107
- * @param date The date to get the time zoned date from. It can be an SDate or a
108
- * string in the YYYY-MM-DD format.
115
+ * @param date The date to get the time zoned date from. It can be an SDate
116
+ * or a string in the YYYY-MM-DD format.
109
117
  * @param timeZone The time zone to adjust the date to. See
110
118
  * `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
111
119
  */
@@ -117,18 +125,18 @@ export declare const getTimeZonedDateFromDate: (date: string | SDate, timeZone:
117
125
  * and not full 24-hour periods which could be different due to daylight saving
118
126
  * adjustments.
119
127
  *
120
- * @param date1 The first date to get the days between. It can be an SDate or a
121
- * string in the YYYY-MM-DD format.
122
- * @param date2 The second date to get the days between. It can be an SDate or a
123
- * string in the YYYY-MM-DD format.
128
+ * @param date1 The first date to get the days between. It can be an SDate or
129
+ * a string in the YYYY-MM-DD format.
130
+ * @param date2 The second date to get the days between. It can be an SDate
131
+ * or a string in the YYYY-MM-DD format.
124
132
  */
125
133
  export declare const getDaysBetweenDates: (date1: string | SDate, date2: string | SDate) => number;
126
134
  /**
127
135
  * Returns a string representation that includes all of the date components of
128
136
  * the given date formatted according to the given locale.
129
137
  *
130
- * @param date The date to get the full string representation for. It can be an
131
- * SDate or a string in the YYYY-MM-DD format.
138
+ * @param date The date to get the full string representation for. It can be
139
+ * an SDate or a string in the YYYY-MM-DD format.
132
140
  * @param locale The locale to use for the string representation.
133
141
  *
134
142
  * @example
@@ -147,10 +155,10 @@ export declare const getFullDateString: (date: string | SDate, locale: Intl.Loca
147
155
  /**
148
156
  * Get the short string representation of the given date in the given locale.
149
157
  *
150
- * @param date The date to get the short string representation for. It can be an
151
- * SDate or a string in the YYYY-MM-DD format.
152
- * @param timeZone The time zone used to determine if in the current year. See
153
- * `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
158
+ * @param date The date to get the short string representation for. It can be
159
+ * an SDate or a string in the YYYY-MM-DD format.
160
+ * @param timeZone The time zone used to determine if in the current year.
161
+ * See `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
154
162
  * @param locale The locale to use for the string representation.
155
163
  * @param options The options to customize the short string representation.
156
164
  *
@@ -177,7 +185,7 @@ export declare const getShortDateString: (date: string | SDate, timeZone: string
177
185
  * --- Operations ---
178
186
  */
179
187
  /**
180
- * Returns a new SDates instance with the date resulting from adding the given
188
+ * Returns a new SDate instance with the date resulting from adding the given
181
189
  * number of days to the given date. Because it adds calendar days rather than
182
190
  * 24-hour days, this operation is not affected by time zones.
183
191
  *
@@ -252,8 +260,8 @@ export declare const addYearsToDate: (date: string | SDate, years: number) => SD
252
260
  * Returns true when the two given dates represent the same day and false
253
261
  * otherwise.
254
262
  *
255
- * @param date1 The first date to compare. It can be an SDate or a string in the
256
- * YYYY-MM-DD format.
263
+ * @param date1 The first date to compare. It can be an SDate or a string in
264
+ * the YYYY-MM-DD format.
257
265
  * @param date2 The second date to compare. It can be an SDate or a string in
258
266
  * the YYYY-MM-DD format.
259
267
  */
@@ -262,8 +270,8 @@ export declare const isSameDate: (date1: string | SDate, date2: string | SDate)
262
270
  * Returns true when the first date represents a date before the second date and
263
271
  * false otherwise.
264
272
  *
265
- * @param date1 The first date to compare. It can be an SDate or a string in the
266
- * YYYY-MM-DD format.
273
+ * @param date1 The first date to compare. It can be an SDate or a string in
274
+ * the YYYY-MM-DD format.
267
275
  * @param date2 The second date to compare. It can be an SDate or a string in
268
276
  * the YYYY-MM-DD format.
269
277
  */
package/dist/sDate.js CHANGED
@@ -36,7 +36,7 @@ export const getDateToday = (timeZone) => {
36
36
  };
37
37
  /**
38
38
  * Returns a new SDate instance set to the next date after the provided date
39
- * that match the given weekday.
39
+ * that matches the given weekday.
40
40
  *
41
41
  * @param date The date to start from (not included). It can be an SDate or a
42
42
  * string in the YYYY-MM-DD format.
@@ -54,12 +54,12 @@ export const getNextDateByWeekday = (date, weekday) => {
54
54
  return addDaysToDate(sDateValue, adjustment);
55
55
  };
56
56
  /**
57
- * Returns a new SDate instance set to date that is before the provided date and
58
- * matches the given weekday.
57
+ * Returns a new SDate instance set to the date that is before the provided date
58
+ * and matches the given weekday.
59
59
  *
60
- * @param date The date to start from (not included).
61
- * @param weekday The weekday to find the previous date for. It can be an SDate
62
- * or a string in the YYYY-MM-DD format.
60
+ * @param date The date to start from (not included). It can be an SDate or a
61
+ * string in the YYYY-MM-DD format.
62
+ * @param weekday The weekday to find the previous date for.
63
63
  */
64
64
  export const getPreviousDateByWeekday = (date, weekday) => {
65
65
  const sDateValue = sDate(date);
@@ -89,8 +89,8 @@ export const getDateForFirstDayOfMonth = (date) => {
89
89
  * Returns a new SDate instance set to the last day of the month for the
90
90
  * provided date.
91
91
  *
92
- * @param date The date to get the last day of the month for. It can be an SDate
93
- * or a string in the YYYY-MM-DD format.
92
+ * @param date The date to get the last day of the month for. It can be an
93
+ * SDate or a string in the YYYY-MM-DD format.
94
94
  */
95
95
  export const getDateForLastDayOfMonth = (date) => {
96
96
  const sDateValue = sDate(date);
@@ -105,19 +105,19 @@ export const getDateForLastDayOfMonth = (date) => {
105
105
  /**
106
106
  * Returns the year from the given date.
107
107
  *
108
- * @param date The date to get the year from. It can be an SDate or a string in
109
- * the YYYY-MM-DD format.
108
+ * @param date The date to get the year from. It can be an SDate or a string
109
+ * in the YYYY-MM-DD format.
110
110
  */
111
111
  export const getYearFromDate = (date) => {
112
112
  const sDateValue = sDate(date);
113
113
  return Number(getISOYearFromISODate(sDateValue.date));
114
114
  };
115
115
  /**
116
- * Returns the month from the given date. Returns a 0-index value (i.e. Janary
116
+ * Returns the month from the given date. Returns a 0-index value (i.e. January
117
117
  * is 0 and December is 11) to match the result from native Date object.
118
118
  *
119
- * @param date The date to get the month from. It can be an SDate or a string in
120
- * the YYYY-MM-DD format.
119
+ * @param date The date to get the month from. It can be an SDate or a string
120
+ * in the YYYY-MM-DD format.
121
121
  */
122
122
  export const getMonthFromDate = (date) => {
123
123
  const sDateValue = sDate(date);
@@ -126,8 +126,8 @@ export const getMonthFromDate = (date) => {
126
126
  /**
127
127
  * Returns the day of the month from the given date.
128
128
  *
129
- * @param date The date to get the day from. It can be an SDate or a string in
130
- * the YYYY-MM-DD format.
129
+ * @param date The date to get the day from. It can be an SDate or a string
130
+ * in the YYYY-MM-DD format.
131
131
  */
132
132
  export const getDateFromDate = (date) => {
133
133
  const sDateValue = sDate(date);
@@ -137,8 +137,8 @@ export const getDateFromDate = (date) => {
137
137
  * Returns the day of the week from the given date (Sunday to Saturday / 0 to
138
138
  * 6).
139
139
  *
140
- * @param date The date to get the weekday from. It can be an SDate or a string
141
- * in the YYYY-MM-DD format.
140
+ * @param date The date to get the weekday from. It can be an SDate or a
141
+ * string in the YYYY-MM-DD format.
142
142
  */
143
143
  export const getWeekdayFromDate = (date) => {
144
144
  const sDateValue = sDate(date);
@@ -167,8 +167,8 @@ export const getUTCMillisecondsFromDate = (date, timeZone) => {
167
167
  * Returns a native Date adjusted so that the local time of that date matches
168
168
  * the local time at the specified time zone.
169
169
  *
170
- * @param date The date to get the time zoned date from. It can be an SDate or a
171
- * string in the YYYY-MM-DD format.
170
+ * @param date The date to get the time zoned date from. It can be an SDate
171
+ * or a string in the YYYY-MM-DD format.
172
172
  * @param timeZone The time zone to adjust the date to. See
173
173
  * `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
174
174
  */
@@ -185,10 +185,10 @@ export const getTimeZonedDateFromDate = (date, timeZone) => {
185
185
  * and not full 24-hour periods which could be different due to daylight saving
186
186
  * adjustments.
187
187
  *
188
- * @param date1 The first date to get the days between. It can be an SDate or a
189
- * string in the YYYY-MM-DD format.
190
- * @param date2 The second date to get the days between. It can be an SDate or a
191
- * string in the YYYY-MM-DD format.
188
+ * @param date1 The first date to get the days between. It can be an SDate or
189
+ * a string in the YYYY-MM-DD format.
190
+ * @param date2 The second date to get the days between. It can be an SDate
191
+ * or a string in the YYYY-MM-DD format.
192
192
  */
193
193
  export const getDaysBetweenDates = (date1, date2) => {
194
194
  const sDate1 = sDate(date1);
@@ -201,8 +201,8 @@ export const getDaysBetweenDates = (date1, date2) => {
201
201
  * Returns a string representation that includes all of the date components of
202
202
  * the given date formatted according to the given locale.
203
203
  *
204
- * @param date The date to get the full string representation for. It can be an
205
- * SDate or a string in the YYYY-MM-DD format.
204
+ * @param date The date to get the full string representation for. It can be
205
+ * an SDate or a string in the YYYY-MM-DD format.
206
206
  * @param locale The locale to use for the string representation.
207
207
  *
208
208
  * @example
@@ -228,10 +228,10 @@ export const getFullDateString = (date, locale) => {
228
228
  /**
229
229
  * Get the short string representation of the given date in the given locale.
230
230
  *
231
- * @param date The date to get the short string representation for. It can be an
232
- * SDate or a string in the YYYY-MM-DD format.
233
- * @param timeZone The time zone used to determine if in the current year. See
234
- * `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
231
+ * @param date The date to get the short string representation for. It can be
232
+ * an SDate or a string in the YYYY-MM-DD format.
233
+ * @param timeZone The time zone used to determine if in the current year.
234
+ * See `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
235
235
  * @param locale The locale to use for the string representation.
236
236
  * @param options The options to customize the short string representation.
237
237
  *
@@ -272,7 +272,7 @@ export const getShortDateString = (date, timeZone, locale, options) => {
272
272
  * --- Operations ---
273
273
  */
274
274
  /**
275
- * Returns a new SDates instance with the date resulting from adding the given
275
+ * Returns a new SDate instance with the date resulting from adding the given
276
276
  * number of days to the given date. Because it adds calendar days rather than
277
277
  * 24-hour days, this operation is not affected by time zones.
278
278
  *
@@ -376,8 +376,8 @@ export const addYearsToDate = (date, years) => {
376
376
  * Returns true when the two given dates represent the same day and false
377
377
  * otherwise.
378
378
  *
379
- * @param date1 The first date to compare. It can be an SDate or a string in the
380
- * YYYY-MM-DD format.
379
+ * @param date1 The first date to compare. It can be an SDate or a string in
380
+ * the YYYY-MM-DD format.
381
381
  * @param date2 The second date to compare. It can be an SDate or a string in
382
382
  * the YYYY-MM-DD format.
383
383
  */
@@ -390,8 +390,8 @@ export const isSameDate = (date1, date2) => {
390
390
  * Returns true when the first date represents a date before the second date and
391
391
  * false otherwise.
392
392
  *
393
- * @param date1 The first date to compare. It can be an SDate or a string in the
394
- * YYYY-MM-DD format.
393
+ * @param date1 The first date to compare. It can be an SDate or a string in
394
+ * the YYYY-MM-DD format.
395
395
  * @param date2 The second date to compare. It can be an SDate or a string in
396
396
  * the YYYY-MM-DD format.
397
397
  */
package/dist/sTime.d.ts CHANGED
@@ -5,7 +5,7 @@ import { STime } from './internal/STime.js';
5
5
  /**
6
6
  * Returns a new STime instance.
7
7
  *
8
- * @param time And instance of STime or a string in the format 'HH:MM'.
8
+ * @param time An instance of STime or a string in the format 'HH:MM'.
9
9
  */
10
10
  export declare const sTime: (time: string | STime) => STime;
11
11
  /**
package/dist/sTime.js CHANGED
@@ -8,7 +8,7 @@ import { getTimeZonedDate } from './internal/zoned.js';
8
8
  /**
9
9
  * Returns a new STime instance.
10
10
  *
11
- * @param time And instance of STime or a string in the format 'HH:MM'.
11
+ * @param time An instance of STime or a string in the format 'HH:MM'.
12
12
  */
13
13
  export const sTime = (time) => {
14
14
  if (time instanceof STime) {
@@ -1,8 +1,15 @@
1
1
  import { SDate } from './internal/SDate.js';
2
2
  import { STime } from './internal/STime.js';
3
3
  import { STimestamp } from './internal/STimestamp.js';
4
+ /**
5
+ * Options for customizing the short timestamp string representation.
6
+ */
4
7
  export interface STimestampShortStringOptions {
8
+ /** Whether to include the abbreviated weekday name in the output. */
5
9
  includeWeekday: boolean;
10
+ /**
11
+ * Called when the timestamp is today. Return value is used as prefix text.
12
+ */
6
13
  onTodayAtText: () => string;
7
14
  }
8
15
  /**
@@ -66,9 +73,9 @@ export declare const getUTCMillisecondsFromTimestamp: (timestamp: string | STime
66
73
  * Returns a native Date adjusted so that the local time of that date matches
67
74
  * the local timestamp at the specified time zone.
68
75
  *
69
- * @param date The date to get the time zoned date from. It can be an SDate or a
70
- * string in the YYYY-MM-DD format.
71
- * @param timeZone The time zone to adjust the date to. See
76
+ * @param timestamp The timestamp to get the time zoned date from. It can be
77
+ * an STimestamp or a string in the YYYY-MM-DDTHH:MM format.
78
+ * @param timeZone The time zone to adjust the timestamp to. See
72
79
  * `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
73
80
  */
74
81
  export declare const getTimeZonedDateFromTimestamp: (timestamp: string | STimestamp, timeZone: string) => Date;
@@ -230,7 +237,7 @@ export declare const addDaysToTimestamp: (timestamp: string | STimestamp, days:
230
237
  * 2024-03-10T02:00 (a time that technically does not exist on a watch that
231
238
  * automatically adjusts for Daylight Saving) will result in 2024-03-10T01:01.
232
239
  * This is because 2024-03-10T02:00 is converted to 2024-03-10T06:00 UTC (due
233
- * to timezone offset being -4 starting from 02:00 local time) and one minute
240
+ * to time zone offset being -4 starting from 02:00 local time) and one minute
234
241
  * later would be 2024-03-10T06:01 UTC which would be 2024-03-10T01:01 in
235
242
  * `America/New_York`. A similar situation happens when the time zone
236
243
  * transitions from Daylight Saving Time to Standard Time as can be derived from
@@ -57,8 +57,8 @@ export const getTimestampNow = (timeZone) => {
57
57
  */
58
58
  export const getTimestampFromDateAndTime = (date, time) => {
59
59
  const sDateValue = sDate(date);
60
- const sDimeValue = sTime(time);
61
- return sTimestamp(`${sDateValue.date}T${sDimeValue.time}`);
60
+ const sTimeValue = sTime(time);
61
+ return sTimestamp(`${sDateValue.date}T${sTimeValue.time}`);
62
62
  };
63
63
  /**
64
64
  * --- Getters ---
@@ -88,9 +88,9 @@ export const getUTCMillisecondsFromTimestamp = (timestamp, timeZone) => {
88
88
  * Returns a native Date adjusted so that the local time of that date matches
89
89
  * the local timestamp at the specified time zone.
90
90
  *
91
- * @param date The date to get the time zoned date from. It can be an SDate or a
92
- * string in the YYYY-MM-DD format.
93
- * @param timeZone The time zone to adjust the date to. See
91
+ * @param timestamp The timestamp to get the time zoned date from. It can be
92
+ * an STimestamp or a string in the YYYY-MM-DDTHH:MM format.
93
+ * @param timeZone The time zone to adjust the timestamp to. See
94
94
  * `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
95
95
  */
96
96
  export const getTimeZonedDateFromTimestamp = (timestamp, timeZone) => {
@@ -282,7 +282,7 @@ export const addDaysToTimestamp = (timestamp, days) => {
282
282
  * 2024-03-10T02:00 (a time that technically does not exist on a watch that
283
283
  * automatically adjusts for Daylight Saving) will result in 2024-03-10T01:01.
284
284
  * This is because 2024-03-10T02:00 is converted to 2024-03-10T06:00 UTC (due
285
- * to timezone offset being -4 starting from 02:00 local time) and one minute
285
+ * to time zone offset being -4 starting from 02:00 local time) and one minute
286
286
  * later would be 2024-03-10T06:01 UTC which would be 2024-03-10T01:01 in
287
287
  * `America/New_York`. A similar situation happens when the time zone
288
288
  * transitions from Daylight Saving Time to Standard Time as can be derived from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scdate",
3
- "version": "2.1.1",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"