jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
360 stars 85 forks source link

Example jquery-ui code #33

Closed fform closed 9 years ago

fform commented 9 years ago

I have not used the bootstrap-datepicker before. When I saw the jquery example use $("..").datepicker( I just assumed this was also using jquery-ui. Of course I didn't initially read through every bit of the readme (my fault) but I was confused as bootstrap and jq-ui have a extremely similar pattern.

If you try to get Datepair with jquery-ui's datepicker, you get an unhelpful "empty object" error. I eventually realized that bootstrap had a different implementation for datepicker, and I needed to update the parseDate and updateDate methods.

So this is a suggestion to throw some example code like the following for jquery-ui into the readme.


$('#timePair').datepair({
    parseDate: function (el) {
      var utc = new Date($(el).datepicker('getDate'));
      return utc && new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000));
    },
    updateDate: function (el, v) {
      $(el).datepicker('setDate', v);
    }
  });
jonthornton commented 9 years ago

Great idea. Thanks!