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

DatePickerAndroid choose wrong default date #21906

Closed
kkusanagi opened this issue Oct 23, 2018 · 6 comments
Closed

DatePickerAndroid choose wrong default date #21906

kkusanagi opened this issue Oct 23, 2018 · 6 comments
Labels
Bug Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@kkusanagi
Copy link

I use moment code as below. As I am in Malaysia, so the timezone is +8

    const dtStartDate = moment();
    dtStartDate.hour(0).minute(0).second(0);
    this.state.dtStartDate = dtStartDate.toDate();

As I set code as below

try {
     const {action, year, month, day} = await DatePickerAndroid.open({
       // Use `new Date()` for current date.
       // May 25 2020. Month 0 is January.
       date: this.state.dtStartDate
     });
     if (action !== DatePickerAndroid.dismissedAction) {
       // Selected year, month (0-11), day
     }
   } catch ({code, message}) {
     console.warn('Cannot open date picker', message);
   }

The default select date had become yesterday. (The round select is yesterday which is wrong. But the today date word is highlighted which is correct.)
Then when I tried change the hour to 8. the default select date become today.

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Memory: 216.81 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.11.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
Android SDK:
Build Tools: 19.1.0, 20.0.0, 23.0.1, 23.0.3, 24.0.3, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3
API Levels: 16, 17, 18, 19, 21, 23, 24, 25, 26, 27
IDEs:
Android Studio: 3.1 AI-173.4819257
Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
react: ^16.5.2 => 16.5.2
react-native: ^0.57.2 => 0.57.2
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-check-box: 2.0.2
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
react-native-tab-view: 0.0.69

@wbercx
Copy link

wbercx commented Oct 26, 2018

Which Android API level is this on? I've run into a similar bug in production a few months ago, and I had a hard time working out what was going on because it was so unexpected.

Before you read any further, I upgraded JavaScriptCore and my problems went away.

What happened was:

const momentDate = moment();
const date = momentDate.toDate(); 

console.log(date); // Fri Oct 26 2018 21:58:01 GMT+0000 (AUS Eastern Summer Time)
console.log(date); // Fri Oct 27 2018 08:58:01 GMT+1100 (AUS Eastern Summer Time)

First access:

  • Timezone offset wrong (GMT+0000 in Australia?)
  • Date and time correct.
  • Human readable timezone correct.

Any subsequent access:

  • Timezone offset correct.
  • Date and time completely wrong, and got +11ed along with the offset.
  • Human readable timezone still correct.

The workaround I found that reliably worked at the time, which I still cannot wrap my head around because it's ridiculous:

const momentDate = moment();
const date = momentDate.toDate(); 

// Get the string representation, and assign it to a constant or variable.
// If the value of toString() is NOT assigned to something, it will continue to be unreliable,
// though I'm pretty sure any optimising compiler would immediately eliminate this as "dead code",
// as we're not even going to use corruptDateString.
const corruptDateString = date.toString();

// Happy days. Correct date, time and offset.
console.log(date); // Fri Oct 26 2018 21:58:01 GMT+1100 (AUS Eastern Summer Time)

@kkusanagi
Copy link
Author

@wbercx ,I'm doing at API 24 Android 7.0

I had tried your method and it failed.

Below is failed sample.

    const dtNowDate = moment();
    dtNowDate.hour(0).minute(0).second(0);
    const dtStartDate = dtNowDate.toDate();
    console.log(dtStartDate);
    const dtCorruptDate = dtStartDate.toString();
    this.state.dtStartDate = dtStartDate;
    console.log(dtStartDate);

the output is

Sat Oct 27 2018 00:00:00 GMT+0800 (Malaysia Time)
Sat Oct 27 2018 00:00:00 GMT+0800 (Malaysia Time)

And the calendar selection still wrong. seems the calendar is using UTC time .

Does this mean I need to remove GMT offset +0800 every time when select the date?

@stale
Copy link

stale bot commented Aug 2, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 2, 2019
@kkusanagi
Copy link
Author

i've upgrade to 0.59 and above and seems it fixed the bug.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 2, 2019
@stale
Copy link

stale bot commented Oct 31, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 31, 2019
@stale
Copy link

stale bot commented Nov 7, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Nov 7, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Nov 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

4 participants