Handling Different Timezones

rated by 0 users
This post has 11 Replies | 3 Followers

Top 150 Contributor
Points 1,874
aaronglover Posted: 06-05-2008 11:32 AM

Hi,

If I have a Server/Client application which uses WinSchedule & UltraDayView and it is operated in two different timezones.....  how can I ignore the timezones???

 

Eg:    Server Timezone = UTC +5 hours
         Client #1 Timezone = UTC +5 hours
         Client #2 Timezone = UTC +6 hours

When Client #1 makes an appointment at 8AM....it appears on Client#2 to be at 9AM. Obviously the appointments start/end time is relative to each Client computer..... but how can I stop this happening....

If they make an appointment at 8 at one location then I want it to appear at 8 at all locations REGARDLESS of timezone settings on thier computer?

Unfortunately.... unlike the "UltraWebInfo"  there does not seem to be a TimezoneOffset setting.

Any ideas?

regards
Aaron

 

 

Top 10 Contributor
Points 63,257
Infragistics Employee

See UltraCalendarInfo.DataBindingsForAppointments.DateMembersSerializationMode

  • | Post Points: 20
Top 150 Contributor
Points 1,874

Thanks for your previous post Brian.

I am having a massive problem though... :(

First some background
  • I am using .NET Remoting (similar to webservices and problem exists in webservices too)
  • I am remoting ADO.NET Datasets from a Server to a client
  • Server Exists in TimeZone +9
  • Client Exists in TimeZone +10 

The Problem although it is not an exactly an Infragistics Issue... it is a very relevant problem for users of your controls (the scheduling controls)

The Problem

When you pass an object of the DataSet class to a remote Web service or to a Web service that is in a time zone that is different from the time zone of the calling application, the DateTime columns in a contained table are converted to the equivalent local time. The DateTime columns are converted because the System.Data.DataSet code adjusts to the equivalent local time according to the time zone of the remote computer. For example, if a value of 5:00 is passed from a client computer in Pacific Time to a Web service in Eastern Time, the value in the DataSet object changes to 8:00 in the receiving method of the Web service. This article describes how to work around this problem by passing the time zone information from the client application to the Web service and by adjusting the DateTime columns at the remote computer. The System.Data is the namespace that contains the DataSet class.

 
The Following article from Microsoft explains this in detail including a workaround. But I have READ and READ and READ this article but still don't know how to implement the workaround.

http://support.microsoft.com/default.aspx?scid=kb;en-us;842545

Unfortunately simply doing the following didn't help me :-(

[quote user="[Infragistics] Brian Fallon"]See UltraCalendarInfo.DataBindingsForAppointments.DateMembersSerializationMode[/quote]

It seems to be default behaviour anyway. and doing a DateSerializationMode.SerializeDatesAsUniversalTime seemed to screw up the appointments completely.

Somewhere in your library of code... do you have an implementation of a workaround that will solve my problem?

Consider my environment as such

Database --> .NET Remoting --> {{{{{INTERNET}}}}}}} --> Client

The Dataset is created on the SERVER.... NOT on the client as the microsoft article seems to demonstrate.

Any help/advice is greatly appreciated!!!!!!!!!!!!!!!!!

 

Regards

Aaron

Top 10 Contributor
Points 63,257
Infragistics Employee

The general solution to this problem is to use the DateTimeKind functionality that was added with CLR2.0. Since you are pushing these DataSets out from the server, and thus have control over that data, you can make sure that all DateTime structs contained therein are marked as being expressed as universal time, i.e., the DateTimeKind is set to 'Utc'. One of the DateTime constructors takes this enumeration as a parameter, so instead of making the server data specific to a particular time zone, make it use universal time for all dates, and push the responsibility of converting those dates to local time down to the client. You would then want to use universal time for the WinSchedule date serialization as well.

  • | Post Points: 20
Top 150 Contributor
Points 1,874

 Hi Brian,

 The solution *I THINK* was to do the following

Dim dt As DataTable = New DataTable

      ...
      ...
      ...

For Each col As DataColumn In dt.Columns         
    If col.DataType Is GetType(System.DateTime) Then
         col.DateTimeMode = DataSetDateTime.Unspecified
    End If
Next

Each time I create a datatable on the server... run through the following code and set each datacolumn DATETIMEMODE that has a datatype of DateTime to "UNSPECIFIED"

DateTimeMode

As intellisense shows.... When using this mode 'Serialization in this mode does not cause an offset"

 

In the Calinfo.DataBindingsForAppointments I left the DateSerializationMode = LocalTime and it all seems to work perfectly....

 

Is there anything wrong with what I have done?

 

Regards
Aaron

  • | Post Points: 35
Top 10 Contributor
Points 63,257
Infragistics Employee

That is basically what I was talking about - prevent the server from marking the dates as local. Leaving DateSerializationMode at local also sounds correct, since that will prevent us from trying to convert it. That property predates the CLR2.0 support that was added to rectify confusion over local/universal time, so we don't convert to local time as the name might suggest in the more modern context. No, I don't see anything wrong with your approach.

