Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/block-editor/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../data" },
{ "path": "../dataviews/tsconfig.build.json" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../dom" },
{ "path": "../element/tsconfig.build.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../data" },
{ "path": "../dataviews/tsconfig.build.json" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../dom" },
{ "path": "../element/tsconfig.build.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../core-data/tsconfig.build.json" },
{ "path": "../data" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../dom" },
{ "path": "../element/tsconfig.build.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"references": [
{ "path": "../a11y/tsconfig.build.json" },
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../dom" },
{ "path": "../element/tsconfig.build.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{ "path": "./tsconfig.build.json" },
{ "path": "../a11y/tsconfig.build.json" },
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../dom" },
{ "path": "../element/tsconfig.build.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tsconfig.stories.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"references": [
{ "path": "../a11y/tsconfig.build.json" },
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../dom" },
{ "path": "../element/tsconfig.build.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{ "path": "../components/tsconfig.build.json" },
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../data" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../element/tsconfig.build.json" },
{ "path": "../hooks" },
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{ "path": "../components/tsconfig.build.json" },
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../data" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../element/tsconfig.build.json" },
{ "path": "../i18n/tsconfig.build.json" },
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/tsconfig.stories.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{ "path": "../components/tsconfig.build.json" },
{ "path": "../compose/tsconfig.build.json" },
{ "path": "../data" },
{ "path": "../date" },
{ "path": "../date/tsconfig.build.json" },
{ "path": "../deprecated/tsconfig.build.json" },
{ "path": "../element/tsconfig.build.json" },
{ "path": "../hooks" },
Expand Down
4 changes: 4 additions & 0 deletions packages/date/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Raise the minimum required Node.js version to `>=22.13.0`, for stable `require(esm)` support ([#84313](https://github.com/WordPress/gutenberg/pull/84313)).

### Internal

- Convert the tests to TypeScript, and split tsconfig into a build project and a default dev project so the tests are type checked without publishing their declarations ([#84830](https://github.com/WordPress/gutenberg/pull/84830)).

## 5.57.0 (2026-10-07)

### Bug Fixes
Expand Down
107 changes: 83 additions & 24 deletions packages/date/src/test/index.js → packages/date/src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import {
setSettings,
humanTimeDiff,
} from '../';
import type { L10nSettings } from '../';

type LocaleNameKey = 'months' | 'monthsShort' | 'weekdays' | 'weekdaysShort';

/**
* The default settings list the month and weekday names as arrays, which the
* locale tests map over.
*/
type L10nWithNameArrays = Omit< L10nSettings, LocaleNameKey > &
Record< LocaleNameKey, string[] >;

describe( 'isInTheFuture', () => {
it( 'should return true if the date is in the future', () => {
Expand All @@ -33,7 +43,7 @@ describe( 'isInTheFuture', () => {
// Set a timezone in the future.
setSettings( {
...settings,
timezone: { offset: '4', string: '' },
timezone: { ...settings.timezone, offset: 4, string: '' },
} );
// Create a Date object 1 minute in the past.
let date = new Date( Number( getDate() ) - 1000 * 60 );
Expand Down Expand Up @@ -81,7 +91,7 @@ describe( 'Function date', () => {
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
const l10n = settings.l10n as L10nWithNameArrays;
setSettings( {
...settings,
l10n: {
Expand Down Expand Up @@ -118,7 +128,11 @@ describe( 'Function date', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand All @@ -144,7 +158,7 @@ describe( 'Function date', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: '' },
timezone: { ...settings.timezone, offset: -4, string: '' },
} );

// Check.
Expand All @@ -170,7 +184,11 @@ describe( 'Function date', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand All @@ -191,7 +209,11 @@ describe( 'Function date', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand All @@ -206,13 +228,15 @@ describe( 'Function date', () => {
formattedDate = dateNoI18n(
'Y-m-d H:i',
'2019-06-18T11:00:00.000Z',
// @ts-expect-error `date()` types `timezone` as a string, but its JSDoc and `buildMoment()` accept a numeric UTC offset.
8
);
expect( formattedDate ).toBe( '2019-06-18 19:00' );

formattedDate = dateNoI18n(
'Y-m-d H:i',
'2019-06-18T11:00:00.000Z',
// @ts-expect-error `date()` types `timezone` as a string, but its JSDoc and `buildMoment()` accept a numeric UTC offset.
480
);
expect( formattedDate ).toBe( '2019-06-18 19:00' );
Expand Down Expand Up @@ -252,7 +276,7 @@ describe( 'Function gmdate', () => {
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
const l10n = settings.l10n as L10nWithNameArrays;
setSettings( {
...settings,
l10n: {
Expand Down Expand Up @@ -289,7 +313,11 @@ describe( 'Function gmdate', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand Down Expand Up @@ -331,7 +359,7 @@ describe( 'Function dateI18n', () => {
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
const l10n = settings.l10n as L10nWithNameArrays;
setSettings( {
...settings,
l10n: {
Expand Down Expand Up @@ -369,7 +397,11 @@ describe( 'Function dateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand All @@ -395,7 +427,7 @@ describe( 'Function dateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: '' },
timezone: { ...settings.timezone, offset: -4, string: '' },
} );

// Check.
Expand All @@ -421,7 +453,11 @@ describe( 'Function dateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand All @@ -442,7 +478,11 @@ describe( 'Function dateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand Down Expand Up @@ -474,7 +514,11 @@ describe( 'Function dateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check that offset 0 formats in UTC, not site timezone.
Expand All @@ -497,7 +541,11 @@ describe( 'Function dateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand All @@ -518,7 +566,11 @@ describe( 'Function dateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand Down Expand Up @@ -564,7 +616,7 @@ describe( 'Function gmdateI18n', () => {
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
const l10n = settings.l10n as L10nWithNameArrays;
setSettings( {
...settings,
l10n: {
Expand Down Expand Up @@ -601,7 +653,11 @@ describe( 'Function gmdateI18n', () => {
// Simulate different timezone.
setSettings( {
...settings,
timezone: { offset: -4, string: 'America/New_York' },
timezone: {
...settings.timezone,
offset: -4,
string: 'America/New_York',
},
} );

// Check.
Expand Down Expand Up @@ -640,8 +696,8 @@ describe( 'Moment.js Localization', () => {
expect( newSettings.l10n.locale ).toBe( settings.l10n.locale );

// Test the changed values.
expect( newSettings.l10n.relative.mm ).toBe( '%d localized minutes' );
expect( newSettings.l10n.relative.hh ).toBe( '%d localized hours' );
expect( newSettings.l10n.relative!.mm ).toBe( '%d localized minutes' );
expect( newSettings.l10n.relative!.hh ).toBe( '%d localized hours' );

// Restore default settings.
setSettings( settings );
Expand Down Expand Up @@ -693,15 +749,18 @@ describe( 'WP timezone zone recovery', () => {
function destroyWPZone() {
// moment-timezone stores zones in an internal object.
// Removing 'wp' simulates a third-party moment-timezone reload.
const zones = momentLib.tz._zones;
// `_zones` is internal, so moment-timezone's types do not declare it.
const zones = (
momentLib.tz as unknown as { _zones: Record< string, unknown > }
)._zones;
delete zones.wp;
}

it( 'getDate should recover after WP zone is lost', () => {
const settings = getSettings();
setSettings( {
...settings,
timezone: { offset: 4, string: '' },
timezone: { ...settings.timezone, offset: 4, string: '' },
} );

destroyWPZone();
Expand All @@ -718,7 +777,7 @@ describe( 'WP timezone zone recovery', () => {
const settings = getSettings();
setSettings( {
...settings,
timezone: { offset: 4, string: '' },
timezone: { ...settings.timezone, offset: 4, string: '' },
} );

destroyWPZone();
Expand All @@ -734,7 +793,7 @@ describe( 'WP timezone zone recovery', () => {
const settings = getSettings();
setSettings( {
...settings,
timezone: { offset: 4, string: '' },
timezone: { ...settings.timezone, offset: 4, string: '' },
} );

destroyWPZone();
Expand Down
5 changes: 5 additions & 0 deletions packages/date/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@wordpress/monorepo-tools/tsconfig/base.json",
"references": [ { "path": "../deprecated/tsconfig.build.json" } ]
}
7 changes: 5 additions & 2 deletions packages/date/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@wordpress/monorepo-tools/tsconfig/base.json",
"references": [ { "path": "../deprecated/tsconfig.build.json" } ]
"extends": "@wordpress/monorepo-tools/tsconfig/dev.base.json",
"compilerOptions": {
"types": [ "gutenberg-vitest-test-env" ]
},
"references": [ { "path": "./tsconfig.build.json" } ]
}
Loading
Loading