@mediafly/js-ui 51.6.0-11 → 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.
@@ -1,8 +1,16 @@
1
+ export interface DSTSignature {
2
+ observesDST: boolean;
3
+ signature: string;
4
+ }
1
5
  export interface TimeZone {
2
6
  /** 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 name = (_b = (_a = parts.find(p => p.type === 'timeZoneName')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
138
- sig.push(name);
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 sig.join(',');
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;AAmBjD,IAAI,eAAe,GAAsB,IAAI,CAAA;AAE7C;;GAEG;AACH,SAAgB,kBAAkB;IACjC,eAAe,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,gDAEC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,YAAuC;IAElE,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAChD,OAAO,SAAS,CAAA;KAChB;IAED,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,YAAY,KAAK,YAAY,CAAC,CAAA;IACzE,IAAI,UAAU,EAAE;QACf,OAAO,UAAU,CAAA;KACjB;IAED,mHAAmH;IACnH,6EAA6E;IAE7E,MAAM,OAAO,GAAG,cAAc,EAAE,CAAA;IAChC,MAAM,YAAY,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A;IACD,MAAM,OAAO,GAAW,EAAE,CAAA;IAE1B,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACtB,KAAK,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,QAAQ,EAAE;YAChC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAClD;KACD;IAED,OAAO,OAAO,CAAA;AACf,CAAC"}
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,CAAA;IACjC,IAAI,CAAC,EAAE;QACN,aAAa,GAAG,CAAC,CAAA;KACjB;SAAM;QACN,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAA;QAChE,IAAI,CAAC,WAAW,EAAE;YACjB,aAAa,GAAG,CAAC,CAAA;S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CAAC,GAAG,CAAC;SACxB,CAAA;KACD;IAAC,OAAO,KAAK,EAAE;QACf,OAAO;YACN,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,EAAE;SACb,CAAA;KACD;AACF,CAAC;AAED,SAAS,cAAc;IAEtB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IACjC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAA;IACrD,MAAM,QAAQ,GAAG;QAChB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE;QACf,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAG,SAAS;KAC3B,CAAA;IACD,MAAM,OAAO,GAAW,EAAE,CAAA;IAE1B,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACtB,KAAK,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,QAAQ,EAAE;YAChC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAClD;KACD;IAED,OAAO,OAAO,CAAA;AACf,CAAC"}
@@ -472,8 +472,8 @@
472
472
  "affectsGlobalScope": false
473
473
  },
474
474
  "../src/components/date-time-zone-city-picker/time-zone-city.service.ts": {
475
- "version": "7964695cb90f2b3e4f35a8dd0aaebef5acce5afae6b10698a67f4db467866acb",
476
- "signature": "515982a491a5a29f3c5548e2457508deb31e684fe78661c33c3f5286fc901843",
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": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediafly/js-ui",
3
- "version": "51.6.0-11",
3
+ "version": "51.6.0-12",
4
4
  "license": "UNLICENSED",
5
5
  "description": "UI components for Mediafly Angular applications",
6
6
  "repository": {
@@ -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 name = parts.find(p => p.type === 'timeZoneName')?.value ?? ''
193
- sig.push(name)
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 sig.join(',')
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