@pushwoosh/dumb-components 1.1.238 → 2.0.0
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.
|
@@ -4,21 +4,21 @@ const melbourneDst = new Date('2026-10-10T12:00:00Z');
|
|
|
4
4
|
const melbourneStandard = new Date('2026-06-15T12:00:00Z');
|
|
5
5
|
describe('formatTimezoneOffset', () => {
|
|
6
6
|
it('renders sign, hours and minutes', () => {
|
|
7
|
-
expect(formatTimezoneOffset(300)).toBe('
|
|
8
|
-
expect(formatTimezoneOffset(330)).toBe('
|
|
9
|
-
expect(formatTimezoneOffset(-210)).toBe('
|
|
10
|
-
expect(formatTimezoneOffset(0)).toBe('
|
|
7
|
+
expect(formatTimezoneOffset(300)).toBe('UTC+05:00');
|
|
8
|
+
expect(formatTimezoneOffset(330)).toBe('UTC+05:30');
|
|
9
|
+
expect(formatTimezoneOffset(-210)).toBe('UTC-03:30');
|
|
10
|
+
expect(formatTimezoneOffset(0)).toBe('UTC+00:00');
|
|
11
11
|
});
|
|
12
12
|
});
|
|
13
13
|
describe('formatTimezoneShort', () => {
|
|
14
14
|
it('renders the bare offset the calendar badge shows', () => {
|
|
15
|
-
expect(formatTimezoneShort('Asia/Almaty', winter)).toBe('
|
|
16
|
-
expect(formatTimezoneShort('Asia/Kolkata', winter)).toBe('
|
|
17
|
-
expect(formatTimezoneShort('UTC', winter)).toBe('
|
|
15
|
+
expect(formatTimezoneShort('Asia/Almaty', winter)).toBe('UTC+05:00');
|
|
16
|
+
expect(formatTimezoneShort('Asia/Kolkata', winter)).toBe('UTC+05:30');
|
|
17
|
+
expect(formatTimezoneShort('UTC', winter)).toBe('UTC+00:00');
|
|
18
18
|
});
|
|
19
19
|
it('follows DST at the given instant', () => {
|
|
20
|
-
expect(formatTimezoneShort('Australia/Melbourne', melbourneStandard)).toBe('
|
|
21
|
-
expect(formatTimezoneShort('Australia/Melbourne', melbourneDst)).toBe('
|
|
20
|
+
expect(formatTimezoneShort('Australia/Melbourne', melbourneStandard)).toBe('UTC+10:00');
|
|
21
|
+
expect(formatTimezoneShort('Australia/Melbourne', melbourneDst)).toBe('UTC+11:00');
|
|
22
22
|
});
|
|
23
23
|
it('keeps an unknown zone readable', () => {
|
|
24
24
|
expect(formatTimezoneShort('Not/AZone', winter)).toBe('Not/AZone');
|
|
@@ -26,13 +26,13 @@ describe('formatTimezoneShort', () => {
|
|
|
26
26
|
});
|
|
27
27
|
describe('formatTimezoneLabel', () => {
|
|
28
28
|
it('uses the current tzdata: Kazakhstan is UTC+5 since 2024', () => {
|
|
29
|
-
expect(formatTimezoneLabel('Asia/Almaty', winter)).toBe('(
|
|
30
|
-
expect(formatTimezoneLabel('Asia/Qostanay', winter)).toBe('(
|
|
29
|
+
expect(formatTimezoneLabel('Asia/Almaty', winter)).toBe('(UTC+05:00) Asia/Almaty');
|
|
30
|
+
expect(formatTimezoneLabel('Asia/Qostanay', winter)).toBe('(UTC+05:00) Asia/Qostanay');
|
|
31
31
|
});
|
|
32
32
|
it('keeps half-hour zones east of UTC exact', () => {
|
|
33
|
-
expect(formatTimezoneLabel('Asia/Kolkata', winter)).toBe('(
|
|
34
|
-
expect(formatTimezoneLabel('Asia/Kathmandu', winter)).toBe('(
|
|
35
|
-
expect(formatTimezoneLabel('America/St_Johns', winter)).toBe('(
|
|
33
|
+
expect(formatTimezoneLabel('Asia/Kolkata', winter)).toBe('(UTC+05:30) Asia/Kolkata');
|
|
34
|
+
expect(formatTimezoneLabel('Asia/Kathmandu', winter)).toBe('(UTC+05:45) Asia/Kathmandu');
|
|
35
|
+
expect(formatTimezoneLabel('America/St_Johns', winter)).toBe('(UTC-03:30) America/St_Johns');
|
|
36
36
|
});
|
|
37
37
|
it('resolves the offset at the given instant, not today', () => {
|
|
38
38
|
expect(getTimezoneOffsetSafe('Australia/Melbourne', winter)).toBe(660);
|
|
@@ -40,9 +40,9 @@ describe('formatTimezoneLabel', () => {
|
|
|
40
40
|
expect(getTimezoneOffsetSafe('Australia/Melbourne', melbourneDst)).toBe(660);
|
|
41
41
|
});
|
|
42
42
|
it('labels Etc and POSIX names the backend accepts but the picker does not list', () => {
|
|
43
|
-
expect(formatTimezoneLabel('Etc/GMT+3', winter)).toBe('(
|
|
44
|
-
expect(formatTimezoneLabel('Etc/GMT-0', winter)).toBe('(
|
|
45
|
-
expect(formatTimezoneLabel('EST', winter)).toBe('(
|
|
43
|
+
expect(formatTimezoneLabel('Etc/GMT+3', winter)).toBe('(UTC-03:00) Etc/GMT+3');
|
|
44
|
+
expect(formatTimezoneLabel('Etc/GMT-0', winter)).toBe('(UTC+00:00) Etc/GMT-0');
|
|
45
|
+
expect(formatTimezoneLabel('EST', winter)).toBe('(UTC-05:00) EST');
|
|
46
46
|
});
|
|
47
47
|
it('falls back to the bare name for a zone the engine does not know', () => {
|
|
48
48
|
expect(getTimezoneOffsetSafe('Not/A_Zone')).toBeNull();
|
|
@@ -130,7 +130,7 @@ describe('resolveTimezoneOption', () => {
|
|
|
130
130
|
it('never rewrites the stored value', () => {
|
|
131
131
|
expect(resolveTimezoneOption('Europe/Kiev', winter)).toEqual({
|
|
132
132
|
value: 'Europe/Kiev',
|
|
133
|
-
label: '(
|
|
133
|
+
label: '(UTC+02:00) Europe/Kiev'
|
|
134
134
|
});
|
|
135
135
|
expect(resolveTimezoneOption('Not/A_Zone', winter)).toEqual({
|
|
136
136
|
value: 'Not/A_Zone',
|
package/helpers/timezones.d.ts
CHANGED
|
@@ -9,11 +9,11 @@ export declare function getBrowserTimezone(): string;
|
|
|
9
9
|
export declare function canonicalizeTimezone(timezone: string): string | null;
|
|
10
10
|
/** Offset of `timezone` in minutes east of UTC at instant `at`, or `null` for a zone the engine doesn't know. */
|
|
11
11
|
export declare function getTimezoneOffsetSafe(timezone: string, at?: Date): number | null;
|
|
12
|
-
/** Minutes east of UTC rendered as `
|
|
12
|
+
/** Minutes east of UTC rendered as `UTC+05:00` / `UTC-03:30`. */
|
|
13
13
|
export declare function formatTimezoneOffset(minutes: number): string;
|
|
14
|
-
/** The shared picker label, `(
|
|
14
|
+
/** The shared picker label, `(UTC+05:00) Asia/Almaty` at instant `at`; a zone the engine doesn't know is labelled by its bare name. */
|
|
15
15
|
export declare function formatTimezoneLabel(timezone: string, at?: Date): string;
|
|
16
|
-
/** Compact badge for a zone, `
|
|
16
|
+
/** Compact badge for a zone, `UTC+05:00`; a zone the engine doesn't know is shown by its bare name. */
|
|
17
17
|
export declare function formatTimezoneShort(timezone: string, at?: Date): string;
|
|
18
18
|
/** Option for any stored zone name — aliases, `Etc/GMT±N`, POSIX abbreviations — kept verbatim as the value. */
|
|
19
19
|
export declare function resolveTimezoneOption(timezone: string, at?: Date): TimezoneOption;
|
package/helpers/timezones.js
CHANGED
|
@@ -22,20 +22,20 @@ export function getTimezoneOffsetSafe(timezone, at = new Date()) {
|
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
/** Minutes east of UTC rendered as `
|
|
25
|
+
/** Minutes east of UTC rendered as `UTC+05:00` / `UTC-03:30`. */
|
|
26
26
|
export function formatTimezoneOffset(minutes) {
|
|
27
27
|
const sign = minutes < 0 ? '-' : '+';
|
|
28
28
|
const absolute = Math.abs(minutes);
|
|
29
29
|
const hours = String(Math.floor(absolute / 60)).padStart(2, '0');
|
|
30
30
|
const mins = String(absolute % 60).padStart(2, '0');
|
|
31
|
-
return `
|
|
31
|
+
return `UTC${sign}${hours}:${mins}`;
|
|
32
32
|
}
|
|
33
|
-
/** The shared picker label, `(
|
|
33
|
+
/** The shared picker label, `(UTC+05:00) Asia/Almaty` at instant `at`; a zone the engine doesn't know is labelled by its bare name. */
|
|
34
34
|
export function formatTimezoneLabel(timezone, at = new Date()) {
|
|
35
35
|
const offset = getTimezoneOffsetSafe(timezone, at);
|
|
36
36
|
return offset === null ? timezone : `(${formatTimezoneOffset(offset)}) ${timezone}`;
|
|
37
37
|
}
|
|
38
|
-
/** Compact badge for a zone, `
|
|
38
|
+
/** Compact badge for a zone, `UTC+05:00`; a zone the engine doesn't know is shown by its bare name. */
|
|
39
39
|
export function formatTimezoneShort(timezone, at = new Date()) {
|
|
40
40
|
const offset = getTimezoneOffsetSafe(timezone, at);
|
|
41
41
|
return offset === null ? timezone : formatTimezoneOffset(offset);
|