Skip to content

Commit b87a0c4

Browse files
authored
fix: resolve timezoneOffsetInMinutes android bugs (#472)
* modified timezoneOffsetInMinutes prop and corresponding e2e test cases * corrected e2e tests to get similar behaviour for android and ios
1 parent 7113c9e commit b87a0c4

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

android/src/main/java/com/reactcommunity/rndatetimepicker/RNDate.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ public class RNDate {
99

1010
public RNDate(Bundle args) {
1111
now = Calendar.getInstance();
12-
if (args != null && args.containsKey(RNConstants.ARG_TZOFFSET_MINS)) {
13-
now.setTimeZone(TimeZone.getTimeZone("GMT"));
14-
Integer timeZoneOffsetInMinutes = args.getInt(RNConstants.ARG_TZOFFSET_MINS);
15-
now.add(Calendar.MILLISECOND, timeZoneOffsetInMinutes * 60000);
16-
}
1712

1813
if (args != null && args.containsKey(RNConstants.ARG_VALUE)) {
1914
set(args.getLong(RNConstants.ARG_VALUE));
2015
}
16+
17+
if (args != null && args.containsKey(RNConstants.ARG_TZOFFSET_MINS)) {
18+
now.setTimeZone(TimeZone.getTimeZone("GMT"));
19+
Long timeZoneOffsetInMinutesFallback = args.getLong(RNConstants.ARG_TZOFFSET_MINS);
20+
Integer timeZoneOffsetInMinutes = args.getInt(RNConstants.ARG_TZOFFSET_MINS, timeZoneOffsetInMinutesFallback.intValue());
21+
now.add(Calendar.MILLISECOND, timeZoneOffsetInMinutes * 60000);
22+
}
2123
}
2224

2325
public void set(long value) {

example/e2e/detoxTest.spec.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,14 @@ describe('Example', () => {
176176

177177
if (isIOS()) {
178178
const testElement = getDateTimePickerIOS();
179-
await testElement.setColumnToValue(0, '2');
180-
await testElement.setColumnToValue(1, '44');
181-
await testElement.setColumnToValue(2, 'PM');
182-
183-
await expect(timeText).toHaveText('13:44');
179+
await testElement.setColumnToValue(0, '12');
180+
await testElement.setColumnToValue(1, '30');
181+
await testElement.setColumnToValue(2, 'AM');
184182
} else {
185183
await userChangesMinuteValue();
186184
await userTapsOkButtonAndroid();
187-
188-
await expect(timeText).toHaveText('22:30');
189185
}
186+
await expect(timeText).toHaveText('23:30');
190187
});
191188

192189
it(':android: given we specify neutralButtonLabel, tapping the corresponding button sets date to the beginning of the unix time epoch', async () => {

src/datetimepicker.android.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ function getPicker({
6666

6767
function timeZoneOffsetDateSetter(date, timeZoneOffsetInMinutes) {
6868
let localDate = date;
69-
if (
70-
typeof timeZoneOffsetInMinutes !== 'undefined' &&
71-
timeZoneOffsetInMinutes >= 0
72-
) {
69+
if (typeof timeZoneOffsetInMinutes === 'number') {
7370
const offset =
7471
localDate.getTimezoneOffset() * MIN_MS + timeZoneOffsetInMinutes * MIN_MS;
7572
localDate = new Date(date.getTime() - offset);

0 commit comments

Comments
 (0)