@mediafly/js-ui 51.6.0-10 → 51.6.0-12
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/lib/src/components/date-time-zone-city-picker/date-time-zone-city-picker.d.ts +7 -3
- package/lib/src/components/date-time-zone-city-picker/date-time-zone-city-picker.js +31 -38
- package/lib/src/components/date-time-zone-city-picker/date-time-zone-city-picker.js.map +1 -1
- package/lib/src/components/date-time-zone-city-picker/time-zone-city-picker.js +0 -2
- package/lib/src/components/date-time-zone-city-picker/time-zone-city-picker.js.map +1 -1
- package/lib/src/components/date-time-zone-city-picker/time-zone-city.service.d.ts +15 -0
- package/lib/src/components/date-time-zone-city-picker/time-zone-city.service.js +107 -9
- package/lib/src/components/date-time-zone-city-picker/time-zone-city.service.js.map +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +5 -5
- package/package.json +1 -1
- package/src/components/date-time-zone-city-picker/date-time-zone-city-picker.ts +32 -38
- package/src/components/date-time-zone-city-picker/time-zone-city-picker.ts +0 -2
- package/src/components/date-time-zone-city-picker/time-zone-city.service.ts +125 -9
|
@@ -5,22 +5,26 @@ export interface DateTimeZoneCity {
|
|
|
5
5
|
timeZoneName: string | null;
|
|
6
6
|
}
|
|
7
7
|
export default class DateTimeZoneCityPickerController implements IComponentController {
|
|
8
|
+
value?: DateTimeZoneCity;
|
|
8
9
|
format: string;
|
|
9
10
|
inputId: string;
|
|
10
|
-
isDisabled
|
|
11
|
+
isDisabled?: boolean;
|
|
11
12
|
isRequired: boolean;
|
|
12
13
|
onOpen: () => void;
|
|
13
14
|
onChange: (param: {
|
|
14
15
|
newValue: DateTimeZoneCity;
|
|
15
16
|
}) => void;
|
|
16
|
-
protected ngModelCtrl: ng.INgModelController;
|
|
17
17
|
protected dateLuxon: DateTime | null;
|
|
18
18
|
protected timeLuxon: DateTime | null;
|
|
19
19
|
protected timeZoneName: string | null;
|
|
20
20
|
$onInit(): void;
|
|
21
|
-
|
|
21
|
+
$onChanges(changes: {
|
|
22
|
+
value: ng.IChangesObject<DateTimeZoneCity>;
|
|
23
|
+
}): void;
|
|
24
|
+
private initFromValue;
|
|
22
25
|
protected updateDate(dateLuxon: DateTime): void;
|
|
23
26
|
protected updateTime(timeLuxon: DateTime): void;
|
|
24
27
|
protected updateTimeZone(timeZoneName: string): void;
|
|
25
28
|
private updateModel;
|
|
29
|
+
private datesMatch;
|
|
26
30
|
}
|
|
@@ -14,33 +14,14 @@ const luxon_1 = require("luxon");
|
|
|
14
14
|
const time_zone_city_service_1 = require("./time-zone-city.service");
|
|
15
15
|
let DateTimeZoneCityPickerController = class DateTimeZoneCityPickerController {
|
|
16
16
|
$onInit() {
|
|
17
|
-
|
|
18
|
-
this.ngModelCtrl.$formatters.push((modelValue) => {
|
|
19
|
-
var _a;
|
|
20
|
-
if (modelValue) {
|
|
21
|
-
this.initModelFromAPI(modelValue);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
this.dateLuxon = null;
|
|
25
|
-
this.timeLuxon = luxon_1.DateTime.fromObject({
|
|
26
|
-
hour: 0,
|
|
27
|
-
minute: 0,
|
|
28
|
-
second: 0,
|
|
29
|
-
millisecond: 0
|
|
30
|
-
});
|
|
31
|
-
this.timeZoneName = null;
|
|
32
|
-
}
|
|
33
|
-
(_a = this.onChange) === null || _a === void 0 ? void 0 : _a.call(this, { newValue: modelValue });
|
|
34
|
-
return modelValue;
|
|
35
|
-
});
|
|
36
|
-
this.ngModelCtrl.$parsers.push((modelValue) => {
|
|
37
|
-
var _a;
|
|
38
|
-
(_a = this.onChange) === null || _a === void 0 ? void 0 : _a.call(this, { newValue: modelValue });
|
|
39
|
-
return modelValue;
|
|
40
|
-
});
|
|
17
|
+
this.initFromValue(this.value);
|
|
41
18
|
}
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
$onChanges(changes) {
|
|
20
|
+
if (changes.value) {
|
|
21
|
+
this.initFromValue(changes.value.currentValue);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
initFromValue(value) {
|
|
44
25
|
let luxon;
|
|
45
26
|
if (!(value === null || value === void 0 ? void 0 : value.dateTime)) {
|
|
46
27
|
luxon = undefined;
|
|
@@ -79,26 +60,25 @@ let DateTimeZoneCityPickerController = class DateTimeZoneCityPickerController {
|
|
|
79
60
|
millisecond: 0
|
|
80
61
|
});
|
|
81
62
|
}
|
|
82
|
-
const bestMatchTimeZone = time_zone_city_service_1.getTimeZone(value.timeZoneName);
|
|
63
|
+
const bestMatchTimeZone = time_zone_city_service_1.getTimeZone(value === null || value === void 0 ? void 0 : value.timeZoneName);
|
|
83
64
|
this.timeZoneName = (bestMatchTimeZone === null || bestMatchTimeZone === void 0 ? void 0 : bestMatchTimeZone.timeZoneName) || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
84
|
-
console.log(`-----> and so: ${this.dateLuxon} and ${this.timeLuxon} and ${this.timeZoneName}`);
|
|
85
65
|
}
|
|
86
66
|
updateDate(dateLuxon) {
|
|
87
|
-
console.log(`-----> updateDate: ${dateLuxon} (time is ${this.timeLuxon})`);
|
|
88
67
|
this.dateLuxon = dateLuxon;
|
|
89
68
|
this.updateModel();
|
|
90
69
|
}
|
|
91
70
|
updateTime(timeLuxon) {
|
|
92
|
-
console.log(`-----> updateTime: ${timeLuxon}`);
|
|
93
71
|
this.timeLuxon = timeLuxon;
|
|
94
72
|
this.updateModel();
|
|
95
73
|
}
|
|
96
74
|
updateTimeZone(timeZoneName) {
|
|
97
|
-
console.log(`-----> updateTimeZone: ${timeZoneName}`);
|
|
98
75
|
this.timeZoneName = timeZoneName;
|
|
99
76
|
this.updateModel();
|
|
100
77
|
}
|
|
101
78
|
updateModel() {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
const oldDateTime = (_a = this.value) === null || _a === void 0 ? void 0 : _a.dateTime;
|
|
81
|
+
const oldTimeZoneName = (_b = this.value) === null || _b === void 0 ? void 0 : _b.timeZoneName;
|
|
102
82
|
let dateTime;
|
|
103
83
|
if (this.dateLuxon && this.timeLuxon) {
|
|
104
84
|
const targetZone = this.timeZoneName || 'utc';
|
|
@@ -114,12 +94,28 @@ let DateTimeZoneCityPickerController = class DateTimeZoneCityPickerController {
|
|
|
114
94
|
zone: targetZone
|
|
115
95
|
});
|
|
116
96
|
}
|
|
117
|
-
this.
|
|
118
|
-
dateTime,
|
|
97
|
+
this.value = {
|
|
98
|
+
dateTime: dateTime || null,
|
|
119
99
|
timeZoneName: this.timeZoneName
|
|
120
|
-
}
|
|
100
|
+
};
|
|
101
|
+
if (!this.datesMatch(oldDateTime, dateTime) || oldTimeZoneName !== this.timeZoneName) {
|
|
102
|
+
(_c = this.onChange) === null || _c === void 0 ? void 0 : _c.call(this, { newValue: this.value });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
datesMatch(dateTime1, dateTime2) {
|
|
106
|
+
if (dateTime1 instanceof luxon_1.DateTime && dateTime2 instanceof luxon_1.DateTime) {
|
|
107
|
+
return dateTime1.toISO() === dateTime2.toISO();
|
|
108
|
+
}
|
|
109
|
+
else if (dateTime1 instanceof Date && dateTime2 instanceof Date) {
|
|
110
|
+
return dateTime1.toISOString() === dateTime2.toISOString();
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
121
113
|
}
|
|
122
114
|
};
|
|
115
|
+
__decorate([
|
|
116
|
+
decorators_1.Input(),
|
|
117
|
+
__metadata("design:type", Object)
|
|
118
|
+
], DateTimeZoneCityPickerController.prototype, "value", void 0);
|
|
123
119
|
__decorate([
|
|
124
120
|
decorators_1.Input('@'),
|
|
125
121
|
__metadata("design:type", String)
|
|
@@ -129,7 +125,7 @@ __decorate([
|
|
|
129
125
|
__metadata("design:type", String)
|
|
130
126
|
], DateTimeZoneCityPickerController.prototype, "inputId", void 0);
|
|
131
127
|
__decorate([
|
|
132
|
-
decorators_1.Input(
|
|
128
|
+
decorators_1.Input(),
|
|
133
129
|
__metadata("design:type", Boolean)
|
|
134
130
|
], DateTimeZoneCityPickerController.prototype, "isDisabled", void 0);
|
|
135
131
|
__decorate([
|
|
@@ -148,9 +144,6 @@ DateTimeZoneCityPickerController = __decorate([
|
|
|
148
144
|
decorators_1.Component({
|
|
149
145
|
selector: 'mflyDateTimeZoneCityPicker',
|
|
150
146
|
template: require('./date-time-zone-city-picker.html'),
|
|
151
|
-
require: {
|
|
152
|
-
ngModelCtrl: 'ngModel'
|
|
153
|
-
}
|
|
154
147
|
})
|
|
155
148
|
], DateTimeZoneCityPickerController);
|
|
156
149
|
exports.default = DateTimeZoneCityPickerController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-time-zone-city-picker.js","sourceRoot":"","sources":["../../../../src/components/date-time-zone-city-picker/date-time-zone-city-picker.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,8CAAwD;AACxD,iCAAgC;AAChC,qEAAsD;
|
|
1
|
+
{"version":3,"file":"date-time-zone-city-picker.js","sourceRoot":"","sources":["../../../../src/components/date-time-zone-city-picker/date-time-zone-city-picker.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,8CAAwD;AACxD,iCAAgC;AAChC,qEAAsD;AAWtD,IAAqB,gCAAgC,GAArD,MAAqB,gCAAgC;IAcpD,OAAO;QAEN,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAED,UAAU,CAAC,OAAuD;QAEjE,IAAI,OAAO,CAAC,KAAK,EAAE;YAClB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;SAC9C;IACF,CAAC;IAEO,aAAa,CAAC,KAAmC;QAExD,IAAI,KAA2B,CAAA;QAC/B,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAA,EAAE;YACrB,KAAK,GAAG,SAAS,CAAA;SACjB;aAAM,IAAI,KAAK,CAAC,QAAQ,YAAY,gBAAQ,EAAE;YAC9C,KAAK,GAAG,KAAK,CAAC,QAA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it: ${this.timeZoneName} (${typeof this.timeZoneName})`);
|
|
20
19
|
this.timeZones = time_zone_city_service_1.getTimeZones();
|
|
21
20
|
this.setTimeZone(this.timeZoneName);
|
|
22
21
|
}
|
|
@@ -31,7 +30,6 @@ let TimeZoneCityPickerController = class TimeZoneCityPickerController {
|
|
|
31
30
|
}
|
|
32
31
|
setTimeZone(timeZoneName) {
|
|
33
32
|
var _a, _b, _c;
|
|
34
|
-
console.log(`-----> setTimeZone: ${timeZoneName}`);
|
|
35
33
|
const oldTimeZone = this.timeZone;
|
|
36
34
|
this.timeZone = (_c = (_b = (_a = time_zone_city_service_1.getTimeZone(timeZoneName)) !== null && _a !== void 0 ? _a : time_zone_city_service_1.getTimeZone(Intl.DateTimeFormat().resolvedOptions().timeZone)) !== null && _b !== void 0 ? _b : time_zone_city_service_1.getTimeZone('America/Chicago')) !== null && _c !== void 0 ? _c : this.timeZones[0];
|
|
37
35
|
if (oldTimeZone !== this.timeZone) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-zone-city-picker.js","sourceRoot":"","sources":["../../../../src/components/date-time-zone-city-picker/time-zone-city-picker.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,4DAAsE;AACtE,qEAA8E;AAM9E,IAAqB,4BAA4B,GAAjD,MAAqB,4BAA4B;IAAjD;QAOW,cAAS,GAAe,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"time-zone-city-picker.js","sourceRoot":"","sources":["../../../../src/components/date-time-zone-city-picker/time-zone-city-picker.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,4DAAsE;AACtE,qEAA8E;AAM9E,IAAqB,4BAA4B,GAAjD,MAAqB,4BAA4B;IAAjD;QAOW,cAAS,GAAe,EAAE,CAAA;IAgCrC,CAAC;IA9BA,OAAO;QAEN,IAAI,CAAC,SAAS,GAAG,qCAAY,EAAE,CAAA;QAC/B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACpC,CAA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/** e.g. 'Chicago, Reynosa, Winnipeg' */
|
|
3
7
|
cityNames: string;
|
|
4
8
|
/** A signature of the Daylight Saving Time rules for the time zone. */
|
|
5
9
|
dstSignature: string;
|
|
10
|
+
/** The population of the most populous city in the time zone. */
|
|
11
|
+
leadCityPopulation: number;
|
|
12
|
+
/** Whether the time zone observes Daylight Saving Time. */
|
|
13
|
+
observesDST: boolean;
|
|
6
14
|
/** e.g. '-06:00' */
|
|
7
15
|
offset: string;
|
|
8
16
|
/** e.g. -360 */
|
|
@@ -18,6 +26,13 @@ export interface TimeZone {
|
|
|
18
26
|
* You don't need to call this. It's only for testing.
|
|
19
27
|
*/
|
|
20
28
|
export declare function clearTimeZoneCache(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Given a date that includes a time offset, find a matching IANA time zone name.
|
|
31
|
+
* More of our users are in places that observe DST, so we bias towards choosing those: Chicago rather than Mexico City; London rather than Lagos.
|
|
32
|
+
* Where there are still multiple matches, we choose the most populous city.
|
|
33
|
+
* @param dateTime - e.g. '2025-01-01T00:00:00.000-06:00'
|
|
34
|
+
*/
|
|
35
|
+
export declare function getBestGuessTimeZoneCity(dateTimeISO: string): string | undefined;
|
|
21
36
|
/**
|
|
22
37
|
* Finds the time zone that matches the time zone and DST signature of the given time zone name.
|
|
23
38
|
* @param timeZoneName - e.g. 'America/Chicago'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTimeZones = exports.getTimeZone = exports.clearTimeZoneCache = void 0;
|
|
3
|
+
exports.getTimeZones = exports.getTimeZone = exports.getBestGuessTimeZoneCity = exports.clearTimeZoneCache = void 0;
|
|
4
4
|
const tzdb_1 = require("@vvo/tzdb");
|
|
5
5
|
const cityPopulation_1 = require("./cityPopulation");
|
|
6
|
+
const thisYear = new Date().getFullYear();
|
|
6
7
|
let cachedTimeZones = null;
|
|
7
8
|
/**
|
|
8
9
|
* You don't need to call this. It's only for testing.
|
|
@@ -11,6 +12,87 @@ function clearTimeZoneCache() {
|
|
|
11
12
|
cachedTimeZones = null;
|
|
12
13
|
}
|
|
13
14
|
exports.clearTimeZoneCache = clearTimeZoneCache;
|
|
15
|
+
/**
|
|
16
|
+
* Given a date that includes a time offset, find a matching IANA time zone name.
|
|
17
|
+
* More of our users are in places that observe DST, so we bias towards choosing those: Chicago rather than Mexico City; London rather than Lagos.
|
|
18
|
+
* Where there are still multiple matches, we choose the most populous city.
|
|
19
|
+
* @param dateTime - e.g. '2025-01-01T00:00:00.000-06:00'
|
|
20
|
+
*/
|
|
21
|
+
function getBestGuessTimeZoneCity(dateTimeISO) {
|
|
22
|
+
var _a;
|
|
23
|
+
if (!dateTimeISO) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const date = new Date(dateTimeISO);
|
|
27
|
+
if (isNaN(date.getTime())) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
let offsetMinutes;
|
|
31
|
+
const z = /Z$/i.test(dateTimeISO);
|
|
32
|
+
if (z) {
|
|
33
|
+
offsetMinutes = 0;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const offsetMatch = dateTimeISO.match(/([+-])(\d{2}):?(\d{2})$/);
|
|
37
|
+
if (!offsetMatch) {
|
|
38
|
+
offsetMinutes = 0;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
offsetMinutes = parseInt(offsetMatch[2], 10) * 60 + parseInt(offsetMatch[3], 10);
|
|
42
|
+
if (offsetMatch[1] === '-') {
|
|
43
|
+
offsetMinutes = -offsetMinutes;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Find all time zones that match the given date.
|
|
48
|
+
const candidates = [];
|
|
49
|
+
for (const timeZone of getTimeZones()) {
|
|
50
|
+
// For each time zone, format the given datetime to its time zone and see if the offset matches.
|
|
51
|
+
// This takes DST into account, as defined for that instant at that location.
|
|
52
|
+
const dtf = new Intl.DateTimeFormat('en', {
|
|
53
|
+
timeZone: timeZone.timeZoneName,
|
|
54
|
+
timeZoneName: 'shortOffset',
|
|
55
|
+
hour: '2-digit', // forces a time - needed for timeZoneName to appear in parts
|
|
56
|
+
});
|
|
57
|
+
const parts = dtf.formatToParts(new Date(dateTimeISO));
|
|
58
|
+
const tzName = (_a = parts.find(p => p.type === 'timeZoneName')) === null || _a === void 0 ? void 0 : _a.value;
|
|
59
|
+
if (!tzName) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
let tzOffsetMinutes = 0;
|
|
63
|
+
if (tzName !== 'UTC' && tzName !== 'GMT') {
|
|
64
|
+
const m = tzName.match(/^GMT([+-])(\d{1,2})(?::?(\d{2}))?$/);
|
|
65
|
+
if (!m) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const h = parseInt(m[2], 10);
|
|
69
|
+
const min = m[3] ? parseInt(m[3], 10) : 0;
|
|
70
|
+
tzOffsetMinutes = h * 60 + min;
|
|
71
|
+
if (m[1] === '-') {
|
|
72
|
+
tzOffsetMinutes = -tzOffsetMinutes;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (tzOffsetMinutes === offsetMinutes) {
|
|
76
|
+
candidates.push(timeZone);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (candidates.length === 0) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
// More of our users are in places that observe DST, so we should prefer those. Choose Chicago over Mexico City; London over Lagos.
|
|
83
|
+
// Otherwise, choose the most populous city.
|
|
84
|
+
candidates.sort((a, b) => {
|
|
85
|
+
if (a.observesDST && !b.observesDST) {
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
if (!a.observesDST && b.observesDST) {
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
return b.leadCityPopulation - a.leadCityPopulation;
|
|
92
|
+
});
|
|
93
|
+
return candidates[0].timeZoneName;
|
|
94
|
+
}
|
|
95
|
+
exports.getBestGuessTimeZoneCity = getBestGuessTimeZoneCity;
|
|
14
96
|
/**
|
|
15
97
|
* Finds the time zone that matches the time zone and DST signature of the given time zone name.
|
|
16
98
|
* @param timeZoneName - e.g. 'America/Chicago'
|
|
@@ -28,7 +110,7 @@ function getTimeZone(timeZoneName) {
|
|
|
28
110
|
// e.g. given 'Europe/Isle_of_Man', return the time zone for 'Europe/London'.
|
|
29
111
|
const samples = getDateSamples();
|
|
30
112
|
const dstSignature = getDSTSignature(timeZoneName, samples);
|
|
31
|
-
return timeZones.find(tz => tz.dstSignature === dstSignature);
|
|
113
|
+
return timeZones.find(tz => tz.dstSignature === dstSignature.signature);
|
|
32
114
|
}
|
|
33
115
|
exports.getTimeZone = getTimeZone;
|
|
34
116
|
/**
|
|
@@ -60,13 +142,13 @@ function getTimeZones() {
|
|
|
60
142
|
const groups = new Map();
|
|
61
143
|
for (const timezone of timezonesWithDSTSignatures) {
|
|
62
144
|
const cityName = (_a = timezone.mainCities[0]) !== null && _a !== void 0 ? _a : timezone.countryName;
|
|
63
|
-
const group = groups.get(timezone.dstSignature);
|
|
145
|
+
const group = groups.get(timezone.dstSignature.signature);
|
|
64
146
|
const population = (_b = cityPopulation_1.cityPopulation.get(`${cityName}, ${timezone.countryName}`)) !== null && _b !== void 0 ? _b : 0;
|
|
65
147
|
if (!group) {
|
|
66
148
|
const offsetHour = Math.floor(Math.abs(timezone.rawOffsetInMinutes) / 60);
|
|
67
149
|
const offsetMinute = Math.abs(timezone.rawOffsetInMinutes) % 60;
|
|
68
150
|
const offset = `${timezone.rawOffsetInMinutes < 0 ? '-' : '+'}${offsetHour.toString().padStart(2, '0')}:${offsetMinute.toString().padStart(2, '0')}`;
|
|
69
|
-
groups.set(timezone.dstSignature, {
|
|
151
|
+
groups.set(timezone.dstSignature.signature, {
|
|
70
152
|
cities: [{
|
|
71
153
|
city: cityName,
|
|
72
154
|
country: timezone.countryName,
|
|
@@ -75,7 +157,8 @@ function getTimeZones() {
|
|
|
75
157
|
timeZoneAlternativeName: timezone.alternativeName,
|
|
76
158
|
timeZoneName: timezone.name,
|
|
77
159
|
}],
|
|
78
|
-
dstSignature: timezone.dstSignature,
|
|
160
|
+
dstSignature: timezone.dstSignature.signature,
|
|
161
|
+
observesDST: timezone.dstSignature.observesDST,
|
|
79
162
|
offset,
|
|
80
163
|
offsetMinutes: timezone.rawOffsetInMinutes,
|
|
81
164
|
});
|
|
@@ -102,6 +185,8 @@ function getTimeZones() {
|
|
|
102
185
|
.map(group => ({
|
|
103
186
|
cityNames: getCityList(group.cities),
|
|
104
187
|
dstSignature: group.dstSignature,
|
|
188
|
+
leadCityPopulation: group.cities[0].population,
|
|
189
|
+
observesDST: group.observesDST,
|
|
105
190
|
offset: group.offset,
|
|
106
191
|
offsetMinutes: group.offsetMinutes,
|
|
107
192
|
timeZoneAbbreviation: group.cities[0].timeZoneAbbreviation,
|
|
@@ -125,6 +210,7 @@ function getCityList(cities) {
|
|
|
125
210
|
function getDSTSignature(timezoneName, sampleTimes) {
|
|
126
211
|
var _a, _b;
|
|
127
212
|
try {
|
|
213
|
+
let observesDST = false;
|
|
128
214
|
const formatter = new Intl.DateTimeFormat('en', {
|
|
129
215
|
timeZone: timezoneName,
|
|
130
216
|
timeZoneName: 'shortOffset',
|
|
@@ -132,15 +218,27 @@ function getDSTSignature(timezoneName, sampleTimes) {
|
|
|
132
218
|
minute: '2-digit',
|
|
133
219
|
});
|
|
134
220
|
const sig = [];
|
|
221
|
+
let prevOffset;
|
|
135
222
|
for (const sample of sampleTimes) {
|
|
136
223
|
const parts = formatter.formatToParts(sample);
|
|
137
|
-
const
|
|
138
|
-
sig.push(
|
|
224
|
+
const offset = (_b = (_a = parts.find(p => p.type === 'timeZoneName')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
|
|
225
|
+
sig.push(offset);
|
|
226
|
+
// Only say "it observes DST" if it does so now or in the future. (Mexico stopped in 2022, for example.)
|
|
227
|
+
if (prevOffset && prevOffset !== offset && sample.getFullYear() >= thisYear) {
|
|
228
|
+
observesDST = true;
|
|
229
|
+
}
|
|
230
|
+
prevOffset = offset;
|
|
139
231
|
}
|
|
140
|
-
return
|
|
232
|
+
return {
|
|
233
|
+
observesDST,
|
|
234
|
+
signature: sig.join(','),
|
|
235
|
+
};
|
|
141
236
|
}
|
|
142
237
|
catch (error) {
|
|
143
|
-
return
|
|
238
|
+
return {
|
|
239
|
+
observesDST: false,
|
|
240
|
+
signature: '',
|
|
241
|
+
};
|
|
144
242
|
}
|
|
145
243
|
}
|
|
146
244
|
function getDateSamples() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-zone-city.service.js","sourceRoot":"","sources":["../../../../src/components/date-time-zone-city-picker/time-zone-city.service.ts"],"names":[],"mappings":";;;AAAA,oCAAwC;AACxC,qDAAiD;
|
|
1
|
+
{"version":3,"file":"time-zone-city.service.js","sourceRoot":"","sources":["../../../../src/components/date-time-zone-city-picker/time-zone-city.service.ts"],"names":[],"mappings":";;;AAAA,oCAAwC;AACxC,qDAAiD;AA4BjD,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;AAEzC,IAAI,eAAe,GAAsB,IAAI,CAAA;AAE7C;;GAEG;AACH,SAAgB,kBAAkB;IACjC,eAAe,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,gDAEC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,WAAmB;;IAE3D,IAAI,CAAC,WAAW,EAAE;QACjB,OAAO,SAAS,CAAA;KAChB;IAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,CAAA;IAClC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE;QAC1B,OAAO,SAAS,CAAA;KAChB;IAED,IAAI,aAAqB,CAAA;IACzB,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,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
|
474
474
|
"../src/components/date-time-zone-city-picker/time-zone-city.service.ts": {
|
|
475
|
-
"version": "
|
|
476
|
-
"signature": "
|
|
475
|
+
"version": "c3a43f8488e2092716ea874aab742fd184e393e35086d83ea88088c74ba23701",
|
|
476
|
+
"signature": "0ff01dd88863ca5ac6b74b3716b64e3cbf418dbe1366610b107fd12360a28478",
|
|
477
477
|
"affectsGlobalScope": false
|
|
478
478
|
},
|
|
479
479
|
"../src/components/date-time-zone-city-picker/date-time-zone-city-picker.ts": {
|
|
480
|
-
"version": "
|
|
481
|
-
"signature": "
|
|
480
|
+
"version": "2304b0426e41504967e7924637f16c6f783c3f6f64e7a9acec78d3f1aef9a201",
|
|
481
|
+
"signature": "5a6ac6549676b97300c9324cb292c169a54a41abb3dfcb5e865259af70443998",
|
|
482
482
|
"affectsGlobalScope": false
|
|
483
483
|
},
|
|
484
484
|
"../src/components/date-time-zone-city-picker/time-zone-city-picker.ts": {
|
|
485
|
-
"version": "
|
|
485
|
+
"version": "8ba4cd06787ed0ae0b952d629fd8c0e3147ee8ecd821e6b87728e68c6eeb71ff",
|
|
486
486
|
"signature": "6066bd236b98fe3c130fad8cd2c1644e18e3c86032785958211e875620520c32",
|
|
487
487
|
"affectsGlobalScope": false
|
|
488
488
|
},
|
package/package.json
CHANGED
|
@@ -11,54 +11,35 @@ export interface DateTimeZoneCity {
|
|
|
11
11
|
@Component({
|
|
12
12
|
selector: 'mflyDateTimeZoneCityPicker',
|
|
13
13
|
template: require('./date-time-zone-city-picker.html'),
|
|
14
|
-
require: {
|
|
15
|
-
ngModelCtrl: 'ngModel'
|
|
16
|
-
}
|
|
17
14
|
})
|
|
18
15
|
export default class DateTimeZoneCityPickerController implements IComponentController {
|
|
19
16
|
|
|
17
|
+
@Input() value?: DateTimeZoneCity
|
|
20
18
|
@Input('@') format: string
|
|
21
19
|
@Input('@') inputId: string
|
|
22
|
-
@Input(
|
|
20
|
+
@Input() isDisabled?: boolean
|
|
23
21
|
@Input('@') isRequired: boolean
|
|
24
22
|
@Output('&?') onOpen: () => void
|
|
25
23
|
@Output('&?') onChange: (param: { newValue: DateTimeZoneCity }) => void
|
|
26
24
|
|
|
27
|
-
protected ngModelCtrl: ng.INgModelController
|
|
28
|
-
|
|
29
25
|
protected dateLuxon: DateTime | null
|
|
30
26
|
protected timeLuxon: DateTime | null
|
|
31
27
|
protected timeZoneName: string | null
|
|
32
28
|
|
|
33
29
|
$onInit(): void {
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
this.ngModelCtrl.$formatters.push((modelValue: DateTimeZoneCity) => {
|
|
37
|
-
if (modelValue) {
|
|
38
|
-
this.initModelFromAPI(modelValue)
|
|
39
|
-
} else {
|
|
40
|
-
this.dateLuxon = null
|
|
41
|
-
this.timeLuxon = DateTime.fromObject({
|
|
42
|
-
hour: 0,
|
|
43
|
-
minute: 0,
|
|
44
|
-
second: 0,
|
|
45
|
-
millisecond: 0
|
|
46
|
-
})
|
|
47
|
-
this.timeZoneName = null
|
|
48
|
-
}
|
|
49
|
-
this.onChange?.({ newValue: modelValue })
|
|
50
|
-
return modelValue
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
this.ngModelCtrl.$parsers.push((modelValue: DateTimeZoneCity) => {
|
|
54
|
-
this.onChange?.({ newValue: modelValue })
|
|
55
|
-
return modelValue
|
|
56
|
-
})
|
|
31
|
+
this.initFromValue(this.value)
|
|
57
32
|
}
|
|
58
33
|
|
|
59
|
-
|
|
34
|
+
$onChanges(changes: { value: ng.IChangesObject<DateTimeZoneCity> }): void {
|
|
35
|
+
|
|
36
|
+
if (changes.value) {
|
|
37
|
+
this.initFromValue(changes.value.currentValue)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private initFromValue(value: DateTimeZoneCity | undefined): void {
|
|
60
42
|
|
|
61
|
-
console.log(`-----> initModelFromAPI: ${JSON.stringify(value)}`)
|
|
62
43
|
let luxon: DateTime | undefined
|
|
63
44
|
if (!value?.dateTime) {
|
|
64
45
|
luxon = undefined
|
|
@@ -95,34 +76,33 @@ export default class DateTimeZoneCityPickerController implements IComponentContr
|
|
|
95
76
|
})
|
|
96
77
|
}
|
|
97
78
|
|
|
98
|
-
const bestMatchTimeZone = getTimeZone(value
|
|
79
|
+
const bestMatchTimeZone = getTimeZone(value?.timeZoneName)
|
|
99
80
|
this.timeZoneName = bestMatchTimeZone?.timeZoneName || Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
100
|
-
console.log(`-----> and so: ${this.dateLuxon} and ${this.timeLuxon} and ${this.timeZoneName}`)
|
|
101
81
|
}
|
|
102
82
|
|
|
103
83
|
protected updateDate(dateLuxon: DateTime): void {
|
|
104
84
|
|
|
105
|
-
console.log(`-----> updateDate: ${dateLuxon} (time is ${this.timeLuxon})`)
|
|
106
85
|
this.dateLuxon = dateLuxon
|
|
107
86
|
this.updateModel()
|
|
108
87
|
}
|
|
109
88
|
|
|
110
89
|
protected updateTime(timeLuxon: DateTime): void {
|
|
111
90
|
|
|
112
|
-
console.log(`-----> updateTime: ${timeLuxon}`)
|
|
113
91
|
this.timeLuxon = timeLuxon
|
|
114
92
|
this.updateModel()
|
|
115
93
|
}
|
|
116
94
|
|
|
117
95
|
protected updateTimeZone(timeZoneName: string): void {
|
|
118
96
|
|
|
119
|
-
console.log(`-----> updateTimeZone: ${timeZoneName}`)
|
|
120
97
|
this.timeZoneName = timeZoneName
|
|
121
98
|
this.updateModel()
|
|
122
99
|
}
|
|
123
100
|
|
|
124
101
|
private updateModel(): void {
|
|
125
102
|
|
|
103
|
+
const oldDateTime = this.value?.dateTime
|
|
104
|
+
const oldTimeZoneName = this.value?.timeZoneName
|
|
105
|
+
|
|
126
106
|
let dateTime: DateTime | undefined
|
|
127
107
|
if (this.dateLuxon && this.timeLuxon) {
|
|
128
108
|
const targetZone = this.timeZoneName || 'utc'
|
|
@@ -139,9 +119,23 @@ export default class DateTimeZoneCityPickerController implements IComponentContr
|
|
|
139
119
|
})
|
|
140
120
|
}
|
|
141
121
|
|
|
142
|
-
this.
|
|
143
|
-
dateTime,
|
|
122
|
+
this.value = {
|
|
123
|
+
dateTime: dateTime || null,
|
|
144
124
|
timeZoneName: this.timeZoneName
|
|
145
|
-
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!this.datesMatch(oldDateTime, dateTime) || oldTimeZoneName !== this.timeZoneName) {
|
|
128
|
+
this.onChange?.({ newValue: this.value })
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private datesMatch(dateTime1: DateTime | Date | null | undefined, dateTime2: DateTime | Date | null | undefined): boolean {
|
|
133
|
+
|
|
134
|
+
if (dateTime1 instanceof DateTime && dateTime2 instanceof DateTime) {
|
|
135
|
+
return dateTime1.toISO() === dateTime2.toISO()
|
|
136
|
+
} else if (dateTime1 instanceof Date && dateTime2 instanceof Date) {
|
|
137
|
+
return dateTime1.toISOString() === dateTime2.toISOString()
|
|
138
|
+
}
|
|
139
|
+
return false
|
|
146
140
|
}
|
|
147
141
|
}
|
|
@@ -17,7 +17,6 @@ export default class TimeZoneCityPickerController implements IComponentControlle
|
|
|
17
17
|
|
|
18
18
|
$onInit(): void {
|
|
19
19
|
|
|
20
|
-
console.log(`-----> $onInit: ${this.timeZoneName} (${typeof this.timeZoneName})`)
|
|
21
20
|
this.timeZones = getTimeZones()
|
|
22
21
|
this.setTimeZone(this.timeZoneName)
|
|
23
22
|
}
|
|
@@ -37,7 +36,6 @@ export default class TimeZoneCityPickerController implements IComponentControlle
|
|
|
37
36
|
|
|
38
37
|
private setTimeZone(timeZoneName: string): void {
|
|
39
38
|
|
|
40
|
-
console.log(`-----> setTimeZone: ${timeZoneName}`)
|
|
41
39
|
const oldTimeZone = this.timeZone
|
|
42
40
|
this.timeZone = getTimeZone(timeZoneName)
|
|
43
41
|
?? getTimeZone(Intl.DateTimeFormat().resolvedOptions().timeZone)
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { rawTimeZones } from '@vvo/tzdb'
|
|
2
2
|
import { cityPopulation } from './cityPopulation'
|
|
3
3
|
|
|
4
|
+
export interface DSTSignature {
|
|
5
|
+
observesDST: boolean
|
|
6
|
+
signature: string
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export interface TimeZone {
|
|
5
10
|
/** e.g. 'Chicago, Reynosa, Winnipeg' */
|
|
6
11
|
cityNames: string
|
|
7
12
|
/** A signature of the Daylight Saving Time rules for the time zone. */
|
|
8
13
|
dstSignature: string
|
|
14
|
+
/** The population of the most populous city in the time zone. */
|
|
15
|
+
leadCityPopulation: number
|
|
16
|
+
/** Whether the time zone observes Daylight Saving Time. */
|
|
17
|
+
observesDST: boolean
|
|
9
18
|
/** e.g. '-06:00' */
|
|
10
19
|
offset: string
|
|
11
20
|
/** e.g. -360 */
|
|
@@ -18,6 +27,8 @@ export interface TimeZone {
|
|
|
18
27
|
timeZoneName: string
|
|
19
28
|
}
|
|
20
29
|
|
|
30
|
+
const thisYear = new Date().getFullYear()
|
|
31
|
+
|
|
21
32
|
let cachedTimeZones: TimeZone[] | null = null
|
|
22
33
|
|
|
23
34
|
/**
|
|
@@ -27,6 +38,94 @@ export function clearTimeZoneCache(): void {
|
|
|
27
38
|
cachedTimeZones = null
|
|
28
39
|
}
|
|
29
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Given a date that includes a time offset, find a matching IANA time zone name.
|
|
43
|
+
* More of our users are in places that observe DST, so we bias towards choosing those: Chicago rather than Mexico City; London rather than Lagos.
|
|
44
|
+
* Where there are still multiple matches, we choose the most populous city.
|
|
45
|
+
* @param dateTime - e.g. '2025-01-01T00:00:00.000-06:00'
|
|
46
|
+
*/
|
|
47
|
+
export function getBestGuessTimeZoneCity(dateTimeISO: string): string | undefined {
|
|
48
|
+
|
|
49
|
+
if (!dateTimeISO) {
|
|
50
|
+
return undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const date = new Date(dateTimeISO)
|
|
54
|
+
if (isNaN(date.getTime())) {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let offsetMinutes: number
|
|
59
|
+
const z = /Z$/i.test(dateTimeISO)
|
|
60
|
+
if (z) {
|
|
61
|
+
offsetMinutes = 0
|
|
62
|
+
} else {
|
|
63
|
+
const offsetMatch = dateTimeISO.match(/([+-])(\d{2}):?(\d{2})$/)
|
|
64
|
+
if (!offsetMatch) {
|
|
65
|
+
offsetMinutes = 0
|
|
66
|
+
} else {
|
|
67
|
+
offsetMinutes = parseInt(offsetMatch[2], 10) * 60 + parseInt(offsetMatch[3], 10)
|
|
68
|
+
if (offsetMatch[1] === '-') {
|
|
69
|
+
offsetMinutes = -offsetMinutes
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Find all time zones that match the given date.
|
|
75
|
+
const candidates: TimeZone[] = []
|
|
76
|
+
for (const timeZone of getTimeZones()) {
|
|
77
|
+
|
|
78
|
+
// For each time zone, format the given datetime to its time zone and see if the offset matches.
|
|
79
|
+
// This takes DST into account, as defined for that instant at that location.
|
|
80
|
+
const dtf = new Intl.DateTimeFormat('en', {
|
|
81
|
+
timeZone: timeZone.timeZoneName,
|
|
82
|
+
timeZoneName: 'shortOffset' as any, // TypeScript doesn't know that 'shortOffset' is safe: https://caniuse.com/?search=shortOffset
|
|
83
|
+
hour: '2-digit', // forces a time - needed for timeZoneName to appear in parts
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const parts = dtf.formatToParts(new Date(dateTimeISO))
|
|
87
|
+
const tzName = parts.find(p => p.type === 'timeZoneName')?.value
|
|
88
|
+
if (!tzName) {
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let tzOffsetMinutes = 0
|
|
93
|
+
if (tzName !== 'UTC' && tzName !== 'GMT') {
|
|
94
|
+
const m = tzName.match(/^GMT([+-])(\d{1,2})(?::?(\d{2}))?$/)
|
|
95
|
+
if (!m) {
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
const h = parseInt(m[2], 10)
|
|
99
|
+
const min = m[3] ? parseInt(m[3], 10) : 0
|
|
100
|
+
tzOffsetMinutes = h * 60 + min
|
|
101
|
+
if (m[1] === '-') {
|
|
102
|
+
tzOffsetMinutes = -tzOffsetMinutes
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (tzOffsetMinutes === offsetMinutes) {
|
|
106
|
+
candidates.push(timeZone)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (candidates.length === 0) {
|
|
111
|
+
return undefined
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// More of our users are in places that observe DST, so we should prefer those. Choose Chicago over Mexico City; London over Lagos.
|
|
115
|
+
// Otherwise, choose the most populous city.
|
|
116
|
+
candidates.sort((a, b) => {
|
|
117
|
+
if (a.observesDST && !b.observesDST) {
|
|
118
|
+
return -1
|
|
119
|
+
}
|
|
120
|
+
if (!a.observesDST && b.observesDST) {
|
|
121
|
+
return 1
|
|
122
|
+
}
|
|
123
|
+
return b.leadCityPopulation - a.leadCityPopulation
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
return candidates[0].timeZoneName
|
|
127
|
+
}
|
|
128
|
+
|
|
30
129
|
/**
|
|
31
130
|
* Finds the time zone that matches the time zone and DST signature of the given time zone name.
|
|
32
131
|
* @param timeZoneName - e.g. 'America/Chicago'
|
|
@@ -50,7 +149,7 @@ export function getTimeZone(timeZoneName: string | null | undefined): TimeZone |
|
|
|
50
149
|
const samples = getDateSamples()
|
|
51
150
|
const dstSignature = getDSTSignature(timeZoneName, samples)
|
|
52
151
|
|
|
53
|
-
return timeZones.find(tz => tz.dstSignature === dstSignature)
|
|
152
|
+
return timeZones.find(tz => tz.dstSignature === dstSignature.signature)
|
|
54
153
|
}
|
|
55
154
|
|
|
56
155
|
/**
|
|
@@ -88,6 +187,7 @@ export function getTimeZones(): TimeZone[] {
|
|
|
88
187
|
timeZoneName: string // 'America/Chicago'
|
|
89
188
|
}[]
|
|
90
189
|
dstSignature: string
|
|
190
|
+
observesDST: boolean
|
|
91
191
|
offset: string
|
|
92
192
|
offsetMinutes: number
|
|
93
193
|
}
|
|
@@ -107,13 +207,13 @@ export function getTimeZones(): TimeZone[] {
|
|
|
107
207
|
const groups = new Map<string, TimeZoneCityGroup>()
|
|
108
208
|
for (const timezone of timezonesWithDSTSignatures) {
|
|
109
209
|
const cityName = timezone.mainCities[0] ?? timezone.countryName
|
|
110
|
-
const group = groups.get(timezone.dstSignature)
|
|
210
|
+
const group = groups.get(timezone.dstSignature.signature)
|
|
111
211
|
const population = cityPopulation.get(`${cityName}, ${timezone.countryName}`) ?? 0
|
|
112
212
|
if (!group) {
|
|
113
213
|
const offsetHour = Math.floor(Math.abs(timezone.rawOffsetInMinutes) / 60)
|
|
114
214
|
const offsetMinute = Math.abs(timezone.rawOffsetInMinutes) % 60
|
|
115
215
|
const offset = `${timezone.rawOffsetInMinutes < 0 ? '-' : '+'}${offsetHour.toString().padStart(2, '0')}:${offsetMinute.toString().padStart(2, '0')}`
|
|
116
|
-
groups.set(timezone.dstSignature, {
|
|
216
|
+
groups.set(timezone.dstSignature.signature, {
|
|
117
217
|
cities: [{
|
|
118
218
|
city: cityName,
|
|
119
219
|
country: timezone.countryName,
|
|
@@ -122,7 +222,8 @@ export function getTimeZones(): TimeZone[] {
|
|
|
122
222
|
timeZoneAlternativeName: timezone.alternativeName,
|
|
123
223
|
timeZoneName: timezone.name,
|
|
124
224
|
}],
|
|
125
|
-
dstSignature: timezone.dstSignature,
|
|
225
|
+
dstSignature: timezone.dstSignature.signature,
|
|
226
|
+
observesDST: timezone.dstSignature.observesDST,
|
|
126
227
|
offset,
|
|
127
228
|
offsetMinutes: timezone.rawOffsetInMinutes,
|
|
128
229
|
})
|
|
@@ -150,6 +251,8 @@ export function getTimeZones(): TimeZone[] {
|
|
|
150
251
|
.map(group => ({
|
|
151
252
|
cityNames: getCityList(group.cities),
|
|
152
253
|
dstSignature: group.dstSignature,
|
|
254
|
+
leadCityPopulation: group.cities[0].population,
|
|
255
|
+
observesDST: group.observesDST,
|
|
153
256
|
offset: group.offset,
|
|
154
257
|
offsetMinutes: group.offsetMinutes,
|
|
155
258
|
timeZoneAbbreviation: group.cities[0].timeZoneAbbreviation,
|
|
@@ -176,9 +279,10 @@ function getCityList(cities: { city: string, country: string }[]) {
|
|
|
176
279
|
}
|
|
177
280
|
|
|
178
281
|
// To detect places with the same DST rules, make a signature for each timezone: a list of offset minutes at each sample time
|
|
179
|
-
function getDSTSignature(timezoneName: string, sampleTimes: Date[]) {
|
|
282
|
+
function getDSTSignature(timezoneName: string, sampleTimes: Date[]): DSTSignature {
|
|
180
283
|
|
|
181
284
|
try {
|
|
285
|
+
let observesDST = false
|
|
182
286
|
const formatter = new Intl.DateTimeFormat('en', {
|
|
183
287
|
timeZone: timezoneName,
|
|
184
288
|
timeZoneName: 'shortOffset' as any, // TypeScript doesn't know that 'shortOffset' is safe: https://caniuse.com/?search=shortOffset
|
|
@@ -187,15 +291,27 @@ function getDSTSignature(timezoneName: string, sampleTimes: Date[]) {
|
|
|
187
291
|
})
|
|
188
292
|
|
|
189
293
|
const sig: string[] = []
|
|
294
|
+
let prevOffset: string | undefined
|
|
190
295
|
for (const sample of sampleTimes) {
|
|
191
296
|
const parts = formatter.formatToParts(sample)
|
|
192
|
-
const
|
|
193
|
-
sig.push(
|
|
297
|
+
const offset = parts.find(p => p.type === 'timeZoneName')?.value ?? ''
|
|
298
|
+
sig.push(offset)
|
|
299
|
+
// Only say "it observes DST" if it does so now or in the future. (Mexico stopped in 2022, for example.)
|
|
300
|
+
if (prevOffset && prevOffset !== offset && sample.getFullYear() >= thisYear) {
|
|
301
|
+
observesDST = true
|
|
302
|
+
}
|
|
303
|
+
prevOffset = offset
|
|
194
304
|
}
|
|
195
305
|
|
|
196
|
-
return
|
|
306
|
+
return {
|
|
307
|
+
observesDST,
|
|
308
|
+
signature: sig.join(','),
|
|
309
|
+
}
|
|
197
310
|
} catch (error) {
|
|
198
|
-
return
|
|
311
|
+
return {
|
|
312
|
+
observesDST: false,
|
|
313
|
+
signature: '',
|
|
314
|
+
}
|
|
199
315
|
}
|
|
200
316
|
}
|
|
201
317
|
|