Note that I recently had to add a new property, DateMemberDeserialization, to work around an MS bug in the SoapFormatter class whereby a DateTime's status as either a local or universal time is not preserved during the serialization process. This might not affect you but if necessary, you can use this property to prevent WinSchedule from picking up the wrong DateTimeKind as it might because of this bug.

  • | Post Points: 20
Top 150 Contributor
Points 1,874

I still can't believe this issue was fixed so simply... I spent a couple of days scouring the web/msdn/blogs etc for answers solutions.

I did have some question marks about whether the MS Article: http://support.microsoft.com/kb/842545 was still relevent as it says it is for .NET 1.1. However at the same time there is NO good information/articles on what the DateTimeMode Property does so it was relieving to find that this property worked for me.

[quote user="[Infragistics] Brian Fallon"]Note that I recently had to add a new property, DateMemberDeserialization, to work around an MS bug in the SoapFormatter class whereby a DateTime's status as either a local or universal time is not preserved during the serialization process. This might not affect you but if necessary, you can use this property to prevent WinSchedule from picking up the wrong DateTimeKind as it might because of this bug.[/quote]

I am using Binary Serialization over TCP so as you said this won't affect me. But... from reading... this seems to be a common problem for people who are merging datasets/tables. When you merge a Typed Dataset with an untyped dataset for instance... the DateTimeKind setting in the Typed dataset takes precedence. Although this is not the bug you describe... this is just a note for those people who might read this forum later.

Thanks for your help as always Brian... really appreciate it!

Regards
Aaron

  • | Post Points: 5
Not Ranked
Points 230

Hi!!!!!!!!!

I m also having the same problem.When I save my data from one time zone.And then when I fetch saved data from some other time zone.Then it is converted to Local time.I want to prevent it.I want to load the original saved data regardless to the client time zone.Please help me.

I checked ur code to set the DateTimeMode as unspecified.But it is not working correctly.

Also please tell me the use of Calinfo.DataBindingsForAppointments??????????????????

Thanx in advance.

  • | Post Points: 35
Top 150 Contributor
Points 1,874

I don't know why you would still be having these issues.

Here are my subroutines which fix the problem.

    ' Returns an ADO.NET DataSet.
    'Generic GETDATA. Returns Dataset
    Public Function GetDataSet(ByVal szSQL As String) As DataSet

        Try
            Dim sqlConn As SqlConnection = OpenDatabase()
            With sqlConn
                Dim SQLcommand As SqlCommand = New SqlCommand(szSQL, sqlConn)
                Dim adapter As SqlDataAdapter = New SqlDataAdapter(szSQL, sqlConn)
                Dim ds As DataSet = New DataSet
                Try
                    adapter.Fill(ds)
                    CloseDatabase(sqlConn)
                    SetDateColumnsSerializationMode(ds)
                    Return ds
                Catch ex As Exception
                    Return Nothing
                Finally
                    CloseDatabase(sqlConn)
                End Try
            End With
        Catch ex As Exception
            Return Nothing
        End Try

    End Function
 

     Private Overloads Sub SetDateColumnsSerializationMode(ByRef ds As DataSet)
        Try
            If ds IsNot Nothing Then
                For Each dt As DataTable In ds.Tables
                    SetDateColumnsSerializationMode(dt)
                Next
            Else
                Throw New Exception("Passed Dataset = NOTHING. Can't set date columns serialization on columns which do not exist.")
            End If
        Catch ex As Exception
            LogException(Ex)

            Throw Ex
        End Try
    End Sub

    Private Overloads Sub SetDateColumnsSerializationMode(ByRef dt As DataTable)
        Try
            If dt IsNot Nothing Then
                For Each col As DataColumn In dt.Columns
                    If col.DataType Is GetType(System.DateTime) Then
                        col.DateTimeMode = DataSetDateTime.Unspecified
                    End If
                Next
            End If
        Catch ex As Exception
            LogException(ex)
            Throw New Exception("Unable to set Date Column Serialization.  Original Message = " & ex.Message, ex.InnerException)
        End Try
    End Sub

 

So as you can see... In my generic GetData routine... before the function returns the dataset it sets the DateTimeMode for each DateTime column in the dataset/datatable.

Copy and paste and see how you go.

 

As for your other question about how to use the DataBindingsForAppointments you should open up a NEW Thread, but before you do that have a quick search in the forum for posts that already exist relating to this very question and/or refer to the Database Demo and Documentation.

 

Regards
Aaron

  • | Post Points: 20
Top 10 Contributor
Points 63,257
Infragistics Employee

Chetna:
Also please tell me the use of Calinfo.DataBindingsForAppointments??????????????????

See 'WinSchedule Database Demo' sample

  • | Post Points: 20
Not Ranked
Points 230

Thanks Aaron .

This solved my problem.

Thanks a lot.I spent many hours over this issue.Now with ur help I solved it.

Thanks again.

  • | Post Points: 5
Not Ranked
Points 230

Thanks Brian. :)

  • | Post Points: 5
Page 1 of 1 (12 items) | RSS