This is a migrated thread and some comments may be shown as answers.

raddatepicker timezone issue

11 Answers 336 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Bart Martin Ongtangco
Top achievements
Rank 1
Bart Martin Ongtangco asked on 15 Sep 2010, 11:27 AM
hello,

we're currently getting the selected date through the client object (javascript) and passing them through jQuery ajax.

var theDate = $find('<%= radDatePicker1.ClientID %>').get_selectedDate();
$.ajax({data: JSON.stringify({ dateIn : theDate })});

[WebMethod()]
public void GetDateSelected(DateTime? dateIn)
{
    // do something
}

Our servers are currently in Arizona (GMT -7) and pacific time users doesn't experience the issue. If a client from a Mountain Timezone accesses the datepicker, the control increments 1 day to the selected date. Is there any way to prevent this?

11 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 15 Sep 2010, 03:32 PM
Hello,

If I understand you correctly, you can solve that by taking the current time of the user in javascript ( new Date().getTimezoneOffset() ) when a date is selected and if it belongs to a certain timezone, change the selected date to another one which is a day back.

Best wishes,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bart Martin Ongtangco
Top achievements
Rank 1
answered on 16 Sep 2010, 02:39 AM
i don't understand why i had to convert the date when they're simply selecting the date. why is it incrementing a day when the time difference is only 1 hour in between?
0
Tsvetina
Telerik team
answered on 16 Sep 2010, 03:15 PM
Hi,

Could you please let me know does this happen in all cases or only for certain dates? If it happens occasionally could you give us exact dates which we can test? Also, if there are any specifics about the scenario where the dates are selected, please, let us know. 

Additionally, could you confirm that the control which you use is RadDatePicker, not RadDateTimePicker?

We will try to replicate the issue locally and if we manage we will track its cause.

Sincerely yours,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bart Martin Ongtangco
Top achievements
Rank 1
answered on 16 Sep 2010, 11:08 PM
it happens on all dates. i did mention RadDatePicker. thank you
0
Tsvetina
Telerik team
answered on 22 Sep 2010, 07:45 AM
Hi,

Indeed, there is an issue with the selected dates of RadDatePicker but it is caused by current limitations of the javascript engine concerning daylight savings.

However, there is a workaround for the issue. Its logic is to wire the DateSelected client-side event of the Calendar in the RadDatePicker, take the value of the selected date and then in the method handling DateSelected client-side event of the RadDatePicker itself compare if they are the same. If not, set the date selected in the calendar as a date of the RadDatePicker.

You can find a sample project demonstrating that approach attached to this post.

All the best,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bart Martin Ongtangco
Top achievements
Rank 1
answered on 22 Sep 2010, 07:55 AM
i'll check on this Tsvetina, I shall update you in a day after testing your solution. Thank you
0
Bart Martin Ongtangco
Top achievements
Rank 1
answered on 22 Sep 2010, 08:49 AM
i mimicked your example but still got the same issue. here's how i tested it.

1) Server machine time (AZ GMT -7)
2) Client machine time (EST GMT -5)
3) I select the date
4) selected date value passes through jQuery ajax then to webservice.

once it gets in the webservice, the date just goes to the past with 1 day behind.
0
Tsvetina
Telerik team
answered on 27 Sep 2010, 03:30 PM
Hi Bart Martin Ongtangco,

In this case the solution goes back to the initial idea - you should keep the datetime values in the datasource in UTC format and adjust them according to the client's timezone offset before you use them on the client-side. I am attaching a project which demonstrates such approach. The time is adjusted in the _buildTimeMatrix() method.

Regards,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bart Martin Ongtangco
Top achievements
Rank 1
answered on 28 Sep 2010, 03:25 AM
Sorry, but i am really getting disappointed with your suggestions, i feel that we're going in circles. am i supposed to convert everything to RadDateTImePicker? I did mention that i'm using RadDatePicker, but you keep on insisting I should instead use this.
0
Tsvetina
Telerik team
answered on 30 Sep 2010, 11:09 AM
Hello,

You do not need to use a DateTimePicker, this javascript limitation influences the RadDatePicker in the same way, since its values are of DateTime type, even though it shows only the date. DateTimePicker is used in the sample in order to better visualize the scenario.

The problem does not originate from our controls' implementation, as previously said, so the ways to work around it may unfortunately not be that intuitive.

Sincerely yours,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Tom
Top achievements
Rank 1
answered on 18 Apr 2012, 08:33 PM
For reference, here is some code that could satisfy the needs of some users here. Tsvetina made a reference to it in a previous post.

I use it for sending a date, via an AJAX call, that is interpreted on the server as a DateTime with a zeroed out time component:

                        var selDt = ipt.get_selectedDate();
                        var offset = selDt.getTimezoneOffset();
                        selDt.setMinutes(selDt.getMinutes() - offset)
                        var toDate = selDt;

Some code I used came from a post here: http://stackoverflow.com/questions/1016847/converting-net-datetime-to-json/4372901#4372901
Tags
Calendar
Asked by
Bart Martin Ongtangco
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Bart Martin Ongtangco
Top achievements
Rank 1
Tom
Top achievements
Rank 1
Share this question
or