mgcrea / angular-strap

AngularJS 1.2+ native directives for Bootstrap 3.
mgcrea.github.io/angular-strap
MIT License
5.73k stars 1.38k forks source link

Datepicker initially shows wrong date #1226

Closed dready closed 9 years ago

dready commented 9 years ago

Hi,

i am not sure if it's related to any specific issue therefore i write a new one.

Somehow the model Date Element get's the entered date - 1 day.

For Example if i click on November the 5th of this year: 05/11/2014 then the $scope.fromDate is 2014-11-04T23:00:00.000Z. (see screenshot)

This was tested on the angular-strap demo page as the screenshot suggests. http://mgcrea.github.io/angular-strap/##datepickers

I am Located in Vienna/Austria/Europe and our timezone is UTC+01:00

The fun part, if i load a model that has a date it works more or less as expected.

Any Ideas? Thanks screen shot 2014-11-04 at 13 17 04

vmlf01 commented 9 years ago

Please see #1196. Basically, it has to do with the browser timezone, the value you see on the model is a Date object relative to UTC ( "Z" ), and so is correct.

dready commented 9 years ago

Hi,

i am not yet totally convinced. For Example:

Let's say we have a hotel website. You can book when you are staying here. It's in paris.

Now the user want's to stay there from the 5th of December to the 10th of December. Unfortunately the User is located in Japan because of a business Trip.

Now the booking plattform recieves 2014-12-04T15:00:00.000Z ... they could not care less about timezones.. they just want to know when the user want's to stay there.

We could now argue that you just have to add some hours, depending on the Time (this is getting ugly) but in my tests i figured out that there are additional side effects.

If the model already has a date i get weird values: "2014-10-01T21:59:59.000Z" instead of 2014-10-01 (still UTC+1).. so how does this keep up with our booking example? I have no idea what the browsers local timezone looks like...

So basically i understand the need for UTC. But i have a perfect example within my application where i really don't care about it. And if the default behaviour is UTC i would really like an option to disable that converting since i don't need it.

Best Regards,

Thomas

dready commented 9 years ago

got it. use dateType=string instead.

sorry for the inconvenience.

bests

vmlf01 commented 9 years ago

Handling dates is a complicated matter. The UTC is javascript internal representation of Dates. Should a date picker be worried about timezones and what the applications does with the values the user picks? It couldn't hurt, but in the end you still have to think and decide how to process the values in the larger context of the application (client, server, database, external systems, etc.)

Something I am trying to get a grasp on also, but not an easy topic.

dsmithco commented 9 years ago

Frustating to save one date and then get another one back.... I was able to do what I needed by setting...

data-date-type="string" data-date-format="M/d/y" data-model-date-format="y-MM-d"

My model (Rails app) will accept a date format of "2014-1-15"

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.