jonthornton / Datepair.js

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

getTimeDiff - problem #16

Closed grzegorzjawo closed 10 years ago

grzegorzjawo commented 10 years ago

I'm using http://jonthornton.github.io/Datepair.js/ and I need a variable time difference in days with hours to use in other functions.

I can not find of example of how tu use this method.

When I use it:

$('#container').datepair(); var milliseconds = $('#container').datepair('getTimeDiff'); $('#container').datepair('remove');

I get an error in Firefox: TypeError: data[option] is not a function jquery.datepair.js:30

Thanks a lot for simple example how to get time diff.

jonthornton commented 10 years ago

This was a bug - should be fixed now. Thanks for reporting!

grzegorzjawo commented 10 years ago

Still... the error is gone, but I don't get milliseconds. Can you look at this below...

$('#containter').datepair();

var milliseconds = $('#containter').datepair('getTimeDiff');

$("Value").ready(function()

{

    $("#txtTarget").keyup(function(event)

    {

        $("#Result").val(milliseconds);

     });

});
jonthornton commented 10 years ago

Don't use $("#txtTarget").keyup(); bind to the rangeSelected event:

$('#container').on('rangeSelected', function(e){
    var milliseconds = $('#containter').datepair('getTimeDiff');
    // do something with milliseconds value
});
grzegorzjawo commented 10 years ago

Thanks. It displays seconds, but when I change few times the range, unfortunately it doesn't display new value of seconds. Is there something You can do about it?

$('#containter').on('rangeSelected', function(e){
var milliseconds = $('#containter').datepair('getTimeDiff');
$('#eventsExampleStatus').text('' + milliseconds + '');
jonthornton commented 10 years ago

I need to see a fully working code sample to help further. Post a link to your app or put code in a jsfiddle.

grzegorzjawo commented 10 years ago

Sure... http://www.goget.pl/system/plus/payu/examples/v2/order/calendar.php

jonthornton commented 10 years ago

You're mixing non-jquery

var SearchEl = document.getElementById('container');
var SearchDatepair = new Datepair(SearchEl);

and jquery

var milliseconds = $('#container').datepair('getTimeDiff');

That's why it's not working. Pick one or the other.

grzegorzjawo commented 10 years ago

Good point. I changed it and it works. Thanks for help!