@tmlmobilidade/utils 20251031.1051.3 → 20251202.1817.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/README.md +239 -9
- package/dist/{src/http.js → http.js} +1 -1
- package/dist/index.d.ts +8 -17
- package/dist/index.js +8 -17
- package/dist/objects/fill-template.d.ts +7 -0
- package/dist/objects/fill-template.js +52 -0
- package/dist/{src/objects → objects}/index.d.ts +1 -0
- package/dist/{src/objects → objects}/index.js +1 -0
- package/dist/permissions.d.ts +46 -0
- package/dist/permissions.js +86 -0
- package/dist/{src/validate-query-params.js → validate-query-params.js} +1 -1
- package/package.json +21 -35
- package/dist/src/css/get-variable-value.d.ts +0 -1
- package/dist/src/css/get-variable-value.js +0 -8
- package/dist/src/css/index.d.ts +0 -1
- package/dist/src/css/index.js +0 -1
- package/dist/src/dates/dates.d.ts +0 -175
- package/dist/src/dates/dates.js +0 -385
- package/dist/src/dates/format.d.ts +0 -27
- package/dist/src/dates/format.js +0 -99
- package/dist/src/dates/index.d.ts +0 -4
- package/dist/src/dates/index.js +0 -4
- package/dist/src/dates/types.d.ts +0 -4
- package/dist/src/dates/types.js +0 -338
- package/dist/src/dates/utils.d.ts +0 -17
- package/dist/src/dates/utils.js +0 -53
- package/dist/src/files/files.d.ts +0 -64
- package/dist/src/files/files.js +0 -152
- package/dist/src/files/utils.d.ts +0 -20
- package/dist/src/files/utils.js +0 -47
- package/dist/src/geo/chunk-line.d.ts +0 -10
- package/dist/src/geo/chunk-line.js +0 -75
- package/dist/src/geo/constants.d.ts +0 -8
- package/dist/src/geo/constants.js +0 -8
- package/dist/src/geo/conversions.d.ts +0 -36
- package/dist/src/geo/conversions.js +0 -79
- package/dist/src/geo/coordinates.d.ts +0 -37
- package/dist/src/geo/coordinates.js +0 -64
- package/dist/src/geo/cut-line-at-length.d.ts +0 -10
- package/dist/src/geo/cut-line-at-length.js +0 -68
- package/dist/src/geo/geojson-collections.d.ts +0 -11
- package/dist/src/geo/geojson-collections.js +0 -29
- package/dist/src/geo/get-geofence-on-point.d.ts +0 -17
- package/dist/src/geo/get-geofence-on-point.js +0 -46
- package/dist/src/geo/index.d.ts +0 -9
- package/dist/src/geo/index.js +0 -9
- package/dist/src/geo/is-point-in-polygon.d.ts +0 -9
- package/dist/src/geo/is-point-in-polygon.js +0 -37
- package/dist/src/geo/measurements.d.ts +0 -42
- package/dist/src/geo/measurements.js +0 -71
- package/dist/src/logs/index.d.ts +0 -1
- package/dist/src/logs/index.js +0 -1
- package/dist/src/logs/logs.d.ts +0 -82
- package/dist/src/logs/logs.js +0 -145
- package/dist/src/math/coefficient-of-variation.d.ts +0 -6
- package/dist/src/math/coefficient-of-variation.js +0 -14
- package/dist/src/math/entropy.d.ts +0 -6
- package/dist/src/math/entropy.js +0 -20
- package/dist/src/math/index.d.ts +0 -3
- package/dist/src/math/index.js +0 -3
- package/dist/src/math/round-number-bias.d.ts +0 -6
- package/dist/src/math/round-number-bias.js +0 -11
- package/dist/src/navigation/index.d.ts +0 -1
- package/dist/src/navigation/index.js +0 -1
- package/dist/src/navigation/keep-url-params.d.ts +0 -8
- package/dist/src/navigation/keep-url-params.js +0 -13
- package/dist/src/nuqs/index.d.ts +0 -1
- package/dist/src/nuqs/index.js +0 -2
- package/dist/src/nuqs/parse-as-array-of-strings.d.ts +0 -1
- package/dist/src/nuqs/parse-as-array-of-strings.js +0 -43
- package/dist/src/permissions.d.ts +0 -46
- package/dist/src/permissions.js +0 -77
- package/dist/src/random/generate-random-number.d.ts +0 -8
- package/dist/src/random/generate-random-number.js +0 -14
- package/dist/src/random/generate-random-string.d.ts +0 -12
- package/dist/src/random/generate-random-string.js +0 -32
- package/dist/src/random/generate-random-token.d.ts +0 -8
- package/dist/src/random/generate-random-token.js +0 -12
- package/dist/src/random/index.d.ts +0 -3
- package/dist/src/random/index.js +0 -3
- package/dist/src/strings/index.d.ts +0 -2
- package/dist/src/strings/index.js +0 -2
- package/dist/src/strings/normalize-string.d.ts +0 -8
- package/dist/src/strings/normalize-string.js +0 -18
- package/dist/src/strings/validation.d.ts +0 -2
- package/dist/src/strings/validation.js +0 -7
- /package/dist/{src/batching → batching}/index.d.ts +0 -0
- /package/dist/{src/batching → batching}/index.js +0 -0
- /package/dist/{src/batching → batching}/perform-in-chunks.d.ts +0 -0
- /package/dist/{src/batching → batching}/perform-in-chunks.js +0 -0
- /package/dist/{src/caching → caching}/cache.d.ts +0 -0
- /package/dist/{src/caching → caching}/cache.js +0 -0
- /package/dist/{src/caching → caching}/index.d.ts +0 -0
- /package/dist/{src/caching → caching}/index.js +0 -0
- /package/dist/{src/generic → generic}/get-value-at-path.d.ts +0 -0
- /package/dist/{src/generic → generic}/get-value-at-path.js +0 -0
- /package/dist/{src/generic → generic}/index.d.ts +0 -0
- /package/dist/{src/generic → generic}/index.js +0 -0
- /package/dist/{src/generic → generic}/set-value-at-path.d.ts +0 -0
- /package/dist/{src/generic → generic}/set-value-at-path.js +0 -0
- /package/dist/{src/http.d.ts → http.d.ts} +0 -0
- /package/dist/{src/objects → objects}/compare-objects.d.ts +0 -0
- /package/dist/{src/objects → objects}/compare-objects.js +0 -0
- /package/dist/{src/objects → objects}/convert-object.d.ts +0 -0
- /package/dist/{src/objects → objects}/convert-object.js +0 -0
- /package/dist/{src/objects → objects}/flatten-object.d.ts +0 -0
- /package/dist/{src/objects → objects}/flatten-object.js +0 -0
- /package/dist/{src/objects → objects}/merge-objects.d.ts +0 -0
- /package/dist/{src/objects → objects}/merge-objects.js +0 -0
- /package/dist/{src/singleton-proxy.d.ts → singleton-proxy.d.ts} +0 -0
- /package/dist/{src/singleton-proxy.js → singleton-proxy.js} +0 -0
- /package/dist/{src/validate-query-params.d.ts → validate-query-params.d.ts} +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { type DatesFormat } from './format.js';
|
|
2
|
-
import { type TimezoneIdentified } from './types.js';
|
|
3
|
-
import { type OperationalDate, type UnixTimestamp } from '@tmlmobilidade/types';
|
|
4
|
-
import { type DateObjectUnits, type DateTimeUnit, type DurationObjectUnits } from 'luxon';
|
|
5
|
-
interface DatesConstructor {
|
|
6
|
-
iso: null | string;
|
|
7
|
-
js_date: Date;
|
|
8
|
-
operational_date: OperationalDate;
|
|
9
|
-
std_window: {
|
|
10
|
-
end: UnixTimestamp;
|
|
11
|
-
start: UnixTimestamp;
|
|
12
|
-
};
|
|
13
|
-
unix_timestamp: UnixTimestamp;
|
|
14
|
-
}
|
|
15
|
-
export declare class Dates {
|
|
16
|
-
static readonly STANDARD_WINDOW_HOURS = 10;
|
|
17
|
-
static get FORMATS(): {
|
|
18
|
-
DATE_FULL: DatesFormat;
|
|
19
|
-
DATE_FULL_WITH_YEAR: DatesFormat;
|
|
20
|
-
DATE_HUGE: DatesFormat;
|
|
21
|
-
DATE_MEDIUM: DatesFormat;
|
|
22
|
-
DATE_SHORT: DatesFormat;
|
|
23
|
-
DATETIME_FULL: DatesFormat;
|
|
24
|
-
DATETIME_FULL_WITH_SECONDS: DatesFormat;
|
|
25
|
-
DATETIME_MEDIUM: DatesFormat;
|
|
26
|
-
DATETIME_MEDIUM_WITH_SECONDS: DatesFormat;
|
|
27
|
-
DATETIME_SHORT: DatesFormat;
|
|
28
|
-
DATETIME_SHORT_WITH_SECONDS: DatesFormat;
|
|
29
|
-
OPERATIONAL_DATE_FORMAT: string;
|
|
30
|
-
TIME_SIMPLE: DatesFormat;
|
|
31
|
-
TIME_WITH_SECONDS: DatesFormat;
|
|
32
|
-
};
|
|
33
|
-
static get TIMEZONE_LIST(): readonly ["Africa/Abidjan", "Africa/Accra", "Africa/Algiers", "Africa/Bissau", "Africa/Cairo", "Africa/Casablanca", "Africa/Ceuta", "Africa/El_Aaiun", "Africa/Johannesburg", "Africa/Juba", "Africa/Khartoum", "Africa/Lagos", "Africa/Maputo", "Africa/Monrovia", "Africa/Nairobi", "Africa/Ndjamena", "Africa/Sao_Tome", "Africa/Tripoli", "Africa/Tunis", "Africa/Windhoek", "America/Adak", "America/Anchorage", "America/Araguaina", "America/Argentina/Buenos_Aires", "America/Argentina/Catamarca", "America/Argentina/Cordoba", "America/Argentina/Jujuy", "America/Argentina/La_Rioja", "America/Argentina/Mendoza", "America/Argentina/Rio_Gallegos", "America/Argentina/Salta", "America/Argentina/San_Juan", "America/Argentina/San_Luis", "America/Argentina/Tucuman", "America/Argentina/Ushuaia", "America/Asuncion", "America/Atikokan", "America/Bahia_Banderas", "America/Bahia", "America/Barbados", "America/Belem", "America/Belize", "America/Blanc-Sablon", "America/Boa_Vista", "America/Bogota", "America/Boise", "America/Cambridge_Bay", "America/Campo_Grande", "America/Cancun", "America/Caracas", "America/Cayenne", "America/Chicago", "America/Chihuahua", "America/Costa_Rica", "America/Creston", "America/Cuiaba", "America/Curacao", "America/Danmarkshavn", "America/Dawson_Creek", "America/Dawson", "America/Denver", "America/Detroit", "America/Edmonton", "America/Eirunepe", "America/El_Salvador", "America/Fort_Nelson", "America/Fortaleza", "America/Glace_Bay", "America/Goose_Bay", "America/Grand_Turk", "America/Guatemala", "America/Guayaquil", "America/Guyana", "America/Halifax", "America/Havana", "America/Hermosillo", "America/Indiana", "America/Inuvik", "America/Iqaluit", "America/Jamaica", "America/Juneau", "America/Kentucky", "America/La_Paz", "America/Lima", "America/Los_Angeles", "America/Maceio", "America/Managua", "America/Manaus", "America/Martinique", "America/Matamoros", "America/Mazatlan", "America/Menominee", "America/Merida", "America/Metlakatla", "America/Mexico_City", "America/Miquelon", "America/Moncton", "America/Monterrey", "America/Montevideo", "America/Nassau", "America/New_York", "America/Nipigon", "America/Nome", "America/Noronha", "America/North_Dakota", "America/Nuuk", "America/Ojinaga", "America/Panama", "America/Pangnirtung", "America/Paramaribo", "America/Phoenix", "America/Port_of_Spain", "America/Port-au-Prince", "America/Porto_Velho", "America/Puerto_Rico", "America/Punta_Arenas", "America/Rainy_River", "America/Rankin_Inlet", "America/Recife", "America/Regina", "America/Resolute", "America/Rio_Branco", "America/Santarem", "America/Santiago", "America/Santo_Domingo", "America/Sao_Paulo", "America/Scoresbysund", "America/Sitka", "America/St_Johns", "America/Swift_Current", "America/Tegucigalpa", "America/Thule", "America/Thunder_Bay", "America/Tijuana", "America/Toronto", "America/Vancouver", "America/Whitehorse", "America/Winnipeg", "America/Yakutat", "America/Yellowknife", "Antarctica/Casey", "Antarctica/Davis", "Antarctica/DumontDUrville", "Antarctica/Macquarie", "Antarctica/Mawson", "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/Syowa", "Antarctica/Troll", "Antarctica/Vostok", "Asia/Almaty", "Asia/Amman", "Asia/Anadyr", "Asia/Aqtau", "Asia/Aqtobe", "Asia/Ashgabat", "Asia/Atyrau", "Asia/Baghdad", "Asia/Baku", "Asia/Bangkok", "Asia/Barnaul", "Asia/Beirut", "Asia/Bishkek", "Asia/Brunei", "Asia/Chita", "Asia/Choibalsan", "Asia/Colombo", "Asia/Damascus", "Asia/Dhaka", "Asia/Dili", "Asia/Dubai", "Asia/Dushanbe", "Asia/Famagusta", "Asia/Gaza", "Asia/Hebron", "Asia/Ho_Chi_Minh", "Asia/Hong_Kong", "Asia/Hovd", "Asia/Irkutsk", "Asia/Jakarta", "Asia/Jayapura", "Asia/Jerusalem", "Asia/Kabul", "Asia/Kamchatka", "Asia/Karachi", "Asia/Kathmandu", "Asia/Khandyga", "Asia/Kolkata", "Asia/Krasnoyarsk", "Asia/Kuala_Lumpur", "Asia/Kuching", "Asia/Macau", "Asia/Magadan", "Asia/Makassar", "Asia/Manila", "Asia/Nicosia", "Asia/Novokuznetsk", "Asia/Novosibirsk", "Asia/Omsk", "Asia/Pontianak", "Asia/Pyongyang", "Asia/Qatar", "Asia/Qostanay", "Asia/Qyzylorda", "Asia/Riyadh", "Asia/Sakhalin", "Asia/Samarkand", "Asia/Seoul", "Asia/Shanghai", "Asia/Singapore", "Asia/Srednekolymsk", "Asia/Taipei", "Asia/Tashkent", "Asia/Tbilisi", "Asia/Tehran", "Asia/Thimphu", "Asia/Tokyo", "Asia/Tomsk", "Asia/Ulaanbaatar", "Asia/Urumqi", "Asia/Ust-Nera", "Asia/Vladivostok", "Asia/Yakutsk", "Asia/Yangon", "Asia/Yekaterinburg", "Asia/Yerevan", "Atlantic/Azores", "Atlantic/Bermuda", "Atlantic/Canary", "Atlantic/Cape_Verde", "Atlantic/Faroe", "Atlantic/Madeira", "Atlantic/Reykjavik", "Atlantic/South_Georgia", "Atlantic/Stanley", "Australia/Adelaide", "Australia/Brisbane", "Australia/Broken_Hill", "Australia/Darwin", "Australia/Eucla", "Australia/Hobart", "Australia/Lindeman", "Australia/Lord_Howe", "Australia/Melbourne", "Australia/Perth", "Australia/Sydney", "Europe/Amsterdam", "Europe/Andorra", "Europe/Astrakhan", "Europe/Athens", "Europe/Belgrade", "Europe/Berlin", "Europe/Brussels", "Europe/Bucharest", "Europe/Budapest", "Europe/Chisinau", "Europe/Copenhagen", "Europe/Dublin", "Europe/Gibraltar", "Europe/Helsinki", "Europe/Istanbul", "Europe/Kaliningrad", "Europe/Kiev", "Europe/Kirov", "Europe/Lisbon", "Europe/London", "Europe/Luxembourg", "Europe/Madrid", "Europe/Malta", "Europe/Minsk", "Europe/Monaco", "Europe/Moscow", "Europe/Paris", "Europe/Prague", "Europe/Riga", "Europe/Rome", "Europe/Samara", "Europe/Saratov", "Europe/Simferopol", "Europe/Sofia", "Europe/Stockholm", "Europe/Tallinn", "Europe/Tirane", "Europe/Ulyanovsk", "Europe/Uzhgorod", "Europe/Vienna", "Europe/Vilnius", "Europe/Volgograd", "Europe/Warsaw", "Europe/Zaporozhye", "Europe/Zurich", "Indian/Chagos", "Indian/Christmas", "Indian/Cocos", "Indian/Kerguelen", "Indian/Mahe", "Indian/Maldives", "Indian/Mauritius", "Indian/Reunion", "Pacific/Apia", "Pacific/Auckland", "Pacific/Bougainville", "Pacific/Chatham", "Pacific/Chuuk", "Pacific/Easter", "Pacific/Efate", "Pacific/Enderbury", "Pacific/Fakaofo", "Pacific/Fiji", "Pacific/Funafuti", "Pacific/Galapagos", "Pacific/Gambier", "Pacific/Guadalcanal", "Pacific/Guam", "Pacific/Honolulu", "Pacific/Kiritimati", "Pacific/Kosrae", "Pacific/Kwajalein", "Pacific/Majuro", "Pacific/Marquesas", "Pacific/Nauru", "Pacific/Niue", "Pacific/Norfolk", "Pacific/Noumea", "Pacific/Pago_Pago", "Pacific/Palau", "Pacific/Pitcairn", "Pacific/Pohnpei", "Pacific/Port_Moresby", "Pacific/Rarotonga", "Pacific/Tarawa", "Pacific/Tongatapu", "Pacific/Wake", "Pacific/Wallis"];
|
|
34
|
-
static get TIMEZONE_LIST_VALUES(): import("zod").Values<["Africa/Abidjan", "Africa/Accra", "Africa/Algiers", "Africa/Bissau", "Africa/Cairo", "Africa/Casablanca", "Africa/Ceuta", "Africa/El_Aaiun", "Africa/Johannesburg", "Africa/Juba", "Africa/Khartoum", "Africa/Lagos", "Africa/Maputo", "Africa/Monrovia", "Africa/Nairobi", "Africa/Ndjamena", "Africa/Sao_Tome", "Africa/Tripoli", "Africa/Tunis", "Africa/Windhoek", "America/Adak", "America/Anchorage", "America/Araguaina", "America/Argentina/Buenos_Aires", "America/Argentina/Catamarca", "America/Argentina/Cordoba", "America/Argentina/Jujuy", "America/Argentina/La_Rioja", "America/Argentina/Mendoza", "America/Argentina/Rio_Gallegos", "America/Argentina/Salta", "America/Argentina/San_Juan", "America/Argentina/San_Luis", "America/Argentina/Tucuman", "America/Argentina/Ushuaia", "America/Asuncion", "America/Atikokan", "America/Bahia_Banderas", "America/Bahia", "America/Barbados", "America/Belem", "America/Belize", "America/Blanc-Sablon", "America/Boa_Vista", "America/Bogota", "America/Boise", "America/Cambridge_Bay", "America/Campo_Grande", "America/Cancun", "America/Caracas", "America/Cayenne", "America/Chicago", "America/Chihuahua", "America/Costa_Rica", "America/Creston", "America/Cuiaba", "America/Curacao", "America/Danmarkshavn", "America/Dawson_Creek", "America/Dawson", "America/Denver", "America/Detroit", "America/Edmonton", "America/Eirunepe", "America/El_Salvador", "America/Fort_Nelson", "America/Fortaleza", "America/Glace_Bay", "America/Goose_Bay", "America/Grand_Turk", "America/Guatemala", "America/Guayaquil", "America/Guyana", "America/Halifax", "America/Havana", "America/Hermosillo", "America/Indiana", "America/Inuvik", "America/Iqaluit", "America/Jamaica", "America/Juneau", "America/Kentucky", "America/La_Paz", "America/Lima", "America/Los_Angeles", "America/Maceio", "America/Managua", "America/Manaus", "America/Martinique", "America/Matamoros", "America/Mazatlan", "America/Menominee", "America/Merida", "America/Metlakatla", "America/Mexico_City", "America/Miquelon", "America/Moncton", "America/Monterrey", "America/Montevideo", "America/Nassau", "America/New_York", "America/Nipigon", "America/Nome", "America/Noronha", "America/North_Dakota", "America/Nuuk", "America/Ojinaga", "America/Panama", "America/Pangnirtung", "America/Paramaribo", "America/Phoenix", "America/Port_of_Spain", "America/Port-au-Prince", "America/Porto_Velho", "America/Puerto_Rico", "America/Punta_Arenas", "America/Rainy_River", "America/Rankin_Inlet", "America/Recife", "America/Regina", "America/Resolute", "America/Rio_Branco", "America/Santarem", "America/Santiago", "America/Santo_Domingo", "America/Sao_Paulo", "America/Scoresbysund", "America/Sitka", "America/St_Johns", "America/Swift_Current", "America/Tegucigalpa", "America/Thule", "America/Thunder_Bay", "America/Tijuana", "America/Toronto", "America/Vancouver", "America/Whitehorse", "America/Winnipeg", "America/Yakutat", "America/Yellowknife", "Antarctica/Casey", "Antarctica/Davis", "Antarctica/DumontDUrville", "Antarctica/Macquarie", "Antarctica/Mawson", "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/Syowa", "Antarctica/Troll", "Antarctica/Vostok", "Asia/Almaty", "Asia/Amman", "Asia/Anadyr", "Asia/Aqtau", "Asia/Aqtobe", "Asia/Ashgabat", "Asia/Atyrau", "Asia/Baghdad", "Asia/Baku", "Asia/Bangkok", "Asia/Barnaul", "Asia/Beirut", "Asia/Bishkek", "Asia/Brunei", "Asia/Chita", "Asia/Choibalsan", "Asia/Colombo", "Asia/Damascus", "Asia/Dhaka", "Asia/Dili", "Asia/Dubai", "Asia/Dushanbe", "Asia/Famagusta", "Asia/Gaza", "Asia/Hebron", "Asia/Ho_Chi_Minh", "Asia/Hong_Kong", "Asia/Hovd", "Asia/Irkutsk", "Asia/Jakarta", "Asia/Jayapura", "Asia/Jerusalem", "Asia/Kabul", "Asia/Kamchatka", "Asia/Karachi", "Asia/Kathmandu", "Asia/Khandyga", "Asia/Kolkata", "Asia/Krasnoyarsk", "Asia/Kuala_Lumpur", "Asia/Kuching", "Asia/Macau", "Asia/Magadan", "Asia/Makassar", "Asia/Manila", "Asia/Nicosia", "Asia/Novokuznetsk", "Asia/Novosibirsk", "Asia/Omsk", "Asia/Pontianak", "Asia/Pyongyang", "Asia/Qatar", "Asia/Qostanay", "Asia/Qyzylorda", "Asia/Riyadh", "Asia/Sakhalin", "Asia/Samarkand", "Asia/Seoul", "Asia/Shanghai", "Asia/Singapore", "Asia/Srednekolymsk", "Asia/Taipei", "Asia/Tashkent", "Asia/Tbilisi", "Asia/Tehran", "Asia/Thimphu", "Asia/Tokyo", "Asia/Tomsk", "Asia/Ulaanbaatar", "Asia/Urumqi", "Asia/Ust-Nera", "Asia/Vladivostok", "Asia/Yakutsk", "Asia/Yangon", "Asia/Yekaterinburg", "Asia/Yerevan", "Atlantic/Azores", "Atlantic/Bermuda", "Atlantic/Canary", "Atlantic/Cape_Verde", "Atlantic/Faroe", "Atlantic/Madeira", "Atlantic/Reykjavik", "Atlantic/South_Georgia", "Atlantic/Stanley", "Australia/Adelaide", "Australia/Brisbane", "Australia/Broken_Hill", "Australia/Darwin", "Australia/Eucla", "Australia/Hobart", "Australia/Lindeman", "Australia/Lord_Howe", "Australia/Melbourne", "Australia/Perth", "Australia/Sydney", "Europe/Amsterdam", "Europe/Andorra", "Europe/Astrakhan", "Europe/Athens", "Europe/Belgrade", "Europe/Berlin", "Europe/Brussels", "Europe/Bucharest", "Europe/Budapest", "Europe/Chisinau", "Europe/Copenhagen", "Europe/Dublin", "Europe/Gibraltar", "Europe/Helsinki", "Europe/Istanbul", "Europe/Kaliningrad", "Europe/Kiev", "Europe/Kirov", "Europe/Lisbon", "Europe/London", "Europe/Luxembourg", "Europe/Madrid", "Europe/Malta", "Europe/Minsk", "Europe/Monaco", "Europe/Moscow", "Europe/Paris", "Europe/Prague", "Europe/Riga", "Europe/Rome", "Europe/Samara", "Europe/Saratov", "Europe/Simferopol", "Europe/Sofia", "Europe/Stockholm", "Europe/Tallinn", "Europe/Tirane", "Europe/Ulyanovsk", "Europe/Uzhgorod", "Europe/Vienna", "Europe/Vilnius", "Europe/Volgograd", "Europe/Warsaw", "Europe/Zaporozhye", "Europe/Zurich", "Indian/Chagos", "Indian/Christmas", "Indian/Cocos", "Indian/Kerguelen", "Indian/Mahe", "Indian/Maldives", "Indian/Mauritius", "Indian/Reunion", "Pacific/Apia", "Pacific/Auckland", "Pacific/Bougainville", "Pacific/Chatham", "Pacific/Chuuk", "Pacific/Easter", "Pacific/Efate", "Pacific/Enderbury", "Pacific/Fakaofo", "Pacific/Fiji", "Pacific/Funafuti", "Pacific/Galapagos", "Pacific/Gambier", "Pacific/Guadalcanal", "Pacific/Guam", "Pacific/Honolulu", "Pacific/Kiritimati", "Pacific/Kosrae", "Pacific/Kwajalein", "Pacific/Majuro", "Pacific/Marquesas", "Pacific/Nauru", "Pacific/Niue", "Pacific/Norfolk", "Pacific/Noumea", "Pacific/Pago_Pago", "Pacific/Palau", "Pacific/Pitcairn", "Pacific/Pohnpei", "Pacific/Port_Moresby", "Pacific/Rarotonga", "Pacific/Tarawa", "Pacific/Tongatapu", "Pacific/Wake", "Pacific/Wallis"]>;
|
|
35
|
-
iso: null | string;
|
|
36
|
-
js_date: Date;
|
|
37
|
-
operational_date: OperationalDate;
|
|
38
|
-
std_window: {
|
|
39
|
-
end: UnixTimestamp;
|
|
40
|
-
start: UnixTimestamp;
|
|
41
|
-
};
|
|
42
|
-
unix_timestamp: UnixTimestamp;
|
|
43
|
-
constructor({ iso, js_date, operational_date, std_window, unix_timestamp }: DatesConstructor);
|
|
44
|
-
/**
|
|
45
|
-
* Creates a Dates object from a date/time string in a specific format.
|
|
46
|
-
* @param text The date/time string to parse.
|
|
47
|
-
* @param format The format string to use for parsing the date/time.
|
|
48
|
-
* See Luxon documentation for format tokens: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
|
|
49
|
-
* @param timezone The timezone to set for the Dates object.
|
|
50
|
-
* @returns A new Dates object parsed from the string.
|
|
51
|
-
*/
|
|
52
|
-
static fromFormat(text: string, format: string, timezone: 'local' | 'utc' | TimezoneIdentified): Dates;
|
|
53
|
-
/**
|
|
54
|
-
* Creates a Dates object from an ISO 8601 date/time string.
|
|
55
|
-
* This method assumes the string has a timezone offset.
|
|
56
|
-
* @param isoText The ISO 8601 date/time string to parse.
|
|
57
|
-
* @returns A new Dates object created from the ISO string.
|
|
58
|
-
*/
|
|
59
|
-
static fromISO(isoText: string): Dates;
|
|
60
|
-
/**
|
|
61
|
-
* Creates a Dates object from a JavaScript Date object.
|
|
62
|
-
* @param date The JavaScript Date object to convert. It is assumed that the date is in UTC.
|
|
63
|
-
* @returns A new Dates object created from the JavaScript Date.
|
|
64
|
-
*/
|
|
65
|
-
static fromJSDate(date: Date): Dates;
|
|
66
|
-
/**
|
|
67
|
-
* Creates a Dates object from an operational date string in 'yyyyMMdd' format.
|
|
68
|
-
* @param date The operational date string in 'yyyyMMdd' format or an OperationalDate object.
|
|
69
|
-
* @param timezone The timezone to set for the Dates object.
|
|
70
|
-
* @returns A new Dates object created from the operational date.
|
|
71
|
-
*/
|
|
72
|
-
static fromOperationalDate(date: OperationalDate | string, timezone: 'local' | 'utc' | TimezoneIdentified): Dates;
|
|
73
|
-
/**
|
|
74
|
-
* Creates a Dates object from Unix epoch seconds
|
|
75
|
-
* @param seconds The number of seconds since Unix epoch
|
|
76
|
-
* @returns A new Dates object created from the seconds timestamp
|
|
77
|
-
*/
|
|
78
|
-
static fromSeconds(seconds: number): Dates;
|
|
79
|
-
/**
|
|
80
|
-
* Creates a Dates object from Unix epoch in milliseconds.
|
|
81
|
-
* @param millis The number of milliseconds since Unix epoch. Unix timestamp is always in UTC.
|
|
82
|
-
* @returns A new Dates object created from the milliseconds timestamp.
|
|
83
|
-
*/
|
|
84
|
-
static fromUnixTimestamp(millis: number | UnixTimestamp): Dates;
|
|
85
|
-
/**
|
|
86
|
-
* Creates a Dates object with the current date and time.
|
|
87
|
-
* @param timezone The timezone to set for the Dates object.
|
|
88
|
-
* @returns A new Dates object with the current date and time in the specified timezone.
|
|
89
|
-
*/
|
|
90
|
-
static now(timezone: 'local' | 'utc' | TimezoneIdentified): Dates;
|
|
91
|
-
/**
|
|
92
|
-
* Returns a new Dates object with the end of the specified unit.
|
|
93
|
-
* @param unit The unit to set the end of, e.g., 'day', 'month', 'year', etc.
|
|
94
|
-
* @returns A new Dates object with the end of the specified unit.
|
|
95
|
-
*/
|
|
96
|
-
endOf(unit: DateTimeUnit): Dates;
|
|
97
|
-
/**
|
|
98
|
-
* Returns a new Dates object with the current date and time minus a duration.
|
|
99
|
-
* @param duration The duration to subtract
|
|
100
|
-
* @returns A new Dates object with the current date and time minus a duration
|
|
101
|
-
*/
|
|
102
|
-
minus(duration: DurationObjectUnits): Dates;
|
|
103
|
-
/**
|
|
104
|
-
* Returns a new Dates object with the current date and time plus a duration
|
|
105
|
-
* @param duration The duration to add
|
|
106
|
-
* @returns A new Dates object with the current date and time plus a duration
|
|
107
|
-
*/
|
|
108
|
-
plus(duration: DurationObjectUnits): Dates;
|
|
109
|
-
/**
|
|
110
|
-
* Sets the date and time for the Dates object.
|
|
111
|
-
* @param dateOrTime The date or time to set, can be an object with DateObjectUnits or a string in ISO format.
|
|
112
|
-
* @returns The Dates object
|
|
113
|
-
*/
|
|
114
|
-
set(dateOrTime: DateObjectUnits): Dates;
|
|
115
|
-
/**
|
|
116
|
-
* Sets the timezone for the Dates object.
|
|
117
|
-
* @param timezone The timezone to set in the format of an IANA timezone.
|
|
118
|
-
* @param method The method to use for updating the timezone information.
|
|
119
|
-
* - `offset_only` Updates only offset setting to the new timezone. The ISO string will show adjusted time components (hour, minutes, etc.) to their equivalent in the new timezone. The UTC value in milliseconds stays the same. The timestamp is the source of truth.
|
|
120
|
-
* - `rebase_utc` Keeps the individual time components (hour, minutes, etc.) and updates the internal UTC value in milliseconds to reflect the change. The ISO string will show the same time components as before, but the UTC value in milliseconds will be adjusted to match the new timezone. The ISO string is the source of truth.
|
|
121
|
-
* @returns The Dates object
|
|
122
|
-
*/
|
|
123
|
-
setZone(timezone: TimezoneIdentified, method: 'offset_only' | 'rebase_utc'): Dates;
|
|
124
|
-
/**
|
|
125
|
-
* Returns a new Dates object with the start of the specified unit.
|
|
126
|
-
* @param unit The unit to set the start of, e.g., 'day', 'month', 'year', etc.
|
|
127
|
-
* @returns A new Dates object with the start of the specified unit.
|
|
128
|
-
*/
|
|
129
|
-
startOf(unit: DateTimeUnit): Dates;
|
|
130
|
-
/**
|
|
131
|
-
* Returns the time remaining until a given unix_timestamp (in ms) from now,
|
|
132
|
-
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
133
|
-
* @param unixTimestamp The target timestamp in milliseconds
|
|
134
|
-
* @returns { minutes: number, hours: number, days: number }
|
|
135
|
-
*/
|
|
136
|
-
timeUntil(unixTimestamp: UnixTimestamp): {
|
|
137
|
-
days: number;
|
|
138
|
-
hours: number;
|
|
139
|
-
minutes: number;
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Returns a human-readable, localized string for the time remaining until a given unix_timestamp (in ms) from now.
|
|
143
|
-
* @param unixTimestamp The target timestamp in milliseconds
|
|
144
|
-
* @param locale Optional locale string (e.g., 'en', 'pt')
|
|
145
|
-
* @returns A localized string like "2 days, 3 hours, 15 minutes"
|
|
146
|
-
*/
|
|
147
|
-
timeUntilLocaleString(unixTimestamp: UnixTimestamp, locale?: 'en' | 'pt'): string;
|
|
148
|
-
/**
|
|
149
|
-
* Returns the date as a string in the specified format.
|
|
150
|
-
* @param format The format string (see Luxon tokens documentation)
|
|
151
|
-
* @returns The date as a string in the specified format
|
|
152
|
-
*/
|
|
153
|
-
toFormat(format: string): string;
|
|
154
|
-
/**
|
|
155
|
-
* Returns the date as a string in the specified format.
|
|
156
|
-
* @param format The format string (see Luxon tokens documentation)
|
|
157
|
-
* @returns The date as a string in the specified format
|
|
158
|
-
*/
|
|
159
|
-
toLocaleString(format: DatesFormat, locale?: string): string;
|
|
160
|
-
/**
|
|
161
|
-
* Returns the operational date based on the provided timestamp and format.
|
|
162
|
-
* @param timestamp - The timestamp to be parsed.
|
|
163
|
-
* @returns The operational date in the yyyyLLdd format.
|
|
164
|
-
*/
|
|
165
|
-
private getOperationalDate;
|
|
166
|
-
/**
|
|
167
|
-
* This function returns the start and end of the standard window interval for a given timestamp.
|
|
168
|
-
* The standard window interval is the period in which is possible to receive data for a given ride.
|
|
169
|
-
* Currently, the standard window starts 10 hours before and ends 10 hours after the scheduled ride start.
|
|
170
|
-
* @param isoDate The ISO date string to calculate the standard window interval.
|
|
171
|
-
* @returns An object containing the start and end of the standard window interval.
|
|
172
|
-
*/
|
|
173
|
-
private getStandardWindowInterval;
|
|
174
|
-
}
|
|
175
|
-
export {};
|
package/dist/src/dates/dates.js
DELETED
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
import { Formats, OPERATIONAL_DATE_FORMAT } from './format.js';
|
|
3
|
-
import { timezoneList, timezoneListSchema } from './types.js';
|
|
4
|
-
import { DateTime } from 'luxon';
|
|
5
|
-
/* * */
|
|
6
|
-
export class Dates {
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// Static properties
|
|
10
|
-
static STANDARD_WINDOW_HOURS = 10;
|
|
11
|
-
static get FORMATS() { return Formats; }
|
|
12
|
-
static get TIMEZONE_LIST() { return timezoneList; }
|
|
13
|
-
static get TIMEZONE_LIST_VALUES() { return timezoneListSchema.Values; }
|
|
14
|
-
//
|
|
15
|
-
// Instance properties
|
|
16
|
-
iso;
|
|
17
|
-
js_date;
|
|
18
|
-
operational_date;
|
|
19
|
-
std_window;
|
|
20
|
-
unix_timestamp;
|
|
21
|
-
//
|
|
22
|
-
// Constructor
|
|
23
|
-
constructor({ iso, js_date, operational_date, std_window, unix_timestamp }) {
|
|
24
|
-
this.iso = iso ?? null;
|
|
25
|
-
this.js_date = js_date;
|
|
26
|
-
this.operational_date = operational_date;
|
|
27
|
-
this.std_window = std_window;
|
|
28
|
-
this.unix_timestamp = unix_timestamp;
|
|
29
|
-
}
|
|
30
|
-
//
|
|
31
|
-
// Static methods
|
|
32
|
-
/**
|
|
33
|
-
* Creates a Dates object from a date/time string in a specific format.
|
|
34
|
-
* @param text The date/time string to parse.
|
|
35
|
-
* @param format The format string to use for parsing the date/time.
|
|
36
|
-
* See Luxon documentation for format tokens: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
|
|
37
|
-
* @param timezone The timezone to set for the Dates object.
|
|
38
|
-
* @returns A new Dates object parsed from the string.
|
|
39
|
-
*/
|
|
40
|
-
static fromFormat(text, format, timezone) {
|
|
41
|
-
const dateTime = DateTime
|
|
42
|
-
.fromFormat(text, format, { setZone: true })
|
|
43
|
-
.setZone(timezone, { keepLocalTime: true });
|
|
44
|
-
return new Dates({
|
|
45
|
-
iso: dateTime.toISO(),
|
|
46
|
-
js_date: dateTime.toJSDate(),
|
|
47
|
-
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
48
|
-
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
49
|
-
unix_timestamp: dateTime.toMillis(),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a Dates object from an ISO 8601 date/time string.
|
|
54
|
-
* This method assumes the string has a timezone offset.
|
|
55
|
-
* @param isoText The ISO 8601 date/time string to parse.
|
|
56
|
-
* @returns A new Dates object created from the ISO string.
|
|
57
|
-
*/
|
|
58
|
-
static fromISO(isoText) {
|
|
59
|
-
const dateTime = DateTime.fromISO(isoText, { setZone: true });
|
|
60
|
-
return new Dates({
|
|
61
|
-
iso: dateTime.toISO(),
|
|
62
|
-
js_date: dateTime.toJSDate(),
|
|
63
|
-
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
64
|
-
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
65
|
-
unix_timestamp: dateTime.toMillis(),
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Creates a Dates object from a JavaScript Date object.
|
|
70
|
-
* @param date The JavaScript Date object to convert. It is assumed that the date is in UTC.
|
|
71
|
-
* @returns A new Dates object created from the JavaScript Date.
|
|
72
|
-
*/
|
|
73
|
-
static fromJSDate(date) {
|
|
74
|
-
const dateTime = DateTime
|
|
75
|
-
.fromJSDate(date)
|
|
76
|
-
.setZone('utc', { keepLocalTime: false });
|
|
77
|
-
return new Dates({
|
|
78
|
-
iso: dateTime.toISO(),
|
|
79
|
-
js_date: dateTime.toJSDate(),
|
|
80
|
-
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
81
|
-
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
82
|
-
unix_timestamp: dateTime.toMillis(),
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Creates a Dates object from an operational date string in 'yyyyMMdd' format.
|
|
87
|
-
* @param date The operational date string in 'yyyyMMdd' format or an OperationalDate object.
|
|
88
|
-
* @param timezone The timezone to set for the Dates object.
|
|
89
|
-
* @returns A new Dates object created from the operational date.
|
|
90
|
-
*/
|
|
91
|
-
static fromOperationalDate(date, timezone) {
|
|
92
|
-
const dateTime = DateTime
|
|
93
|
-
.fromFormat(date, OPERATIONAL_DATE_FORMAT)
|
|
94
|
-
.setZone(timezone, { keepLocalTime: true })
|
|
95
|
-
.set({ hour: 4, millisecond: 0, minute: 0, second: 0 }); // Start of the operational date
|
|
96
|
-
return new Dates({
|
|
97
|
-
iso: dateTime.toISO(),
|
|
98
|
-
js_date: dateTime.toJSDate(),
|
|
99
|
-
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
100
|
-
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
101
|
-
unix_timestamp: dateTime.toMillis(),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Creates a Dates object from Unix epoch seconds
|
|
106
|
-
* @param seconds The number of seconds since Unix epoch
|
|
107
|
-
* @returns A new Dates object created from the seconds timestamp
|
|
108
|
-
*/
|
|
109
|
-
static fromSeconds(seconds) {
|
|
110
|
-
const dateTime = DateTime
|
|
111
|
-
.fromSeconds(seconds)
|
|
112
|
-
.setZone('utc', { keepLocalTime: false });
|
|
113
|
-
return new Dates({
|
|
114
|
-
iso: dateTime.toISO(),
|
|
115
|
-
js_date: dateTime.toJSDate(),
|
|
116
|
-
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
117
|
-
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
118
|
-
unix_timestamp: dateTime.toMillis(),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Creates a Dates object from Unix epoch in milliseconds.
|
|
123
|
-
* @param millis The number of milliseconds since Unix epoch. Unix timestamp is always in UTC.
|
|
124
|
-
* @returns A new Dates object created from the milliseconds timestamp.
|
|
125
|
-
*/
|
|
126
|
-
static fromUnixTimestamp(millis) {
|
|
127
|
-
const dateTime = DateTime
|
|
128
|
-
.fromMillis(millis)
|
|
129
|
-
.setZone('utc', { keepLocalTime: false });
|
|
130
|
-
return new Dates({
|
|
131
|
-
iso: dateTime.toISO(),
|
|
132
|
-
js_date: dateTime.toJSDate(),
|
|
133
|
-
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
134
|
-
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
135
|
-
unix_timestamp: dateTime.toMillis(),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Creates a Dates object with the current date and time.
|
|
140
|
-
* @param timezone The timezone to set for the Dates object.
|
|
141
|
-
* @returns A new Dates object with the current date and time in the specified timezone.
|
|
142
|
-
*/
|
|
143
|
-
static now(timezone) {
|
|
144
|
-
const dateTime = DateTime
|
|
145
|
-
.now()
|
|
146
|
-
.setZone(timezone, { keepLocalTime: false });
|
|
147
|
-
return new Dates({
|
|
148
|
-
iso: dateTime.toISO(),
|
|
149
|
-
js_date: dateTime.toJSDate(),
|
|
150
|
-
operational_date: this.prototype.getOperationalDate(dateTime.toISO()),
|
|
151
|
-
std_window: this.prototype.getStandardWindowInterval(dateTime.toISO()),
|
|
152
|
-
unix_timestamp: dateTime.toMillis(),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Returns a new Dates object with the end of the specified unit.
|
|
157
|
-
* @param unit The unit to set the end of, e.g., 'day', 'month', 'year', etc.
|
|
158
|
-
* @returns A new Dates object with the end of the specified unit.
|
|
159
|
-
*/
|
|
160
|
-
endOf(unit) {
|
|
161
|
-
if (!this.iso)
|
|
162
|
-
throw new Error('ISO date is not set.');
|
|
163
|
-
const dateTime = DateTime
|
|
164
|
-
.fromISO(this.iso, { setZone: true })
|
|
165
|
-
.endOf(unit);
|
|
166
|
-
return new Dates({
|
|
167
|
-
iso: dateTime.toISO(),
|
|
168
|
-
js_date: dateTime.toJSDate(),
|
|
169
|
-
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
170
|
-
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
171
|
-
unix_timestamp: dateTime.toMillis(),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Returns a new Dates object with the current date and time minus a duration.
|
|
176
|
-
* @param duration The duration to subtract
|
|
177
|
-
* @returns A new Dates object with the current date and time minus a duration
|
|
178
|
-
*/
|
|
179
|
-
minus(duration) {
|
|
180
|
-
if (!this.iso)
|
|
181
|
-
throw new Error('ISO date is not set.');
|
|
182
|
-
const dateTime = DateTime
|
|
183
|
-
.fromISO(this.iso, { setZone: true })
|
|
184
|
-
.minus(duration);
|
|
185
|
-
return new Dates({
|
|
186
|
-
iso: dateTime.toISO(),
|
|
187
|
-
js_date: dateTime.toJSDate(),
|
|
188
|
-
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
189
|
-
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
190
|
-
unix_timestamp: dateTime.toMillis(),
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Returns a new Dates object with the current date and time plus a duration
|
|
195
|
-
* @param duration The duration to add
|
|
196
|
-
* @returns A new Dates object with the current date and time plus a duration
|
|
197
|
-
*/
|
|
198
|
-
plus(duration) {
|
|
199
|
-
if (!this.iso)
|
|
200
|
-
throw new Error('ISO date is not set.');
|
|
201
|
-
const dateTime = DateTime
|
|
202
|
-
.fromISO(this.iso, { setZone: true })
|
|
203
|
-
.plus(duration);
|
|
204
|
-
return new Dates({
|
|
205
|
-
iso: dateTime.toISO(),
|
|
206
|
-
js_date: dateTime.toJSDate(),
|
|
207
|
-
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
208
|
-
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
209
|
-
unix_timestamp: dateTime.toMillis(),
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
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
|
-
* @returns The Dates object
|
|
216
|
-
*/
|
|
217
|
-
set(dateOrTime) {
|
|
218
|
-
if (!this.iso)
|
|
219
|
-
throw new Error('ISO date is not set.');
|
|
220
|
-
const dateTime = DateTime
|
|
221
|
-
.fromISO(this.iso, { setZone: true })
|
|
222
|
-
.set(dateOrTime);
|
|
223
|
-
return new Dates({
|
|
224
|
-
iso: dateTime.toISO(),
|
|
225
|
-
js_date: dateTime.toJSDate(),
|
|
226
|
-
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
227
|
-
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
228
|
-
unix_timestamp: dateTime.toMillis(),
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Sets the timezone for the Dates object.
|
|
233
|
-
* @param timezone The timezone to set in the format of an IANA timezone.
|
|
234
|
-
* @param method The method to use for updating the timezone information.
|
|
235
|
-
* - `offset_only` Updates only offset setting to the new timezone. The ISO string will show adjusted time components (hour, minutes, etc.) to their equivalent in the new timezone. The UTC value in milliseconds stays the same. The timestamp is the source of truth.
|
|
236
|
-
* - `rebase_utc` Keeps the individual time components (hour, minutes, etc.) and updates the internal UTC value in milliseconds to reflect the change. The ISO string will show the same time components as before, but the UTC value in milliseconds will be adjusted to match the new timezone. The ISO string is the source of truth.
|
|
237
|
-
* @returns The Dates object
|
|
238
|
-
*/
|
|
239
|
-
setZone(timezone, method) {
|
|
240
|
-
if (!this.iso)
|
|
241
|
-
throw new Error('ISO date is not set.');
|
|
242
|
-
const dateTime = DateTime
|
|
243
|
-
.fromISO(this.iso, { setZone: true })
|
|
244
|
-
.setZone(timezone, { keepLocalTime: method === 'rebase_utc' });
|
|
245
|
-
return new Dates({
|
|
246
|
-
iso: dateTime.toISO(),
|
|
247
|
-
js_date: dateTime.toJSDate(),
|
|
248
|
-
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
249
|
-
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
250
|
-
unix_timestamp: dateTime.toMillis(),
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Returns a new Dates object with the start of the specified unit.
|
|
255
|
-
* @param unit The unit to set the start of, e.g., 'day', 'month', 'year', etc.
|
|
256
|
-
* @returns A new Dates object with the start of the specified unit.
|
|
257
|
-
*/
|
|
258
|
-
startOf(unit) {
|
|
259
|
-
if (!this.iso)
|
|
260
|
-
throw new Error('ISO date is not set.');
|
|
261
|
-
const dateTime = DateTime
|
|
262
|
-
.fromISO(this.iso, { setZone: true })
|
|
263
|
-
.startOf(unit);
|
|
264
|
-
return new Dates({
|
|
265
|
-
iso: dateTime.toISO(),
|
|
266
|
-
js_date: dateTime.toJSDate(),
|
|
267
|
-
operational_date: this.getOperationalDate(dateTime.toISO()),
|
|
268
|
-
std_window: this.getStandardWindowInterval(dateTime.toISO()),
|
|
269
|
-
unix_timestamp: dateTime.toMillis(),
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Returns the time remaining until a given unix_timestamp (in ms) from now,
|
|
274
|
-
* as an object with minutes, hours, and days (all as floats, not rounded).
|
|
275
|
-
* @param unixTimestamp The target timestamp in milliseconds
|
|
276
|
-
* @returns { minutes: number, hours: number, days: number }
|
|
277
|
-
*/
|
|
278
|
-
timeUntil(unixTimestamp) {
|
|
279
|
-
const now = Date.now();
|
|
280
|
-
const diffMs = unixTimestamp - now;
|
|
281
|
-
const minutes = diffMs / (1000 * 60);
|
|
282
|
-
const hours = diffMs / (1000 * 60 * 60);
|
|
283
|
-
const days = diffMs / (1000 * 60 * 60 * 24);
|
|
284
|
-
return { days, hours, minutes };
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Returns a human-readable, localized string for the time remaining until a given unix_timestamp (in ms) from now.
|
|
288
|
-
* @param unixTimestamp The target timestamp in milliseconds
|
|
289
|
-
* @param locale Optional locale string (e.g., 'en', 'pt')
|
|
290
|
-
* @returns A localized string like "2 days, 3 hours, 15 minutes"
|
|
291
|
-
*/
|
|
292
|
-
timeUntilLocaleString(unixTimestamp, locale = 'pt') {
|
|
293
|
-
const now = Date.now();
|
|
294
|
-
const diffMs = unixTimestamp - now;
|
|
295
|
-
const parts = [];
|
|
296
|
-
if (diffMs < 60 * 1000) {
|
|
297
|
-
return locale === 'en' ? 'Arriving' : 'A Chegar';
|
|
298
|
-
}
|
|
299
|
-
const totalMinutes = Math.round(diffMs / (1000 * 60));
|
|
300
|
-
const days = Math.floor(totalMinutes / (60 * 24));
|
|
301
|
-
const hours = Math.floor((totalMinutes % (60 * 24)) / 60);
|
|
302
|
-
const minutes = totalMinutes % 60;
|
|
303
|
-
if (days > 0) {
|
|
304
|
-
parts.push(`${days} ${days === 1 ? locale === 'en' ? 'day' : 'dia' : locale === 'en' ? 'days' : 'dias'}`);
|
|
305
|
-
}
|
|
306
|
-
if (hours > 0) {
|
|
307
|
-
parts.push(`${hours} ${hours === 1 ? locale === 'en' ? 'hour' : 'hora' : locale === 'en' ? 'hours' : 'horas'}`);
|
|
308
|
-
}
|
|
309
|
-
if (minutes > 0 || parts.length === 0) {
|
|
310
|
-
parts.push(`${minutes} ${minutes === 1 ? locale === 'en' ? 'minute' : 'minuto' : locale === 'en' ? 'minutes' : 'minutos'}`);
|
|
311
|
-
}
|
|
312
|
-
return parts.join(', ');
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Returns the date as a string in the specified format.
|
|
316
|
-
* @param format The format string (see Luxon tokens documentation)
|
|
317
|
-
* @returns The date as a string in the specified format
|
|
318
|
-
*/
|
|
319
|
-
toFormat(format) {
|
|
320
|
-
if (!this.iso)
|
|
321
|
-
throw new Error('ISO date is not set.');
|
|
322
|
-
const dateTime = DateTime.fromISO(this.iso, { setZone: true });
|
|
323
|
-
return dateTime.toFormat(format);
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Returns the date as a string in the specified format.
|
|
327
|
-
* @param format The format string (see Luxon tokens documentation)
|
|
328
|
-
* @returns The date as a string in the specified format
|
|
329
|
-
*/
|
|
330
|
-
toLocaleString(format, locale) {
|
|
331
|
-
if (!this.iso)
|
|
332
|
-
throw new Error('ISO date is not set.');
|
|
333
|
-
const dateTime = DateTime.fromISO(this.iso, { setZone: true });
|
|
334
|
-
if (locale)
|
|
335
|
-
dateTime.setLocale(locale);
|
|
336
|
-
return dateTime.toLocaleString(format, { locale: locale });
|
|
337
|
-
}
|
|
338
|
-
//
|
|
339
|
-
// Private methods
|
|
340
|
-
/**
|
|
341
|
-
* Returns the operational date based on the provided timestamp and format.
|
|
342
|
-
* @param timestamp - The timestamp to be parsed.
|
|
343
|
-
* @returns The operational date in the yyyyLLdd format.
|
|
344
|
-
*/
|
|
345
|
-
getOperationalDate(isoDate) {
|
|
346
|
-
if (!isoDate)
|
|
347
|
-
throw new Error('ISO date is not set.');
|
|
348
|
-
//
|
|
349
|
-
// Get the date object
|
|
350
|
-
const dateObject = DateTime.fromISO(isoDate, { setZone: true });
|
|
351
|
-
//
|
|
352
|
-
// Check if the time is between 00:00 and 03:59.
|
|
353
|
-
// The operational date is between 04:00 and 03:59 of the following day.
|
|
354
|
-
let operational_date;
|
|
355
|
-
if (dateObject.hour < 4) {
|
|
356
|
-
// If true, return the previous day in the yyyyLLdd format
|
|
357
|
-
const previousDay = dateObject.minus({ days: 1 });
|
|
358
|
-
operational_date = previousDay.toFormat(OPERATIONAL_DATE_FORMAT);
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
// Else, return the current day in the yyyyLLdd format
|
|
362
|
-
operational_date = dateObject.toFormat(OPERATIONAL_DATE_FORMAT);
|
|
363
|
-
}
|
|
364
|
-
//
|
|
365
|
-
// Validate the operational date and return it
|
|
366
|
-
return operational_date;
|
|
367
|
-
//
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* This function returns the start and end of the standard window interval for a given timestamp.
|
|
371
|
-
* The standard window interval is the period in which is possible to receive data for a given ride.
|
|
372
|
-
* Currently, the standard window starts 10 hours before and ends 10 hours after the scheduled ride start.
|
|
373
|
-
* @param isoDate The ISO date string to calculate the standard window interval.
|
|
374
|
-
* @returns An object containing the start and end of the standard window interval.
|
|
375
|
-
*/
|
|
376
|
-
getStandardWindowInterval(isoDate) {
|
|
377
|
-
if (!isoDate)
|
|
378
|
-
throw new Error('ISO date is not set.');
|
|
379
|
-
const dateTime = DateTime.fromISO(isoDate, { setZone: true });
|
|
380
|
-
return {
|
|
381
|
-
end: dateTime.plus({ hours: Dates.STANDARD_WINDOW_HOURS }).toMillis(),
|
|
382
|
-
start: dateTime.minus({ hours: Dates.STANDARD_WINDOW_HOURS }).toMillis(),
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export interface DatesFormat {
|
|
2
|
-
day?: '2-digit' | 'numeric';
|
|
3
|
-
hour?: '2-digit' | 'numeric';
|
|
4
|
-
minute?: '2-digit' | 'numeric';
|
|
5
|
-
month?: '2-digit' | 'long' | 'numeric' | 'short';
|
|
6
|
-
second?: '2-digit' | 'numeric';
|
|
7
|
-
timeZoneName?: 'long' | 'short';
|
|
8
|
-
weekday?: 'long' | 'narrow' | 'short';
|
|
9
|
-
year?: '2-digit' | 'numeric';
|
|
10
|
-
}
|
|
11
|
-
export declare const OPERATIONAL_DATE_FORMAT = "yyyyMMdd";
|
|
12
|
-
export declare const Formats: {
|
|
13
|
-
DATE_FULL: DatesFormat;
|
|
14
|
-
DATE_FULL_WITH_YEAR: DatesFormat;
|
|
15
|
-
DATE_HUGE: DatesFormat;
|
|
16
|
-
DATE_MEDIUM: DatesFormat;
|
|
17
|
-
DATE_SHORT: DatesFormat;
|
|
18
|
-
DATETIME_FULL: DatesFormat;
|
|
19
|
-
DATETIME_FULL_WITH_SECONDS: DatesFormat;
|
|
20
|
-
DATETIME_MEDIUM: DatesFormat;
|
|
21
|
-
DATETIME_MEDIUM_WITH_SECONDS: DatesFormat;
|
|
22
|
-
DATETIME_SHORT: DatesFormat;
|
|
23
|
-
DATETIME_SHORT_WITH_SECONDS: DatesFormat;
|
|
24
|
-
OPERATIONAL_DATE_FORMAT: string;
|
|
25
|
-
TIME_SIMPLE: DatesFormat;
|
|
26
|
-
TIME_WITH_SECONDS: DatesFormat;
|
|
27
|
-
};
|