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

UseClientTimeOffset on TimeView problem

1 Answer 40 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Lars Friede
Top achievements
Rank 1
Lars Friede asked on 17 Aug 2012, 09:58 AM
Hi,
I use the TimeView with a custom collection according to http://demos.telerik.com/aspnet-ajax/calendar/examples/datetimepicker/customcollection/defaultcs.aspx

The custom collection is needed because the user should be able to select the time 23:59. But this does not work in other timezones: when not in the same timezone as UTC time, the picker "results" in another time than the selected. For example, if I pick 23:59, the time in the textbox results in 21:59 for my timezone. Every other time is ok - for example if I pick 12:00, it picks the right one. It seems that the property UseClientTimeOffset does not work for this particular time 23:59?

 

public static void SetA4DValidTimeView(this RadTimeView timeView)
{
    ArrayList arrayList = new ArrayList();
    arrayList.Add(new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 0));
    for (int hour = 1; hour < 24; hour++)
        arrayList.Add(DateTime.UtcNow.Date.AddHours(hour));
    timeView.DataList.DataSource = arrayList;
}

 

 

I created a class in order to use the UseClientTimeOffset property.

 

 

public class A4DRadTimeView: RadTimeView
   {
       public A4DRadTimeView()
       {
           this.SetA4DValidTimeView();
           base.UseClientTimeOffset = true;
       }
   }

Markup:
<MCN:A4DRadDateTimePicker runat="server" ID="dateTimePickerDepartureTime" Enabled="false"
    CssClass="labelregular" Calendar-CultureInfo="en-US" SharedTimeViewID="A4DSharedTimeView">
    <DateInput EmptyMessage="____-__-__ __:__">
        <ClientEvents OnValueChanged="inputValueChanged" />
    </DateInput>
                                     
</MCN:A4DRadDateTimePicker>
<MCN:A4DRadTimeView ID="A4DSharedTimeView" runat="server"></MCN:A4DRadTimeView>


Script:
function inputValueChanged(sender, args) {
    
    var newValue = args.get_newValue();
    var dateFormat = sender.get_dateFormat();
    var date = args.get_newDate();
    if (date != null) {
        if (newValue.indexOf(sender.get_dateFormatInfo().TimeSeparator) < 0 &&
                    date.getHours() == 0 &&
                        date.getMinutes() == 0 &&
                            date.getSeconds() == 0) {
            date.setHours(0);
            date.setMinutes(01);
              
            sender.set_value(date.format(dateFormat));
        }
    }
     
}


1 Answer, 1 is accepted

Sort by
0
Lars Friede
Top achievements
Rank 1
answered on 17 Aug 2012, 11:33 AM

Ok, I have now solved it.

It was actually this line that was the problem:

arrayList.Add(new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 0)); 


The problem seems to be that the datetime created here had its "Kind"="Unspecified", but it should be UTC. (I think this caused it).

So I changed the code in SetA4DValidTimeView to:

List<DateTime> dateList = new List<DateTime>(); 
               
           for (int hour = 0; hour < 24; hour++) 
               dateList.Add(DateTime.UtcNow.Date.AddHours(hour)); 
           dateList[0] = dateList[0].AddDays(1).AddMinutes(-1);

Now, the dateList[0] have its Kind="UTC", and the user can select 23:59 with the correct result.
Tags
Calendar
Asked by
Lars Friede
Top achievements
Rank 1
Answers by
Lars Friede
Top achievements
Rank 1
Share this question
or