scdate 0.2.3 → 0.2.5
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/index.d.ts +9 -9
- package/dist/index.js +5 -5
- package/dist/internal/SDate.d.ts +3 -0
- package/dist/internal/SDate.js +4 -1
- package/dist/internal/STime.d.ts +3 -0
- package/dist/internal/STime.js +4 -1
- package/dist/internal/STimestamp.d.ts +3 -0
- package/dist/internal/STimestamp.js +4 -1
- package/dist/internal/SWeekdays.d.ts +7 -0
- package/dist/internal/SWeekdays.js +8 -1
- package/dist/internal/constants.d.ts +1 -1
- package/dist/internal/constants.js +1 -1
- package/dist/internal/date.d.ts +1 -1
- package/dist/internal/date.js +1 -0
- package/dist/internal/time.js +2 -0
- package/dist/internal/timestamp.d.ts +1 -1
- package/dist/internal/timestamp.js +2 -2
- package/dist/internal/utils.d.ts +4 -0
- package/dist/internal/utils.js +4 -0
- package/dist/internal/weekdays.d.ts +1 -1
- package/dist/internal/weekdays.js +1 -1
- package/dist/internal/zoned.d.ts +6 -2
- package/dist/internal/zoned.js +6 -2
- package/dist/sDate.d.ts +282 -2
- package/dist/sDate.js +289 -6
- package/dist/sTime.d.ts +132 -1
- package/dist/sTime.js +135 -4
- package/dist/sTimestamp.d.ts +269 -3
- package/dist/sTimestamp.js +272 -6
- package/dist/sWeekdays.d.ts +119 -3
- package/dist/sWeekdays.js +123 -5
- package/package.json +8 -8
package/dist/sTime.js
CHANGED
|
@@ -1,44 +1,109 @@
|
|
|
1
|
-
import { STime } from './internal/STime';
|
|
2
|
-
import { MinutesInDay, MinutesInHour } from './internal/constants';
|
|
3
|
-
import { getISOHoursFromISOTime, getISOMinutesFromISOTime, getISOTimeFromDate, } from './internal/time';
|
|
4
|
-
import { getTimeZonedDate } from './internal/zoned';
|
|
1
|
+
import { STime } from './internal/STime.js';
|
|
2
|
+
import { MinutesInDay, MinutesInHour } from './internal/constants.js';
|
|
3
|
+
import { getISOHoursFromISOTime, getISOMinutesFromISOTime, getISOTimeFromDate, } from './internal/time.js';
|
|
4
|
+
import { getTimeZonedDate } from './internal/zoned.js';
|
|
5
|
+
/**
|
|
6
|
+
* --- Factory ---
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Returns a new STime instance.
|
|
10
|
+
*
|
|
11
|
+
* @param time And instance of STime or a string in the format 'HH:MM'.
|
|
12
|
+
*/
|
|
5
13
|
export const sTime = (time) => {
|
|
6
14
|
if (time instanceof STime) {
|
|
7
15
|
return time;
|
|
8
16
|
}
|
|
9
17
|
return new STime(time);
|
|
10
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* --- Factory helpers ---
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Returns a new STime instance with the current time in the given time zone.
|
|
24
|
+
*
|
|
25
|
+
* @param timeZone The time zone to get the current time in. See
|
|
26
|
+
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
27
|
+
*/
|
|
11
28
|
export const getTimeNow = (timeZone) => {
|
|
12
29
|
const date = getTimeZonedDate(Date.now(), timeZone);
|
|
13
30
|
return sTime(getISOTimeFromDate(date));
|
|
14
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Returns a new STime instance with the time at midnight (00:00).
|
|
34
|
+
*/
|
|
15
35
|
export const getTimeAtMidnight = () => sTime('00:00');
|
|
36
|
+
/**
|
|
37
|
+
* Returns a new STime instance with the time resulting from adding the given
|
|
38
|
+
* number of minutes to midnight (00:00).
|
|
39
|
+
*
|
|
40
|
+
* @param timeInMinutes The number of minutes to add to midnight.
|
|
41
|
+
*/
|
|
16
42
|
export const getTimeFromMinutes = (timeInMinutes) => {
|
|
17
43
|
const midnight = getTimeAtMidnight();
|
|
18
44
|
return addMinutesToTime(midnight, timeInMinutes);
|
|
19
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* --- Getters ---
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Returns the hours from the given time.
|
|
51
|
+
*
|
|
52
|
+
* @param time The time to get the hours from. It can be an STime or a string
|
|
53
|
+
* in the HH:MM format.
|
|
54
|
+
*/
|
|
20
55
|
export const getHoursFromTime = (time) => {
|
|
21
56
|
const sTimeValue = sTime(time);
|
|
22
57
|
return Number(getISOHoursFromISOTime(sTimeValue.time));
|
|
23
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Returns the hours from given time as a string (1 - 12).
|
|
61
|
+
*
|
|
62
|
+
* @param time The time to get the hours from. It can be an STime or a string
|
|
63
|
+
* in the HH:MM format.
|
|
64
|
+
*/
|
|
24
65
|
export const get12HoursHoursStringFromTime = (time) => {
|
|
25
66
|
const HoursPMStart = 12;
|
|
26
67
|
const sTimeValue = sTime(time);
|
|
27
68
|
const hours = getHoursFromTime(sTimeValue) % HoursPMStart;
|
|
28
69
|
return hours === 0 ? '12' : hours.toString();
|
|
29
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Returns the minutes from the given time.
|
|
73
|
+
*
|
|
74
|
+
* @param time The time to get the minutes from. It can be an STime or a string
|
|
75
|
+
* in the HH:MM format.
|
|
76
|
+
*/
|
|
30
77
|
export const getMinutesFromTime = (time) => {
|
|
31
78
|
const sTimeValue = sTime(time);
|
|
32
79
|
return Number(getISOMinutesFromISOTime(sTimeValue.time));
|
|
33
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Returns the minutes from given time as a string (00-59).
|
|
83
|
+
*
|
|
84
|
+
* @param time The time to get the minutes from. It can be an STime or a string
|
|
85
|
+
* in the HH:MM format.
|
|
86
|
+
*/
|
|
34
87
|
export const getMinutesStringFromTime = (time) => {
|
|
35
88
|
const sTimeValue = sTime(time);
|
|
36
89
|
return getISOMinutesFromISOTime(sTimeValue.time);
|
|
37
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Returns a string that represents the time in a 12-hour format (HH:MM AM/PM).
|
|
93
|
+
*
|
|
94
|
+
* @param time The time to get the string from. It can be an STime or a string
|
|
95
|
+
* in the HH:MM format.
|
|
96
|
+
*/
|
|
38
97
|
export const get12HourTimeString = (time) => {
|
|
39
98
|
const sTimeValue = sTime(time);
|
|
40
99
|
return `${get12HoursHoursStringFromTime(sTimeValue)}:${getMinutesStringFromTime(sTimeValue)} ${isTimePM(sTimeValue) ? 'PM' : 'AM'}`;
|
|
41
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Returns the time converted to minutes since midnight.
|
|
103
|
+
*
|
|
104
|
+
* @param time The time to get the minutes from. It can be an STime or a string
|
|
105
|
+
* in the HH:MM format.
|
|
106
|
+
*/
|
|
42
107
|
export const getTimeInMinutes = (time, midnightIs24 = false) => {
|
|
43
108
|
const sTimeValue = sTime(time);
|
|
44
109
|
const timeInMinutesMidnight0 = getHoursFromTime(sTimeValue) * MinutesInHour +
|
|
@@ -48,6 +113,18 @@ export const getTimeInMinutes = (time, midnightIs24 = false) => {
|
|
|
48
113
|
}
|
|
49
114
|
return timeInMinutesMidnight0;
|
|
50
115
|
};
|
|
116
|
+
/**
|
|
117
|
+
* --- Operations ---
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* Returns a new STime instance with the time resulting from adding the given
|
|
121
|
+
* number of minutes to the given time. The time will wrap around a 24 hour
|
|
122
|
+
* clock.
|
|
123
|
+
*
|
|
124
|
+
* @param time The time to add the minutes to. It can be an STime or a string
|
|
125
|
+
* in the HH:MM format.
|
|
126
|
+
* @param minutes The number of minutes to add.
|
|
127
|
+
*/
|
|
51
128
|
export const addMinutesToTime = (time, minutes) => {
|
|
52
129
|
const sTimeValue = sTime(time);
|
|
53
130
|
let totalMinutes = (getTimeInMinutes(sTimeValue) + minutes) % MinutesInDay;
|
|
@@ -58,31 +135,85 @@ export const addMinutesToTime = (time, minutes) => {
|
|
|
58
135
|
const newMinutes = totalMinutes % MinutesInHour;
|
|
59
136
|
return sTime(`${newHours.toString().padStart(2, '0')}:${newMinutes.toString().padStart(2, '0')}`);
|
|
60
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* --- Comparisons ---
|
|
140
|
+
*/
|
|
141
|
+
/**
|
|
142
|
+
* Returns true when the two times are the same and false otherwise.
|
|
143
|
+
*
|
|
144
|
+
* @param time1 The first time to compare. It can be an STime or a string in the
|
|
145
|
+
* HH:MM format.
|
|
146
|
+
* @param time2 The second time to compare. It can be an STime or a string in
|
|
147
|
+
* the HH:MM format.
|
|
148
|
+
*/
|
|
61
149
|
export const isSameTime = (time1, time2) => {
|
|
62
150
|
const sTime1 = sTime(time1);
|
|
63
151
|
const sTime2 = sTime(time2);
|
|
64
152
|
return sTime1.time === sTime2.time;
|
|
65
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* Returns true when first time represents a time that happens after the second
|
|
156
|
+
* time. Returns false otherwise.
|
|
157
|
+
*
|
|
158
|
+
* @param time1 The first time to compare. It can be an STime or a string in the
|
|
159
|
+
* HH:MM format.
|
|
160
|
+
* @param time2 The second time to compare. It can be an STime or a string in
|
|
161
|
+
* the HH:MM format.
|
|
162
|
+
*/
|
|
66
163
|
export const isAfterTime = (time1, time2) => {
|
|
67
164
|
const sTime1 = sTime(time1);
|
|
68
165
|
const sTime2 = sTime(time2);
|
|
69
166
|
return sTime1.time > sTime2.time;
|
|
70
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Returns true when first time represents a time that happens after or at the
|
|
170
|
+
* same time as the second time. Returns false otherwise.
|
|
171
|
+
*
|
|
172
|
+
* @param time1 The first time to compare. It can be an STime or a string in the
|
|
173
|
+
* HH:MM format.
|
|
174
|
+
* @param time2 The second time to compare. It can be an STime or a string in
|
|
175
|
+
* the HH:MM format.
|
|
176
|
+
*/
|
|
71
177
|
export const isSameTimeOrAfter = (time1, time2) => {
|
|
72
178
|
const sTime1 = sTime(time1);
|
|
73
179
|
const sTime2 = sTime(time2);
|
|
74
180
|
return sTime1.time >= sTime2.time;
|
|
75
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* Returns true when first time represents a time that happens before the
|
|
184
|
+
* second time. Returns false otherwise.
|
|
185
|
+
*
|
|
186
|
+
* @param time1 The first time to compare. It can be an STime or a string in the
|
|
187
|
+
* HH:MM format.
|
|
188
|
+
* @param time2 The second time to compare. It can be an STime or a string in
|
|
189
|
+
* the HH:MM format.
|
|
190
|
+
*/
|
|
76
191
|
export const isBeforeTime = (time1, time2) => {
|
|
77
192
|
const sTime1 = sTime(time1);
|
|
78
193
|
const sTime2 = sTime(time2);
|
|
79
194
|
return sTime1.time < sTime2.time;
|
|
80
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* Returns true when first time represents a time that happens before or at the
|
|
198
|
+
* same time as the second time. Returns false otherwise.
|
|
199
|
+
*
|
|
200
|
+
* @param time1 The first time to compare. It can be an STime or a string in the
|
|
201
|
+
* HH:MM format.
|
|
202
|
+
* @param time2 The second time to compare. It can be an STime or a string in
|
|
203
|
+
* the HH:MM format.
|
|
204
|
+
*/
|
|
81
205
|
export const isSameTimeOrBefore = (time1, time2) => {
|
|
82
206
|
const sTime1 = sTime(time1);
|
|
83
207
|
const sTime2 = sTime(time2);
|
|
84
208
|
return sTime1.time <= sTime2.time;
|
|
85
209
|
};
|
|
210
|
+
/**
|
|
211
|
+
* Returns true when the given time is at or after noon (12:00) and false
|
|
212
|
+
* otherwise.
|
|
213
|
+
*
|
|
214
|
+
* @param time The time to check. It can be an STime or a string in the HH:MM
|
|
215
|
+
* format.
|
|
216
|
+
*/
|
|
86
217
|
export const isTimePM = (time) => {
|
|
87
218
|
const sTimeValue = sTime(time);
|
|
88
219
|
const NoonValue = '12:00';
|
package/dist/sTimestamp.d.ts
CHANGED
|
@@ -1,23 +1,289 @@
|
|
|
1
|
-
import { SDate } from './internal/SDate';
|
|
2
|
-
import { STime } from './internal/STime';
|
|
3
|
-
import { STimestamp } from './internal/STimestamp';
|
|
1
|
+
import { SDate } from './internal/SDate.js';
|
|
2
|
+
import { STime } from './internal/STime.js';
|
|
3
|
+
import { STimestamp } from './internal/STimestamp.js';
|
|
4
4
|
export interface STimestampShortStringOptions {
|
|
5
5
|
includeWeekday: boolean;
|
|
6
6
|
onTodayAtText: () => string;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* --- Factory ---
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Returns a new STimestamp instance.
|
|
13
|
+
*
|
|
14
|
+
* @param timestamp An instance of STimestamp or a string in the
|
|
15
|
+
* YYYY-MM-DDTHH:MM format.
|
|
16
|
+
*/
|
|
8
17
|
export declare const sTimestamp: (timestamp: string | STimestamp) => STimestamp;
|
|
18
|
+
/**
|
|
19
|
+
* --- Factory helpers ---
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Returns a new STimestamp instance set to the date and time that results from
|
|
23
|
+
* converting the given number of milliseconds since the Unix epoch to the given
|
|
24
|
+
* time zone.
|
|
25
|
+
*
|
|
26
|
+
* @param utcDateInMilliseconds The number of milliseconds since the Unix epoch.
|
|
27
|
+
* @param timeZone The time zone to use when creating the timestamp. See
|
|
28
|
+
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
29
|
+
*/
|
|
9
30
|
export declare const getTimestampFromUTCMilliseconds: (utcDateInMilliseconds: number, timeZone: string) => STimestamp;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a new STimestamp instance set to the current date and time in the
|
|
33
|
+
* given time zone.
|
|
34
|
+
*
|
|
35
|
+
* @param timeZone The time zone to use when creating the timestamp. See
|
|
36
|
+
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
37
|
+
*/
|
|
10
38
|
export declare const getTimestampNow: (timeZone: string) => STimestamp;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a new STimestamp instance set to the date and time that results from
|
|
41
|
+
* combining the given date and time.
|
|
42
|
+
*
|
|
43
|
+
* @param date The date to use when creating the timestamp. It can be an SDate
|
|
44
|
+
* or a string in the YYYY-MM-DD format.
|
|
45
|
+
* @param time The time to use when creating the timestamp. It can be an STime
|
|
46
|
+
* or a string in the HH:MM format.
|
|
47
|
+
*/
|
|
11
48
|
export declare const getTimestampFromDateAndTime: (date: string | SDate, time: string | STime) => STimestamp;
|
|
49
|
+
/**
|
|
50
|
+
* --- Getters ---
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Returns a native Date adjusted so that the local time of that date matches
|
|
54
|
+
* the local timestamp at the specified time zone.
|
|
55
|
+
*
|
|
56
|
+
* @param date The date to get the time zoned date from. It can be an SDate or a
|
|
57
|
+
* string in the YYYY-MM-DD format.
|
|
58
|
+
* @param timeZone The time zone to adjust the date to. See
|
|
59
|
+
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
60
|
+
*/
|
|
12
61
|
export declare const getTimeZonedDateFromTimestamp: (timestamp: string | STimestamp, timeZone: string) => Date;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the number of seconds from now to the given timestamp. If the
|
|
64
|
+
* timestamp is in the future, the number of seconds will be positive. If the
|
|
65
|
+
* timestamp is in the past, the number of seconds will be negative.
|
|
66
|
+
*
|
|
67
|
+
* Daylight Saving Notes:
|
|
68
|
+
*
|
|
69
|
+
* The following notes use `America/New_York` as the time zone to explain how
|
|
70
|
+
* Daylight Savings is handled, but it works the same across time zones on their
|
|
71
|
+
* respective Daylight Saving schedules as defined by Intl API.
|
|
72
|
+
*
|
|
73
|
+
* Notice that when looking at a watch (that adjusts for Daylight Saving
|
|
74
|
+
* automatically) on 2024-03-10 (the day Daylight Savings goes into effect and
|
|
75
|
+
* the time moves forward one hour) the times between 02:00 and 02:59 never
|
|
76
|
+
* happen as the watch goes from 01:59 to 03:00. In the case of 2024-11-03 (the
|
|
77
|
+
* day the time zone goes back to Standard Time), the times between 01:00 and
|
|
78
|
+
* 01:59 happen twice as the first time the watch hits 02:00 it goes back to
|
|
79
|
+
* 01:00.
|
|
80
|
+
*
|
|
81
|
+
* To account for time zone changes, this method converts the timestamp to UTC
|
|
82
|
+
* milliseconds (for both the current time and the expected timestamp) before
|
|
83
|
+
* calculating the difference in seconds. This works as expected for all times,
|
|
84
|
+
* but the expectation for the transition times (those that don't happen on a
|
|
85
|
+
* watch that automatically adjusts or that happen twice) it can work in
|
|
86
|
+
* unexpected ways.
|
|
87
|
+
*
|
|
88
|
+
* For example, trying to calculate the number of seconds to 2024-03-10T02:00
|
|
89
|
+
* (the start of Daylight Saving Time) at 2024-03-10T01:59 (still in Standard
|
|
90
|
+
* Time) will result in -3540 seconds (59 minutes in the past). A similar
|
|
91
|
+
* situation happens when the time zone transitions from Daylight Saving Time to
|
|
92
|
+
* Standard Time as can be derived from the table below.
|
|
93
|
+
*
|
|
94
|
+
* In 'America/New_York'
|
|
95
|
+
*
|
|
96
|
+
* Transition to Eastern Daylight Time (EDT) in 2024
|
|
97
|
+
* | Time Zone | T1 | T2 | T3 |
|
|
98
|
+
* |------------------|-----------------------|------------------------|-----------------------|
|
|
99
|
+
* | America/New_York | 2024-03-10T01:59(EST) | 2024-03-10T02:00(EDT) | 2024-03-10T03:00(EST) |
|
|
100
|
+
* | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 | 2024-03-10T07:00 |
|
|
101
|
+
*
|
|
102
|
+
* Transition to Eastern Standard Time (EST) in 2024
|
|
103
|
+
* | Time Zone | T1 | T2 | T3 |
|
|
104
|
+
* |------------------|-----------------------|------------------------|-----------------------|
|
|
105
|
+
* | America/New_York | 2024-11-03T01:59(EDT) | 2024-11-03T02:00(EST) | 2024-11-03T03:00(EST) |
|
|
106
|
+
* | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 | 2024-11-03T08:00 |
|
|
107
|
+
*
|
|
108
|
+
* @param timestamp The timestamp to get the seconds to. It can be an STimestamp
|
|
109
|
+
* or a string in the YYYY-MM-DDTHH:MM format.
|
|
110
|
+
* @param timeZone The time zone to use when creating the timestamp. See
|
|
111
|
+
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
112
|
+
*/
|
|
13
113
|
export declare const getSecondsToTimestamp: (timestamp: string | STimestamp, timeZone: string) => number;
|
|
114
|
+
/**
|
|
115
|
+
* Returns a new SDate instance set to the date part of the given timestamp.
|
|
116
|
+
*
|
|
117
|
+
* @param timestamp The timestamp to get the date from. It can be an STimestamp
|
|
118
|
+
* or a string in the YYYY-MM-DDTHH:MM format.
|
|
119
|
+
*/
|
|
14
120
|
export declare const getDateFromTimestamp: (timestamp: string | STimestamp) => SDate;
|
|
121
|
+
/**
|
|
122
|
+
* Returns a new STime instance set to the time part of the given timestamp.
|
|
123
|
+
*
|
|
124
|
+
* @param timestamp The timestamp to get the time from. It can be an STimestamp
|
|
125
|
+
* or a string in the YYYY-MM-DDTHH:MM format.
|
|
126
|
+
*/
|
|
15
127
|
export declare const getTimeFromTimestamp: (timestamp: string | STimestamp) => STime;
|
|
128
|
+
/**
|
|
129
|
+
* Returns a string representation that includes a minimum set of components
|
|
130
|
+
* from the given timestamp. This is a combination of the the results of
|
|
131
|
+
* the `getShortDateString` method, and `get12HourTimeString`.
|
|
132
|
+
*
|
|
133
|
+
* @param timestamp The timestamp to get the short string from. It can be an
|
|
134
|
+
* STimestamp or a string in the YYYY-MM-DDTHH:MM format.
|
|
135
|
+
* @param timeZone The time zone to use when creating the short string. See
|
|
136
|
+
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
137
|
+
* @param locale The locale to use for the string representation.
|
|
138
|
+
* @param options An object with options for the short string representation.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* // Example when the timestamp is today
|
|
143
|
+
* getShortTimestampString('2021-08-10T08:00', 'America/Puerto_Rico', 'en', {
|
|
144
|
+
* includeWeekday: true,
|
|
145
|
+
* onTodayAtText: () => 'Today at',
|
|
146
|
+
* })
|
|
147
|
+
* //=> 'Today at 8:00 AM'
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* // Example when the timestamp is not today
|
|
153
|
+
* getShortTimestampString('2022-09-11T08:00', 'America/Puerto_Rico', 'es', {
|
|
154
|
+
* includeWeekday: true,
|
|
155
|
+
* onTodayAtText: () => 'Hoy a las',
|
|
156
|
+
* })
|
|
157
|
+
* //=> 'dom, 11 sept 22 8:00 AM'
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
16
160
|
export declare const getShortTimestampString: (timestamp: string | STimestamp, timeZone: string, locale: Intl.LocalesArgument, options: STimestampShortStringOptions) => string;
|
|
161
|
+
/**
|
|
162
|
+
* --- Operations ---
|
|
163
|
+
*/
|
|
164
|
+
/**
|
|
165
|
+
* Returns a new STimestamp instance resulting from adding the given number of
|
|
166
|
+
* calendar days to the given timestamp. Because it adds calendar days rather
|
|
167
|
+
* than 24-hour days, this operation is not affected by time zones.
|
|
168
|
+
*
|
|
169
|
+
* @param timestamp The timestamp to add days to. It can be an STimestamp or a
|
|
170
|
+
* string in the YYYY-MM-DDTHH:MM format.
|
|
171
|
+
* @param days The number of days to add to the timestamp.
|
|
172
|
+
*/
|
|
17
173
|
export declare const addDaysToTimestamp: (timestamp: string | STimestamp, days: number) => STimestamp;
|
|
174
|
+
/**
|
|
175
|
+
* Returns a new STimestamp instance resulting from adding the given number of
|
|
176
|
+
* minutes to the given timestamp.
|
|
177
|
+
*
|
|
178
|
+
* Daylight Saving Time Notes:
|
|
179
|
+
*
|
|
180
|
+
* The following notes use `America/New_York` as the time zone to explain how
|
|
181
|
+
* Daylight Savings is handled, but it works the same across time zones on their
|
|
182
|
+
* respective Daylight Saving schedules as defined by Intl API.
|
|
183
|
+
*
|
|
184
|
+
* Notice that when looking at a watch (that adjusts for Daylight Saving
|
|
185
|
+
* automatically) on 2024-03-10 (the day Daylight Savings goes into effect and
|
|
186
|
+
* the time moves forward one hour) the times between 02:00 and 02:59 never
|
|
187
|
+
* happen as the watch goes from 01:59 to 03:00. In the case of 2024-11-03 (the
|
|
188
|
+
* day the time zone goes back to Standard Time), the times between 01:00 and
|
|
189
|
+
* 01:59 happen twice as the first time the watch hits 02:00 it goes back to
|
|
190
|
+
* 01:00.
|
|
191
|
+
*
|
|
192
|
+
* To account for time zone changes, this method converts the timestamp to UTC
|
|
193
|
+
* milliseconds before adding the specified minutes. This works as expected for
|
|
194
|
+
* all times, but the expectation for the transition times (those that don't
|
|
195
|
+
* happen on a watch that automatically adjusts or that happen twice) it can
|
|
196
|
+
* work in unexpected ways.
|
|
197
|
+
*
|
|
198
|
+
* Time is converted from the given time zone to
|
|
199
|
+
* UTC before the minutes are added, and then converted back to the specified
|
|
200
|
+
* time zone. This results in the resulting time being adjusted for daylight saving time
|
|
201
|
+
* changes. (e.g. Adding 60 minutes to 2024-03-10T01:59 in America/New_York will
|
|
202
|
+
* result in 2024-03-10T03:59 as time move forward one hour for daylight saving
|
|
203
|
+
* time at 2024-03-10T02:00.)
|
|
204
|
+
*
|
|
205
|
+
* For example, adding one minute to 2024-03-10T01:59 will result in
|
|
206
|
+
* 2024-03-10T03:00 as expected. However, trying to add one minute to
|
|
207
|
+
* 2024-03-10T02:00 (a time that technically does not exist on a watch that
|
|
208
|
+
* automatically adjusts for Daylight Saving) will result in 2024-03-10T01:01.
|
|
209
|
+
* This is because 2024-03-10T02:00 is converted to 2024-03-10T06:00 UTC (due
|
|
210
|
+
* to timezone offset being -4 starting from 02:00 local time) and one minute
|
|
211
|
+
* later would be 2024-03-10T06:01 UTC which would be 2024-03-10T01:01 in
|
|
212
|
+
* `America/New_York`. A similar situation happens when the time zone
|
|
213
|
+
* transitions from Daylight Saving Time to Standard Time as can be derived from
|
|
214
|
+
* the table below.
|
|
215
|
+
*
|
|
216
|
+
* In 'America/New_York'
|
|
217
|
+
*
|
|
218
|
+
* Transition to Eastern Daylight Time (EDT) in 2024
|
|
219
|
+
* | Time Zone | T1 | T2 | T3 |
|
|
220
|
+
* |------------------|-----------------------|------------------------|-----------------------|
|
|
221
|
+
* | America/New_York | 2024-03-10T01:59(EST) | 2024-03-10T02:00(EDT) | 2024-03-10T03:00(EST) |
|
|
222
|
+
* | UTC | 2024-03-10T06:59 | 2024-03-10T06:00 | 2024-03-10T07:00 |
|
|
223
|
+
*
|
|
224
|
+
* Transition to Eastern Standard Time (EST) in 2024
|
|
225
|
+
* | Time Zone | T1 | T2 | T3 |
|
|
226
|
+
* |------------------|-----------------------|------------------------|-----------------------|
|
|
227
|
+
* | America/New_York | 2024-11-03T01:59(EDT) | 2024-11-03T02:00(EST) | 2024-11-03T03:00(EST) |
|
|
228
|
+
* | UTC | 2024-11-03T05:59 | 2024-11-03T07:00 | 2024-11-03T08:00 |
|
|
229
|
+
*
|
|
230
|
+
* @param timestamp The timestamp to add minutes to. It can be an STimestamp or
|
|
231
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
232
|
+
* @param minutes The number of minutes to add to the timestamp.
|
|
233
|
+
* @param timeZone The time zone to use when creating the timestamp. See
|
|
234
|
+
* `Intl.supportedValuesOf('timeZone')` for a list of valid time zones.
|
|
235
|
+
*/
|
|
18
236
|
export declare const addMinutesToTimestamp: (timestamp: string | STimestamp, minutes: number, timeZone: string) => STimestamp;
|
|
237
|
+
/**
|
|
238
|
+
* --- Comparisons ---
|
|
239
|
+
*/
|
|
240
|
+
/**
|
|
241
|
+
* Returns true if the two timestamps represent the same date and time. Returns
|
|
242
|
+
* false otherwise.
|
|
243
|
+
*
|
|
244
|
+
* @param timestamp1 The first timestamp to compare. It can be an STimestamp or
|
|
245
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
246
|
+
* @param timestamp2 The second timestamp to compare. It can be an STimestamp or
|
|
247
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
248
|
+
*/
|
|
19
249
|
export declare const isSameTimestamp: (timestamp1: string | STimestamp, timestamp2: string | STimestamp) => boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Returns true if the first timestamp represents a date and time that happens
|
|
252
|
+
* before the second timestamp. Returns false otherwise.
|
|
253
|
+
*
|
|
254
|
+
* @param timestamp1 The first timestamp to compare. It can be an STimestamp or
|
|
255
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
256
|
+
* @param timestamp2 The second timestamp to compare. It can be an STimestamp or
|
|
257
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
258
|
+
*/
|
|
20
259
|
export declare const isBeforeTimestamp: (timestamp1: string | STimestamp, timestamp2: string | STimestamp) => boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Returns true if the first timestamp represents a date and time that happens
|
|
262
|
+
* on or before the second timestamp. Returns false otherwise.
|
|
263
|
+
*
|
|
264
|
+
* @param timestamp1 The first timestamp to compare. It can be an STimestamp or
|
|
265
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
266
|
+
* @param timestamp2 The second timestamp to compare. It can be an STimestamp or
|
|
267
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
268
|
+
*/
|
|
21
269
|
export declare const isSameTimestampOrBefore: (timestamp1: string | STimestamp, timestamp2: string | STimestamp) => boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Returns true if the first timestamp represents a date and time that happens
|
|
272
|
+
* after the second timestamp. Returns false otherwise.
|
|
273
|
+
*
|
|
274
|
+
* @param timestamp1 The first timestamp to compare. It can be an STimestamp or
|
|
275
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
276
|
+
* @param timestamp2 The second timestamp to compare. It can be an STimestamp or
|
|
277
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
278
|
+
*/
|
|
22
279
|
export declare const isAfterTimestamp: (timestamp1: string | STimestamp, timestamp2: string | STimestamp) => boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Returns true if the first timestamp represents a date and time that happens
|
|
282
|
+
* on or after the second timestamp. Returns false otherwise.
|
|
283
|
+
*
|
|
284
|
+
* @param timestamp1 The first timestamp to compare. It can be an STimestamp or
|
|
285
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
286
|
+
* @param timestamp2 The second timestamp to compare. It can be an STimestamp or
|
|
287
|
+
* a string in the YYYY-MM-DDTHH:MM format.
|
|
288
|
+
*/
|
|
23
289
|
export declare const isSameTimestampOrAfter: (timestamp1: string | STimestamp, timestamp2: string | STimestamp) => boolean;
|