@tmlmobilidade/utils 20250601.1211.21 → 20250601.1225.43
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/src/dates/dates.d.ts +20 -19
- package/dist/src/dates/dates.js +40 -40
- package/package.json +1 -1
|
@@ -35,38 +35,38 @@ declare class Dates {
|
|
|
35
35
|
constructor({ iso, js_date, operational_date, unix_timestamp }: DatesConstructor);
|
|
36
36
|
/**
|
|
37
37
|
* Creates a Dates object from a string using a specified format
|
|
38
|
-
* @param text
|
|
39
|
-
* @param format
|
|
38
|
+
* @param text The date/time string to parse
|
|
39
|
+
* @param format The format string (see Luxon tokens documentation)
|
|
40
40
|
* @returns A new Dates object parsed from the string
|
|
41
41
|
*/
|
|
42
42
|
static fromFormat(text: string, format: string, timezone?: TimezoneIdentified): Dates;
|
|
43
43
|
/**
|
|
44
44
|
* Creates a Dates object from a string in the ISO 8601 format
|
|
45
|
-
* @param isoText
|
|
45
|
+
* @param isoText The date/time string to parse
|
|
46
46
|
* @returns A new Dates object parsed from the string
|
|
47
47
|
*/
|
|
48
48
|
static fromISO(isoText: string): Dates;
|
|
49
49
|
/**
|
|
50
50
|
* Creates a Dates object from a JavaScript Date object
|
|
51
|
-
* @param date
|
|
51
|
+
* @param date The JavaScript Date object to convert
|
|
52
52
|
* @returns A new Dates object created from the Date
|
|
53
53
|
*/
|
|
54
54
|
static fromJSDate(date: Date, timezone?: TimezoneIdentified): Dates;
|
|
55
55
|
/**
|
|
56
56
|
* Creates a Dates object from Unix epoch milliseconds
|
|
57
|
-
* @param millis
|
|
57
|
+
* @param millis The number of milliseconds since Unix epoch
|
|
58
58
|
* @returns A new Dates object created from the milliseconds timestamp
|
|
59
59
|
*/
|
|
60
60
|
static fromMillis(millis: number, timezone?: TimezoneIdentified): Dates;
|
|
61
61
|
/**
|
|
62
62
|
* Creates a Dates object from an operational date string
|
|
63
|
-
* @param date
|
|
63
|
+
* @param date The operational date in 'yyyyMMdd' format
|
|
64
64
|
* @returns A new Dates object created from the operational date
|
|
65
65
|
*/
|
|
66
66
|
static fromOperationalDate(date: OperationalDate | string, timezone?: TimezoneIdentified): Dates;
|
|
67
67
|
/**
|
|
68
68
|
* Creates a Dates object from Unix epoch seconds
|
|
69
|
-
* @param seconds
|
|
69
|
+
* @param seconds The number of seconds since Unix epoch
|
|
70
70
|
* @returns A new Dates object created from the seconds timestamp
|
|
71
71
|
*/
|
|
72
72
|
static fromSeconds(seconds: number, timezone?: TimezoneIdentified): Dates;
|
|
@@ -78,7 +78,7 @@ declare class Dates {
|
|
|
78
78
|
/**
|
|
79
79
|
* Returns the time remaining until a given unix_timestamp (in ms) from now,
|
|
80
80
|
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
81
|
-
* @param unixTimestamp
|
|
81
|
+
* @param unixTimestamp The target timestamp in milliseconds
|
|
82
82
|
* @returns { minutes: number, hours: number, days: number }
|
|
83
83
|
*/
|
|
84
84
|
static timeUntil(unixTimestamp: UnixTimestamp): {
|
|
@@ -88,38 +88,39 @@ declare class Dates {
|
|
|
88
88
|
};
|
|
89
89
|
/**
|
|
90
90
|
* Returns a human-readable, localized string for the time remaining until a given unix_timestamp (in ms) from now.
|
|
91
|
-
* @param unixTimestamp
|
|
92
|
-
* @param locale
|
|
91
|
+
* @param unixTimestamp The target timestamp in milliseconds
|
|
92
|
+
* @param locale Optional locale string (e.g., 'en', 'pt')
|
|
93
93
|
* @returns A localized string like "2 days, 3 hours, 15 minutes"
|
|
94
94
|
*/
|
|
95
95
|
static timeUntilLocaleString(unixTimestamp: UnixTimestamp, locale?: 'en' | 'pt'): string;
|
|
96
96
|
/**
|
|
97
|
-
* Returns a new Dates object with the current date and time minus a duration
|
|
98
|
-
* @param duration
|
|
97
|
+
* Returns a new Dates object with the current date and time minus a duration.
|
|
98
|
+
* @param duration The duration to subtract
|
|
99
99
|
* @returns A new Dates object with the current date and time minus a duration
|
|
100
100
|
*/
|
|
101
101
|
minus(duration: DurationObjectUnits): Dates;
|
|
102
102
|
/**
|
|
103
103
|
* Returns a new Dates object with the current date and time plus a duration
|
|
104
|
-
* @param duration
|
|
104
|
+
* @param duration The duration to add
|
|
105
105
|
* @returns A new Dates object with the current date and time plus a duration
|
|
106
106
|
*/
|
|
107
107
|
plus(duration: DurationObjectUnits): Dates;
|
|
108
108
|
/**
|
|
109
|
-
* Sets the date
|
|
110
|
-
* @param
|
|
109
|
+
* Sets the date and time for the Dates object.
|
|
110
|
+
* @param dateOrTime The date or time to set, can be an object with DateObjectUnits or a string in ISO format
|
|
111
|
+
* @param timezone The timezone to set in the format of an IANA timezone
|
|
111
112
|
* @returns The Dates object
|
|
112
113
|
*/
|
|
113
114
|
set(dateOrTime: DateObjectUnits, timezone?: TimezoneIdentified): Dates;
|
|
114
115
|
/**
|
|
115
|
-
* Sets the timezone for the Dates object
|
|
116
|
-
* @param timezone
|
|
116
|
+
* Sets the timezone for the Dates object.
|
|
117
|
+
* @param timezone The timezone to set in the format of an IANA timezone
|
|
117
118
|
* @returns The Dates object
|
|
118
119
|
*/
|
|
119
120
|
setZone(timezone: TimezoneIdentified): Dates;
|
|
120
121
|
/**
|
|
121
|
-
* Returns the date as a string in the specified format
|
|
122
|
-
* @param format
|
|
122
|
+
* Returns the date as a string in the specified format.
|
|
123
|
+
* @param format The format string (see Luxon tokens documentation)
|
|
123
124
|
* @returns The date as a string in the specified format
|
|
124
125
|
*/
|
|
125
126
|
toLocaleString(format: DatesFormat, locale?: string): string;
|
package/dist/src/dates/dates.js
CHANGED
|
@@ -29,14 +29,14 @@ class Dates {
|
|
|
29
29
|
// Static methods
|
|
30
30
|
/**
|
|
31
31
|
* Creates a Dates object from a string using a specified format
|
|
32
|
-
* @param text
|
|
33
|
-
* @param format
|
|
32
|
+
* @param text The date/time string to parse
|
|
33
|
+
* @param format The format string (see Luxon tokens documentation)
|
|
34
34
|
* @returns A new Dates object parsed from the string
|
|
35
35
|
*/
|
|
36
|
-
static fromFormat(text, format, timezone) {
|
|
37
|
-
const dateTime = DateTime
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
static fromFormat(text, format, timezone = 'Europe/Lisbon') {
|
|
37
|
+
const dateTime = DateTime
|
|
38
|
+
.fromFormat(text, format)
|
|
39
|
+
.setZone(timezone);
|
|
40
40
|
return new Dates({
|
|
41
41
|
iso: dateTime.toISO(),
|
|
42
42
|
js_date: dateTime.toJSDate(),
|
|
@@ -46,7 +46,7 @@ class Dates {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Creates a Dates object from a string in the ISO 8601 format
|
|
49
|
-
* @param isoText
|
|
49
|
+
* @param isoText The date/time string to parse
|
|
50
50
|
* @returns A new Dates object parsed from the string
|
|
51
51
|
*/
|
|
52
52
|
static fromISO(isoText) {
|
|
@@ -60,13 +60,13 @@ class Dates {
|
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Creates a Dates object from a JavaScript Date object
|
|
63
|
-
* @param date
|
|
63
|
+
* @param date The JavaScript Date object to convert
|
|
64
64
|
* @returns A new Dates object created from the Date
|
|
65
65
|
*/
|
|
66
|
-
static fromJSDate(date, timezone) {
|
|
67
|
-
const dateTime = DateTime
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
static fromJSDate(date, timezone = 'Europe/Lisbon') {
|
|
67
|
+
const dateTime = DateTime
|
|
68
|
+
.fromJSDate(date)
|
|
69
|
+
.setZone(timezone);
|
|
70
70
|
return new Dates({
|
|
71
71
|
iso: dateTime.toISO(),
|
|
72
72
|
js_date: dateTime.toJSDate(),
|
|
@@ -76,13 +76,13 @@ class Dates {
|
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Creates a Dates object from Unix epoch milliseconds
|
|
79
|
-
* @param millis
|
|
79
|
+
* @param millis The number of milliseconds since Unix epoch
|
|
80
80
|
* @returns A new Dates object created from the milliseconds timestamp
|
|
81
81
|
*/
|
|
82
|
-
static fromMillis(millis, timezone) {
|
|
83
|
-
const dateTime = DateTime
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
static fromMillis(millis, timezone = 'Europe/Lisbon') {
|
|
83
|
+
const dateTime = DateTime
|
|
84
|
+
.fromMillis(millis)
|
|
85
|
+
.setZone(timezone);
|
|
86
86
|
return new Dates({
|
|
87
87
|
iso: dateTime.toISO(),
|
|
88
88
|
js_date: dateTime.toJSDate(),
|
|
@@ -92,13 +92,13 @@ class Dates {
|
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Creates a Dates object from an operational date string
|
|
95
|
-
* @param date
|
|
95
|
+
* @param date The operational date in 'yyyyMMdd' format
|
|
96
96
|
* @returns A new Dates object created from the operational date
|
|
97
97
|
*/
|
|
98
|
-
static fromOperationalDate(date, timezone) {
|
|
99
|
-
const dateTime = DateTime
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
static fromOperationalDate(date, timezone = 'Europe/Lisbon') {
|
|
99
|
+
const dateTime = DateTime
|
|
100
|
+
.fromFormat(date, OPERATIONAL_DATE_FORMAT)
|
|
101
|
+
.setZone(timezone);
|
|
102
102
|
return new Dates({
|
|
103
103
|
iso: dateTime.toISO(),
|
|
104
104
|
js_date: dateTime.toJSDate(),
|
|
@@ -108,13 +108,13 @@ class Dates {
|
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* Creates a Dates object from Unix epoch seconds
|
|
111
|
-
* @param seconds
|
|
111
|
+
* @param seconds The number of seconds since Unix epoch
|
|
112
112
|
* @returns A new Dates object created from the seconds timestamp
|
|
113
113
|
*/
|
|
114
|
-
static fromSeconds(seconds, timezone) {
|
|
115
|
-
const dateTime = DateTime
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
static fromSeconds(seconds, timezone = 'Europe/Lisbon') {
|
|
115
|
+
const dateTime = DateTime
|
|
116
|
+
.fromSeconds(seconds)
|
|
117
|
+
.setZone(timezone);
|
|
118
118
|
return new Dates({
|
|
119
119
|
iso: dateTime.toISO(),
|
|
120
120
|
js_date: dateTime.toJSDate(),
|
|
@@ -138,7 +138,7 @@ class Dates {
|
|
|
138
138
|
/**
|
|
139
139
|
* Returns the time remaining until a given unix_timestamp (in ms) from now,
|
|
140
140
|
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
141
|
-
* @param unixTimestamp
|
|
141
|
+
* @param unixTimestamp The target timestamp in milliseconds
|
|
142
142
|
* @returns { minutes: number, hours: number, days: number }
|
|
143
143
|
*/
|
|
144
144
|
static timeUntil(unixTimestamp) {
|
|
@@ -151,8 +151,8 @@ class Dates {
|
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
153
|
* Returns a human-readable, localized string for the time remaining until a given unix_timestamp (in ms) from now.
|
|
154
|
-
* @param unixTimestamp
|
|
155
|
-
* @param locale
|
|
154
|
+
* @param unixTimestamp The target timestamp in milliseconds
|
|
155
|
+
* @param locale Optional locale string (e.g., 'en', 'pt')
|
|
156
156
|
* @returns A localized string like "2 days, 3 hours, 15 minutes"
|
|
157
157
|
*/
|
|
158
158
|
static timeUntilLocaleString(unixTimestamp, locale = 'pt') {
|
|
@@ -178,8 +178,8 @@ class Dates {
|
|
|
178
178
|
return parts.join(', ');
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
|
-
* Returns a new Dates object with the current date and time minus a duration
|
|
182
|
-
* @param duration
|
|
181
|
+
* Returns a new Dates object with the current date and time minus a duration.
|
|
182
|
+
* @param duration The duration to subtract
|
|
183
183
|
* @returns A new Dates object with the current date and time minus a duration
|
|
184
184
|
*/
|
|
185
185
|
minus(duration) {
|
|
@@ -195,7 +195,7 @@ class Dates {
|
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
197
|
* Returns a new Dates object with the current date and time plus a duration
|
|
198
|
-
* @param duration
|
|
198
|
+
* @param duration The duration to add
|
|
199
199
|
* @returns A new Dates object with the current date and time plus a duration
|
|
200
200
|
*/
|
|
201
201
|
plus(duration) {
|
|
@@ -210,8 +210,9 @@ class Dates {
|
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
|
-
* Sets the date
|
|
214
|
-
* @param
|
|
213
|
+
* Sets the date and time for the Dates object.
|
|
214
|
+
* @param dateOrTime The date or time to set, can be an object with DateObjectUnits or a string in ISO format
|
|
215
|
+
* @param timezone The timezone to set in the format of an IANA timezone
|
|
215
216
|
* @returns The Dates object
|
|
216
217
|
*/
|
|
217
218
|
set(dateOrTime, timezone) {
|
|
@@ -228,15 +229,14 @@ class Dates {
|
|
|
228
229
|
});
|
|
229
230
|
}
|
|
230
231
|
/**
|
|
231
|
-
* Sets the timezone for the Dates object
|
|
232
|
-
* @param timezone
|
|
232
|
+
* Sets the timezone for the Dates object.
|
|
233
|
+
* @param timezone The timezone to set in the format of an IANA timezone
|
|
233
234
|
* @returns The Dates object
|
|
234
235
|
*/
|
|
235
236
|
setZone(timezone) {
|
|
236
237
|
if (!this.iso)
|
|
237
238
|
throw new Error('ISO date is not set.');
|
|
238
239
|
const dateTime = DateTime.fromISO(this.iso).setZone(timezone);
|
|
239
|
-
this.timezone = timezone;
|
|
240
240
|
return new Dates({
|
|
241
241
|
iso: dateTime.toISO(),
|
|
242
242
|
js_date: dateTime.toJSDate(),
|
|
@@ -245,8 +245,8 @@ class Dates {
|
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
248
|
-
* Returns the date as a string in the specified format
|
|
249
|
-
* @param format
|
|
248
|
+
* Returns the date as a string in the specified format.
|
|
249
|
+
* @param format The format string (see Luxon tokens documentation)
|
|
250
250
|
* @returns The date as a string in the specified format
|
|
251
251
|
*/
|
|
252
252
|
toLocaleString(format, locale) {
|
package/package.json
CHANGED