@pushwoosh/dumb-components 1.1.237 → 1.1.238
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/Calendar/CalendarDropdown/helpers.js +1 -1
- package/Calendar/CalendarSuperForm/components/CalendarTimeAndTimezoneSection/CalendarTimeAndTimezoneSection.js +1 -1
- package/helpers/__tests__/timezones.test.js +16 -1
- package/helpers/timezones.d.ts +2 -0
- package/helpers/timezones.js +5 -0
- package/package.json +1 -2
- package/Calendar/helpers-tz.d.ts +0 -2
- package/Calendar/helpers-tz.js +0 -47
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatTimezoneShort } from '
|
|
1
|
+
import { formatTimezoneShort } from '../../helpers/timezones';
|
|
2
2
|
export function formatDate(val, withTime = true) {
|
|
3
3
|
const date = new Date(val.year, val.month - 1, val.day, 'hour' in val ? val.hour : 0, 'minute' in val ? val.minute : 0);
|
|
4
4
|
if (withTime) {
|
|
@@ -5,8 +5,8 @@ import { Columns, Horizontal, Vertical } from '@pushwoosh/kit-helpers';
|
|
|
5
5
|
import { TimeIcon } from '@pushwoosh/kit-icons';
|
|
6
6
|
import { H5, Text } from '@pushwoosh/kit-typography';
|
|
7
7
|
import { Button } from '../../../../Button';
|
|
8
|
+
import { formatTimezoneShort } from '../../../../helpers/timezones';
|
|
8
9
|
import { extendPeriodStruct, formatTwoDigitNumber } from '../../../helpers';
|
|
9
|
-
import { formatTimezoneShort } from '../../../helpers-tz';
|
|
10
10
|
import { Lang } from '../../../polyglot';
|
|
11
11
|
import { CalendarTimeInput } from '../CalendarTimeInput';
|
|
12
12
|
import { CalendarTimezoneSelect } from '../CalendarTimezoneSelect';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { canonicalizeTimezone, findTimezoneOption, formatTimezoneLabel, formatTimezoneOffset, getTimezoneOffsetSafe, listTimezones, resolveTimezoneOption } from '../timezones';
|
|
1
|
+
import { canonicalizeTimezone, findTimezoneOption, formatTimezoneLabel, formatTimezoneOffset, formatTimezoneShort, getTimezoneOffsetSafe, listTimezones, resolveTimezoneOption } from '../timezones';
|
|
2
2
|
const winter = new Date('2026-01-15T12:00:00Z');
|
|
3
3
|
const melbourneDst = new Date('2026-10-10T12:00:00Z');
|
|
4
|
+
const melbourneStandard = new Date('2026-06-15T12:00:00Z');
|
|
4
5
|
describe('formatTimezoneOffset', () => {
|
|
5
6
|
it('renders sign, hours and minutes', () => {
|
|
6
7
|
expect(formatTimezoneOffset(300)).toBe('GMT+05:00');
|
|
@@ -9,6 +10,20 @@ describe('formatTimezoneOffset', () => {
|
|
|
9
10
|
expect(formatTimezoneOffset(0)).toBe('GMT+00:00');
|
|
10
11
|
});
|
|
11
12
|
});
|
|
13
|
+
describe('formatTimezoneShort', () => {
|
|
14
|
+
it('renders the bare offset the calendar badge shows', () => {
|
|
15
|
+
expect(formatTimezoneShort('Asia/Almaty', winter)).toBe('GMT+05:00');
|
|
16
|
+
expect(formatTimezoneShort('Asia/Kolkata', winter)).toBe('GMT+05:30');
|
|
17
|
+
expect(formatTimezoneShort('UTC', winter)).toBe('GMT+00:00');
|
|
18
|
+
});
|
|
19
|
+
it('follows DST at the given instant', () => {
|
|
20
|
+
expect(formatTimezoneShort('Australia/Melbourne', melbourneStandard)).toBe('GMT+10:00');
|
|
21
|
+
expect(formatTimezoneShort('Australia/Melbourne', melbourneDst)).toBe('GMT+11:00');
|
|
22
|
+
});
|
|
23
|
+
it('keeps an unknown zone readable', () => {
|
|
24
|
+
expect(formatTimezoneShort('Not/AZone', winter)).toBe('Not/AZone');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
12
27
|
describe('formatTimezoneLabel', () => {
|
|
13
28
|
it('uses the current tzdata: Kazakhstan is UTC+5 since 2024', () => {
|
|
14
29
|
expect(formatTimezoneLabel('Asia/Almaty', winter)).toBe('(GMT+05:00) Asia/Almaty');
|
package/helpers/timezones.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare function getTimezoneOffsetSafe(timezone: string, at?: Date): numb
|
|
|
13
13
|
export declare function formatTimezoneOffset(minutes: number): string;
|
|
14
14
|
/** The shared picker label, `(GMT+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, `GMT+05:00`; a zone the engine doesn't know is shown by its bare name. */
|
|
17
|
+
export declare function formatTimezoneShort(timezone: string, at?: Date): string;
|
|
16
18
|
/** Option for any stored zone name — aliases, `Etc/GMT±N`, POSIX abbreviations — kept verbatim as the value. */
|
|
17
19
|
export declare function resolveTimezoneOption(timezone: string, at?: Date): TimezoneOption;
|
|
18
20
|
/** Zones the browser knows plus `UTC` and every non-empty `include` value, sorted by offset at `at` then by name. Pass the stored value as `include` so an old alias stays selectable and is re-saved unchanged. */
|
package/helpers/timezones.js
CHANGED
|
@@ -35,6 +35,11 @@ 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, `GMT+05:00`; a zone the engine doesn't know is shown by its bare name. */
|
|
39
|
+
export function formatTimezoneShort(timezone, at = new Date()) {
|
|
40
|
+
const offset = getTimezoneOffsetSafe(timezone, at);
|
|
41
|
+
return offset === null ? timezone : formatTimezoneOffset(offset);
|
|
42
|
+
}
|
|
38
43
|
/** Option for any stored zone name — aliases, `Etc/GMT±N`, POSIX abbreviations — kept verbatim as the value. */
|
|
39
44
|
export function resolveTimezoneOption(timezone, at = new Date()) {
|
|
40
45
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/dumb-components",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.238",
|
|
4
4
|
"description": "React components to build Pushwoosh products",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"styled-components": "^5.3.3 || ^6.0.0"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
|
-
"start": "pnpm --dir storybook start",
|
|
69
68
|
"build": "pushwoosh-engine lib:build",
|
|
70
69
|
"check": "pnpm run check:lint && pnpm run check:types",
|
|
71
70
|
"check:lint": "echo \"Run check:lint\" && eslint src",
|
package/Calendar/helpers-tz.d.ts
DELETED
package/Calendar/helpers-tz.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { formatTwoDigitNumber, getTimezoneOffset } from './helpers';
|
|
2
|
-
function getAllTimeZones() {
|
|
3
|
-
return Intl.supportedValuesOf('timeZone');
|
|
4
|
-
}
|
|
5
|
-
function formatTimezoneOffset(minutes) {
|
|
6
|
-
const minutesAbs = Math.abs(minutes);
|
|
7
|
-
const hours = Math.floor(minutesAbs / 60);
|
|
8
|
-
const mins = minutesAbs % 60;
|
|
9
|
-
const sign = minutes < 0 ? '-' : '+';
|
|
10
|
-
if (mins === 0) {
|
|
11
|
-
return `UTC${sign}${hours}`;
|
|
12
|
-
} else {
|
|
13
|
-
return `UTC${sign}${hours}:${formatTwoDigitNumber(mins)}`;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export function groupTimezonesByOffset(at = new Date()) {
|
|
17
|
-
const zones = getAllTimeZones();
|
|
18
|
-
const groups = new Map();
|
|
19
|
-
for (const tz of zones) {
|
|
20
|
-
try {
|
|
21
|
-
const diff = getTimezoneOffset(tz, at);
|
|
22
|
-
const arr = groups.get(diff);
|
|
23
|
-
if (arr) {
|
|
24
|
-
arr.push(tz);
|
|
25
|
-
} else {
|
|
26
|
-
groups.set(diff, [tz]);
|
|
27
|
-
}
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.warn(`Cannot get timezone info for "${tz}"`, e);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const result = [];
|
|
33
|
-
for (const [diff, list] of groups) {
|
|
34
|
-
list.sort((a, b) => a.localeCompare(b));
|
|
35
|
-
result.push([diff, list]);
|
|
36
|
-
}
|
|
37
|
-
result.sort((a, b) => a[0] - b[0]);
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
export function formatTimezoneShort(timezone) {
|
|
41
|
-
const offsetMinutes = getTimezoneOffset(timezone, new Date());
|
|
42
|
-
const formattedOffset = formatTimezoneOffset(offsetMinutes);
|
|
43
|
-
if (formattedOffset === 'UTC+0' || formattedOffset === 'UTC-0') {
|
|
44
|
-
return 'UTC';
|
|
45
|
-
}
|
|
46
|
-
return formattedOffset;
|
|
47
|
-
}
|