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

Native Datepicker issue on mobile Chrome for Android #1591

Closed
francoislevesque opened this issue Jul 25, 2019 · 5 comments
Closed

Native Datepicker issue on mobile Chrome for Android #1591

francoislevesque opened this issue Jul 25, 2019 · 5 comments

Comments

@francoislevesque
Copy link

Overview of the problem

Buefy version: 0.7.10
Vuejs version: 2.6.10
OS/Browser: Chrome mobile Android
Timezone: America/Toronto

Description

The native datepicker doesn't selected the correct date on Chrome Mobile for Android. I haven't tested the other mobile browsers.

Steps to reproduce

  1. Create a simple b-datepicker component.
  2. Open the test app on Android Chrome
  3. Selected a date
  4. The registered date is one day off

Expected behavior

The registered date should be the selected one.

Actual behavior

The registered date is one day off.

Video link

https://youtu.be/lklamdGzGbw

@jtommy
Copy link
Member

jtommy commented Jul 25, 2019

Did you check the value (v-model) ?
Is it incorrect?

@afwn90cj93201nixr2e1re
Copy link
Contributor

Try to change timezone on your phone, xD.

@francoislevesque
Copy link
Author

It is currently 18:52 in Montreal, Canada (Eastern Time).

When I select the 27 of july and console.log the output of change event, I receive the following string:
Fri Jul 26 2019 20:00:00 GMT-0400 (Eastern Daylight Time)

The problem does not occur when using the buefy datepicker, only with the native one.

@francoislevesque
Copy link
Author

francoislevesque commented Jul 25, 2019

The issue is here :

Datepicker.vue

/*
 * Parse date from string
 */
onChangeNativePicker(event) {
  const date = event.target.value
  console.log(date, new Date(date)) // I added this to see the values
  this.computedValue = date ? new Date(date) : null
},

date is the expected "2019-07-27". However, once it is converted to a Date object, it becomes 4 hours earlier (Eastern time is -4 hours), hence the Fri Jul 26 2019 20:00:00 GMT-0400 (Eastern Daylight Time).

Because of that, when the value is parsed in the input via the formatYYYYMMDD() methods, the getDay method returns the day in my timezone, 26, instead of the selected 27.

Update

This would be a quick and easy fix:

onChangeNativePicker(event) {
  const date = event.target.value
  this.computedValue = date ? new Date(date + ' 00:00:00') : null
},

Update 2

The detail behind why Y-m-d creates a date in UTC, and Y-m-d h:i:s create a date in user's timezone is described here: https://stackoverflow.com/a/21153059

Generally speaking, when dealing with Date objects in js, I believe it's better to avoid to automatic parsing and instead manually set the date.

@jtommy
Copy link
Member

jtommy commented Jul 29, 2019

@francoislevesque indeed you can define a parser function, btw i'll add the quick fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants