Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Datepicker value is off by a day when date format is different from the datepicker's date format #2906

Closed
Trish00 opened this issue Oct 29, 2014 · 8 comments

Comments

@Trish00
Copy link

Trish00 commented Oct 29, 2014

I have my date picker format set to: datepicker-popup="MM/dd/yyyy".

If a user types in a date in a different format the date ends as the day before.

i.e. User types in 2013-10-07 date value is 2013/10/06. But if the user types in 2013-10-7 the date is correct.
User types in 2014-08-09 date value is 2014-08-08 but if the user types in 2014-9-09 the date is correct.

Here is an example using your the datepicker example on your website. It would seem it doesn't like the leading zeros.

datepicker - 2014-08-10

@chrisirhc
Copy link
Contributor

Could you please set up a Plunker that demonstrates this issue?

https://github.com/angular-ui/bootstrap/blob/master/CONTRIBUTING.md#you-think-youve-found-a-bug

@Trish00
Copy link
Author

Trish00 commented Nov 3, 2014

Hi Chris,

I create the plunker at: http://plnkr.co/edit/HGL5835WyhMQLibwDX3F

Thanks

Trish

From: Chris Chua
Sent: Sunday, November 02, 2014 3:11 PM
To: angular-ui/bootstrap
Cc: Trish00
Subject: Re: [bootstrap] Datepicker value is off by a day when date format is different from the datepicker's date format (#2906)

Could you please set up a Plunker that demonstrates this issue?

https://github.com/angular-ui/bootstrap/blob/master/CONTRIBUTING.md#you-think-youve-found-a-bug


Reply to this email directly or view it on GitHub.

@chrisirhc
Copy link
Contributor

It looks like when the format is wrong it defaults using new Date(viewValue) to create the date. And when there's a leading 0 in the day, the Date constructor treats it as if it's the UTC timezone (perhaps treating it like the ISO8601 date string format).

I think perhaps in this case, it makes sense to mark the input as invalid.
We could also add an option to make the string parsing relaxed as it is now, but it does lead to unusual errors like this and should only be opt-in. However, that will be a breaking change.

@Trish00
Copy link
Author

Trish00 commented Nov 3, 2014

Thanks Chris, we are looking into using a mask to ensure a correct date format. What do you mean by breaking change.    On 11/03/14, Chris [email protected] wrote: It looks like when the format is wrong it defaults using new Date(viewValue) to create the date. And when there's a leading 0 in the day, the Date constructor treats it as if it's the UTC timezone (perhaps treating it like the ISO8601 date string format).I think perhaps in this case, it makes sense to mark the input as invalid.We could also add an option to make the string parsing relaxed as it is now, but it does lead to unusual errors like this and should only be opt-in. However, that will be a breaking change.—Reply to this email directly or view it on GitHub.

@chrisirhc
Copy link
Contributor

This is a breaking change because users who are expecting a relaxed format (allowing strings that don't fit the dateParser format) are now going to see an invalid input and a null or empty value. As such, perhaps it can be a new option to validate the format strictly.

@Trish00
Copy link
Author

Trish00 commented Nov 4, 2014

Do you know of a good angular mask directive that would work with this datepicker? Thanks  On 11/04/14, Chris [email protected] wrote: This is a breaking change because users who are expecting a relaxed format (allowing strings that don't fit the dateParser format) are now going to see an invalid input and a null or empty value. As such, perhaps it can be a new option to validate the format strictly.—Reply to this email directly or view it on GitHub.

@cgwyllie
Copy link

cgwyllie commented Aug 6, 2015

+1 for exposing a configuration option to allow 'strict' parsing, we've just encountered this issue with 'relaxed' parsing too on a multi-locale app.

davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting
* codepen: http://codepen.io/davious/pen/gpyVQm

related angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm)

related angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm?editors=101)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm?editors=101)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm?editors=101)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Aug 16, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm?editors=101)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Oct 3, 2015
datepickerConfig option for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting

[codepen](http://codepen.io/davious/pen/gpyVQm?editors=101)

Related: angular-ui#1891, angular-ui#2702, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Oct 11, 2015
datepickerConfig option timelessJsonMode for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format (1st load): converts model to date before normal formatting
* timelessJsonUtils constant with method jsonDateToTicks for use with min-date, max-date
	* alias jsonDateAddDays
	* set timelessJsonMode = 'withUtils' to add methods to parent scope
	* also: jsonToDate -- used internally

[codepen](http://codepen.io/davious/pen/XmMbma?editors=101)

Related: angular-ui#1891, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Oct 11, 2015
datepickerConfig option timelessJsonMode for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format (1st load): converts model to date before normal formatting
* timelessJsonUtils constant with method jsonDateToTicks for use with min-date, max-date
	* alias jsonDateAddDays
	* set timelessJsonMode = 'withUtils' to add methods to parent scope
	* also: jsonToDate -- used internally

[codepen](http://codepen.io/davious/pen/XmMbma?editors=101)

Related: angular-ui#1891, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Oct 11, 2015
datepickerConfig option timelessJsonMode for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format (1st load): converts model to date before normal formatting
* timelessJsonUtils constant with method jsonDateToTicks for use with min-date, max-date
	* alias jsonDateAddDays
	* set timelessJsonMode = 'withUtils' to add methods to parent scope
	* also: jsonToDate -- used internally

[codepen](http://codepen.io/davious/pen/XmMbma?editors=101)

Related: angular-ui#1891, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Oct 11, 2015
datepickerConfig option timelessJsonMode for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting
* timelessJsonUtils constant with method jsonDateToTicks for use with min-date, max-date
	* alias jsonDateAddDays
	* set timelessJsonMode = 'withUtils' to add methods to parent scope
	* also: jsonToDate -- used internally

[codepen](http://codepen.io/davious/pen/XmMbma?editors=101)

Related: angular-ui#1891, angular-ui#2906, angular-ui#2952
davious added a commit to davious/angular-ui-bootstrap that referenced this issue Oct 12, 2015
datepickerConfig option timelessJsonMode for json models when we don't care about the time.
* on init and parse: sets model to 'yyyy-MM-dd' format
* on format: converts model to date before normal formatting
* timelessJsonUtils constant with method jsonDateToTicks for use with min-date, max-date
	* alias jsonDateAddDays
	* set timelessJsonMode = 'withUtils' to add methods to parent scope
	* also: jsonToDate -- used internally

[codepen](http://codepen.io/davious/pen/XmMbma?editors=101)

Related: angular-ui#1891, angular-ui#2906, angular-ui#2952
@wesleycho wesleycho modified the milestones: Backlog, 1.0.0 Oct 31, 2015
@wesleycho
Copy link
Contributor

This should now be fixed in master, if not in 0.14.3

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

No branches or pull requests

4 participants