SmartDate and Time Zones

SmartDate and Time Zones

Old forum URL: forums.lhotka.net/forums/t/3140.aspx


Mozts2007 posted on Wednesday, July 04, 2007

I have a Project that we need to keep track of time zones. I have the idea of adding the concept to SmartDate. So that when you call  mMySmartdate. DBvalue it gives you the value in GMT/UTC and then when you load the SmartDate it will use the time zone of you system. Does anyone have  any ideas on how to best do this? Or if it would work .

 

Thanks,

Mozts   

JoOfMetL replied on Thursday, July 05, 2007

For my part, all the dates which I use are universal dates.
My objects and the data base store universal dates.
But I want that the users use local dates.
Therefore, I use two functions.

public DateTime MyDate {
       get { return ToLocalTime (_myDate); }
       set { _myDate = ToUniversaTime (value); }
}

ajj3085 replied on Thursday, July 05, 2007

I did something similar, but I hide this detail in my data layer.

JoOfMetL replied on Thursday, July 05, 2007

It was my first idea.
The business object contains the local date and the dates are stored in universal date in the data base. (the translation is done when the object is loaded or saved)
But if the objects are loaded on the server, the dates will be local at the server and not at the customer machine.
So I finally adopted the solution that I proposed above.

ajj3085 replied on Thursday, July 05, 2007

Actually doesn't Csla set the Locale properly based on client settings?  I'm pretty sure it will... unless you're talking about a web server, although I'd think you'd be able to properly set the locale of the session, which should get moved to the data portal... or is that not how it works?

JoOfMetL replied on Friday, July 06, 2007

I takes the example of a Win32 application which uses WebService to reach the data on a server.
The objects are loaded on the server, therefore if GetLocalTime is made during the loading of the data, the date will be local at the server.

I makes an error?

Mozts2007 replied on Saturday, July 07, 2007

Thanks for your help guys

It sounds like if I need it to work for both windows apps and web apps I need to add the code in my properties not my data access layer.

 

Some thing like:

  Dim mStartdate As SmartDate

    Public Property Startdate() As String

        Get

            Return mstart.Date.ToLocalTime.ToString

        End Get

        Set(ByVal value As String)

            If mstart.Date.ToLocalTime.ToString <> value Then

                mstart.Date = Date.Parse(value).ToUniversalTime

            End If

        End Set

   End Property

Copyright (c) Marimer LLC