Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Android timezone issues and corresponding e2e test #472

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ public class RNDate {

public RNDate(Bundle args) {
now = Calendar.getInstance();
if (args != null && args.containsKey(RNConstants.ARG_TZOFFSET_MINS)) {
now.setTimeZone(TimeZone.getTimeZone("GMT"));
Integer timeZoneOffsetInMinutes = args.getInt(RNConstants.ARG_TZOFFSET_MINS);
now.add(Calendar.MILLISECOND, timeZoneOffsetInMinutes * 60000);
}

if (args != null && args.containsKey(RNConstants.ARG_VALUE)) {
set(args.getLong(RNConstants.ARG_VALUE));
}

if (args != null && args.containsKey(RNConstants.ARG_TZOFFSET_MINS)) {
now.setTimeZone(TimeZone.getTimeZone("GMT"));
Long timeZoneOffsetInMinutesFallback = args.getLong(RNConstants.ARG_TZOFFSET_MINS);
Integer timeZoneOffsetInMinutes = args.getInt(RNConstants.ARG_TZOFFSET_MINS, timeZoneOffsetInMinutesFallback.intValue());
now.add(Calendar.MILLISECOND, timeZoneOffsetInMinutes * 60000);
}
}

public void set(long value) {
Expand Down
2 changes: 1 addition & 1 deletion example/e2e/detoxTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('Example', () => {
await userChangesMinuteValue();
await userTapsOkButtonAndroid();

await expect(timeText).toHaveText('22:30');
await expect(timeText).toHaveText('23:30');
manojmalik20 marked this conversation as resolved.
Show resolved Hide resolved
}
});

Expand Down
5 changes: 1 addition & 4 deletions src/datetimepicker.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ function getPicker({

function timeZoneOffsetDateSetter(date, timeZoneOffsetInMinutes) {
let localDate = date;
if (
typeof timeZoneOffsetInMinutes !== 'undefined' &&
timeZoneOffsetInMinutes >= 0
) {
if (typeof timeZoneOffsetInMinutes === 'number') {
const offset =
localDate.getTimezoneOffset() * MIN_MS + timeZoneOffsetInMinutes * MIN_MS;
localDate = new Date(date.getTime() - offset);
Expand Down