Meteor-Community-Packages / meteor-autoform-bs-datepicker

Custom "bootstrap-datepicker" input type for AutoForm
MIT License
25 stars 32 forks source link

Days are stored one day before actual selection #40

Closed jerocosio closed 7 years ago

jerocosio commented 8 years ago

Hi, I think there is a bug or something wrong with this plugin, when you choose the type as Date and try to add a new date, the plugin don't saves the actual date you want, it saves a day before, you can see this even on the Demos: http://autoform.meteor.com/types just add any date, and then check out the console to see how it changes.

jerocosio commented 8 years ago

This error is still happening, anyway to fix this?

screen shot 2016-06-15 at 4 51 42 p m

jowilhnson commented 8 years ago

It's annoying. I had to set up hooks for any autoform's that use the datepicker.

formToDoc:function(doc) {
    var badDate = doc.date;
    //get the number of minutes the local timezone is offset from UTC
    var zone = new Date().getTimezoneOffset();
    /*
    make a new Date object using the milliseconds from epoch of badDate
    + timezoneOffset converted to milliseconds 
   */
    var newDate = new Date(badDate.getTime() + (zone * 60000));
    //This will set the submitted date to be midnight local time of the day selected in datepicker
    doc.date = newDate;
    return doc;
  }
aldeed commented 7 years ago

Since timezone does not matter, dates are stored UTC by convention. Be sure to specify UTC timezone whenever you display them.