Method Community

 

Time Zone Problem

Last post 08-27-2010 8:52 AM by Method_Victor. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 11-04-2009 8:36 AM

    • Matt
    • Top 10 Contributor
    • Joined on 11-03-2008
    • Posts 877

    Time Zone Problem

     I am using the API Insert/Update to insert the duedatestart(activity table) field. In order to get the time portion to be correct, I need to adjust for the difference in time zones. That worked fine until the time changed this past weekend. Now everything that gets updated is an hour off. Any suggestions on the best way to handle this?


    Matt Raiser

    Founder,



    www.techinthefield.com

    matt@techinthefield.com

    219-221-9500



    ~ Method user / partner since 2008

    ~ Over 15 years field service experience

    ~ 2013 Method Partner of the Year

    ~ Degree in Computer Science





    Creator of:


        


  • 11-09-2009 3:51 PM In reply to

    Re: Time Zone Problem

     Matt,

    How are you adjusting for the time zone? Are you converting the date to UTC time or just adjusting the time?

    If you can send some sample code of how you are generating the date that would be helpfull.

    Peter

  • 11-09-2009 4:05 PM In reply to

    • Matt
    • Top 10 Contributor
    • Joined on 11-03-2008
    • Posts 877

    Re: Time Zone Problem

    Peter,

    Here is the code I am using to convert the time:

    Dim d As Integer
            Dim mo As Integer
            Dim yr As Integer
            Dim hr As Integer
            Dim min As Integer
            Dim sec As Integer
            Dim mil As Integer


            Dim OldDateTime As Date
            OldDateTime = sInput
            d = OldDateTime.Day
            mo = OldDateTime.Month
            yr = OldDateTime.Year
            hr = OldDateTime.Hour + txtTimeAdjust.Text
            If hr > 23 Then
                hr = hr - 24
            End If
            min = OldDateTime.Minute
            sec = OldDateTime.Second
            mil = OldDateTime.Millisecond
            fnTimeZone = mo & "/" & d & "/" & yr & " " & hr & ":" & min & ":" & sec

    the txtTimeAdjust is an integer based on the time zone


                    If comboTimeZone.SelectedItem = "Eastern" Then
                        Form2.txtTimeAdjust.Text = "5"
                    End If
                    If comboTimeZone.SelectedItem = "Central" Then
                        Form2.txtTimeAdjust.Text = "6"
                    End If
                    If comboTimeZone.SelectedItem = "Mountain" Then
                        Form2.txtTimeAdjust.Text = "7"
                    End If
                    If comboTimeZone.SelectedItem = "Pacific" Then
                        Form2.txtTimeAdjust.Text = "8"
                    End If

    I had to add 1 to each of these the day after the time change to have the times be correct. Items that I transferred before the daylight savings switch are all now 1 hour earlier. If there is a better way, please let me know.


    Matt Raiser

    Founder,



    www.techinthefield.com

    matt@techinthefield.com

    219-221-9500



    ~ Method user / partner since 2008

    ~ Over 15 years field service experience

    ~ 2013 Method Partner of the Year

    ~ Degree in Computer Science





    Creator of:


        


  • 11-11-2009 8:27 AM In reply to

    Re: Time Zone Problem

     Matt,

    That's the way Method saves information as well. We find the Time Zone from the user's browser and then add 60 if there must be an adjustment based for daylight savings time.

    Peter

  • 11-23-2009 7:25 AM In reply to

    • Matt
    • Top 10 Contributor
    • Joined on 11-03-2008
    • Posts 877

    Re: Time Zone Problem

     Peter,

    How does Method account for daylight saving when displaying the information back? I have quite a few jobs that were transferred with a start date of Jan 1, 1980 12:00 am. Now in QXO I have a  bunch of jobs with the due date start of Dec 31, 1979 11:00 pm. It is possible that those jobs were transferred in the day or 2 before I corrected the problem, but it looked like there was too many.

    My concern is that if the is a 5 hour time difference when I transfer the data and then 6 months later the time changes... is the time still going to show correctly?


    Matt Raiser

    Founder,



    www.techinthefield.com

    matt@techinthefield.com

    219-221-9500



    ~ Method user / partner since 2008

    ~ Over 15 years field service experience

    ~ 2013 Method Partner of the Year

    ~ Degree in Computer Science





    Creator of:


        


  • 12-01-2009 10:36 AM In reply to

    Re: Time Zone Problem

    Matt,

    All date/time values are stored in the database as UTC time. When a user logs into Method, the user's local time zone is determined as well as if Daylight Savings Time is currently in affect from the browser on the computer.  The offset amount, in minutes, is used on each screen.

    This offset amount adjust the UTC time stored in the database to the local time whenever you show the information in a grid or a field on the screen.  So the time changes will be shown properly when DST shifts.

    Now I went through some example trying to set values in the past through the API. I was using VB.net. If I set the time to July (7/1/1980 00:00:00) and then convert to UTC, the time showed correctly in Method. If I did the same for January (1/1/1980 00:00:00), the UTC time was off by one hour. I checked the database and the UTC time was off by one hour for January.  So it appears .NET is performing a DST offset automatically when calculating the UTC time. 

    So when creating the time in the past, you may have to make the adjustments before sending the information to the API.

    If you need to query the information from the database, use the MethodAPISelect_XML and you'll see the UTC record for date/time fields.

    If there is anything else I can help you with/clarify please let me know.

    Peter

  • 08-25-2010 12:21 PM In reply to

    • seny
    • Top 150 Contributor
    • Joined on 07-15-2010
    • Posts 32

    Re: Time Zone Problem

    When I insert into a date time field using the API, I am passing the UTC time, and in Method itself it displays the right time. However, when I use MethodAPISelect_DataSetV2 to get the time back, there is a 5-hour difference. For example, in Method it displays Aug 25 2010 10:09 AM and in my own application it displays Aug 25 2010 03:09 PM. Our time zone is (UTC-08:00) Pacific Time (US & Canada). Should the difference be 8 hours, instead of 5 hours? Or since it is daylight saving time, should it be 7 hours?

    I have not tested the MethodAPISelect_XML yet, but I like using MethodAPISelect_DataSetV2 more than the XML version, as I can just pass the dataset from the MethodAPISelect_DataSetV2 to my GridView, where for the XML version I have to do extra work.

    Is that possible to make the MethodAPISelect_DataSetV2 return the UTC time?

    Thanks

     

  • 08-27-2010 8:52 AM In reply to

    Re: Time Zone Problem

    Hi Seny,

    We've looked into the problem of MethodAPISelect_DataSetV2 returning date in the incorrect timezone, we've applied a fix, and now, the DataSets are always going to be returned in UTC time. If at any point you would prefer to use MethodAPISelect_XMLV2, you will be happy to find out that it also returns dates in UTC time.

    Thank you
    Victor

Page 1 of 1 (8 items)