in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Convert from Universal Time

Last post 07-20-2008 10:06 AM by C1_IrinaP. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-15-2008 4:57 PM

    Convert from Universal Time

    I need to be able to convert from Universal time to local time in the C1Scheduler. I added my converter in the interval template, and it shows up with the correct time, but no in the right timeframe on the scheduler.
    Filed under: ,
  • 07-16-2008 1:30 PM In reply to

    Re: Convert from Universal Time

    >I need to be able to convert from Universal time to local time in the C1Scheduler. I
    >added my converter in the interval template, and it shows up with the correct time, but
    >no in the right timeframe on the scheduler.

    I think you should add the same converter to other scheduler templates defining it's
    layout. I.e. for all templates which use VisualInterval.StartTime for binding. In other
    words, all UI should be drawn with the same time.

    Can you consider some other approach? For example:

    - create and save appointments with local time;

    - change appointment times from local to Universal before saving data to database and from
    Universal to local after loading data. In this case UI should be drawn in the local time
    automatically.
  • 07-17-2008 10:38 AM In reply to

    Re: Convert from Universal Time

    C1_IrinaP:


    I think you should add the same converter to other scheduler templates defining it's
    layout. I.e. for all templates which use VisualInterval.StartTime for binding. In other
    words, all UI should be drawn with the same time.

    Can you consider some other approach? For example:

    - create and save appointments with local time;

    - change appointment times from local to Universal before saving data to database and from
    Universal to local after loading data. In this case UI should be drawn in the local time
    automatically.

     

    I have to store the data in universal time, so changing to store local is not an option. Which template(s) do I need to change? In addition, I have a ListView that shows all my meetings. So can I convert my times before displaying, Yes, should i have to, no. There needs to be a way to change this. There should be an option to define a converter on the NestedProperty.

  • 07-17-2008 2:28 PM In reply to

    Re: Convert from Universal Time

    > I have to store the data in universal time, so changing to store local is not an option.
    > Which template(s) do I need to change? In addition, I have a ListView that shows all my
    > meetings. So can I convert my times before displaying, Yes, should i have to, no. There
    > needs to be a way to change this. There should be an option to define a converter on the
    > NestedProperty.

    I think, changing times in templates is a wrong decision. There are a lot of internal
    calculations which are made with using appointment times. All these operations should be
    done with the same times.

    Supporting different DateTimeKind values is in our todo list. We have no time frame for
    this feature yet. Is that urgent for you?

    Do you use recurring events? If no, perhaps you can try to workaround the issue by
    changing times when appointments are readed and stored from/to database. For example, if
    you have typed dataset for Appointments table, you may change getters and setters for
    DateTime fields.

    Here is a part of autogenerated code for AppointmentsRow class from my test project:

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator",
    "2.0.0.0")]
    public partial class AppointmentsRow : global::System.Data.DataRow {

    .... skipped

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public System.DateTime End {
    get {
    try {
    return
    ((global::System.DateTime)(this[this.tableAppointments.EndColumn]));
    }
    catch (global::System.InvalidCastException e) {
    throw new global::System.Data.StrongTypingException("The value for
    column \'End\' in table \'Appointments\' is DBNull.", e);
    }
    }
    set {
    this[this.tableAppointments.EndColumn] = value;
    }
    }

    You can change the code in the next way:

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public System.DateTime End {
    get {
    try {
    // convert to local time at reading
    global::System.DateTime dataBaseValue =
    ((global::System.DateTime)(this[this.tableAppointments.EndColumn]));
    global::System.DateTime.SpecifyKind(localValue, DateTimeKind.Utc);
    return dataBaseValue .ToLocalTime();
    }
    catch (global::System.InvalidCastException e) {
    throw new global::System.Data.StrongTypingException("The value for
    column \'End\' in table \'Appointments\' is DBNull.", e);
    }
    }
    set {
    // convert to univeral time before storing
    global::System.DateTime localValue = value;
    global::System.DateTime.SpecifyKind(localValue,
    DateTimeKind.Local);
    this[this.tableAppointments.EndColumn] = localValue
    ..ToUniversalTime() ;
    }
    }
  • 07-20-2008 10:06 AM In reply to

    Re: Convert from Universal Time

    In the next maintenance release the new property will be added to CalendarHelper class:

        public DateTimeKind DateTimeKind { get; set; }

    If you set this property to DateTimeKind.Utc, your data will be converted to Utc time before saving and back to local time before using them in the C1Scheduler control.

    If you want to get the build for testing before it is available on prerelease site, let me know your e-mail, I'll send it to you.

     

Page 1 of 1 (5 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.