From 47cd961f81d81ede388f4895b5c5d9d5031dca0d Mon Sep 17 00:00:00 2001 From: Bao Nguyen Date: Sun, 6 Sep 2026 14:42:34 +0700 Subject: [PATCH] fix(windows): respect the timeZoneOffsetInSeconds prop The IIFE computing the offset tested the const it was initializing instead of the prop, so the branch always took the device fallback and the timeZoneOffsetInSeconds prop was silently ignored. --- src/datetimepicker.windows.js | 3 +-- test/index.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/datetimepicker.windows.js b/src/datetimepicker.windows.js index ab14c93d..811a6ec6 100644 --- a/src/datetimepicker.windows.js +++ b/src/datetimepicker.windows.js @@ -70,12 +70,11 @@ export default function RNDateTimePickerQWE( } }; - // $FlowFixMe[recursive-definition] const timezoneOffsetInSeconds = (() => { // The Date object returns timezone in minutes. Convert that to seconds // and multiply by -1 so that the offset can be added to UTC+0 time to get // the correct value on the native side. - if (timezoneOffsetInSeconds == null && props.value != null) { + if (props.timeZoneOffsetInSeconds == null && props.value != null) { return -60 * props.value.getTimezoneOffset(); } return props.timeZoneOffsetInSeconds; diff --git a/test/index.test.js b/test/index.test.js index d1ce61d6..af11163b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -67,6 +67,31 @@ describe('DateTimePicker', () => { }); }); + describe('RNDateTimePickerWindows', () => { + it.each([0, 3600, -18000])( + 'passes timeZoneOffsetInSeconds %s to native Component', + async (timeZoneOffsetInSeconds) => { + const {toJSON} = await renderPicker(RNDateTimePickerWindows, { + timeZoneOffsetInSeconds, + }); + + expect(toJSON()).toHaveProperty( + 'props.timeZoneOffsetInSeconds', + timeZoneOffsetInSeconds, + ); + }, + ); + + it('falls back to the device offset when timeZoneOffsetInSeconds is omitted', async () => { + const {toJSON} = await renderPicker(RNDateTimePickerWindows); + + expect(toJSON()).toHaveProperty( + 'props.timeZoneOffsetInSeconds', + -60 * new Date(DATE).getTimezoneOffset(), + ); + }); + }); + test.each([ [RNDateTimePickerIOS, NativeDateTimePickerIOS, 'timestamp'], [RNDateTimePickerWindows, NativeDateTimePickerWindows, 'newDate'],