mercredi 23 mars 2016

In bootstrap datepicker, `changeDate` event has date property where value changes after formatting

I'm using bootstrap-datepicker in an ember component. On changeDate(event), I would like to set the date using event. However, event.date returns date in this format:

Tue Mar 01 2016 00:00:00 GMT+0530 (IST)

However doing this:

    function parseFormat(format) {
      return $.fn.datepicker.DPGlobal.parseFormat(format);
    }

    function formatDate(date, format) {
      return $.fn.datepicker.DPGlobal.formatDate(date, parseFormat(format), 'en');
    }

    let selectedDate = formatDate(event.date, parseFormat('yyyy-mm-dd'), 'en');

moves the date one day back(i.e, if 23 Mar 2016 is selected, selectedDate becomes 22 Mar 2016) I believe the problem is with 00:00:00 time because if set event.date as

event.date.setHours(event.date.getHours() + 6)

before formatDate it seems to work fine. However, this seems hacky

Is this an issue or is there a better solution to do what I'm asking for.

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire