DST & getTimezoneOffset()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bobkolk@gmail.com

    DST & getTimezoneOffset()

    I'm writing a backend web app for a company that only has locations in
    the US. Why can't I, at login, pull their getTimezoneOffs et() using
    javascript, cookie it, then when I need to show a local time compute
    the difference in their value in the cookie vs. my server's value?

    I've seen a million articles about factoring in DST, but when my server
    (which is in PA) switches to DST won't the difference value remain the
    same since everyone rolls into DST on the same date?

    For example, in June the server offset is 4 and in California the
    offset is 7. But in December the server is at 5 and California it's 8.
    So it's always a difference of 3. No?

  • ZeldorBlat

    #2
    Re: DST & getTimezoneOffs et()


    bobkolk@gmail.c om wrote:
    I'm writing a backend web app for a company that only has locations in
    the US. Why can't I, at login, pull their getTimezoneOffs et() using
    javascript, cookie it, then when I need to show a local time compute
    the difference in their value in the cookie vs. my server's value?
    You could do that, but it won't work in all cases (see below).
    >
    I've seen a million articles about factoring in DST, but when my server
    (which is in PA) switches to DST won't the difference value remain the
    same since everyone rolls into DST on the same date?
    No -- because not everyone observes DST.
    >
    For example, in June the server offset is 4 and in California the
    offset is 7. But in December the server is at 5 and California it's 8.
    So it's always a difference of 3. No?
    Your best bet is to figure out what timezone they're actually in then
    use timestamps appropriately when parsing and displaying dates and
    times. Timestamps are in UTC which doesn't have DST. The timezone
    setting of the machine will determine how dates are parsed (via
    strtotime()) and how they are displayed (with date()) and will take
    care of DST for you automatically.

    Here's what you really want to do:

    Call date_default_ti mezone_set() with your home timezone in PA at the
    top of all your pages. This is optional since PHP will take it from
    the server, but recommended nonetheless.

    If you want the current date and time, get the timestamp from the
    time() function.

    Before calling date() to format a date for display, call
    date_default_ti mezone_set() with the user's timezone.

    This will take care of all the converting for you and accomdate DST
    automatically.

    Comment

    • bobkolk@gmail.com

      #3
      Re: DST & getTimezoneOffs et()

      I forgot to mention ... I'm running PHP 4.3.4, so I don't have access
      to date_default_ti mezone_set(). :(
      Before calling date() to format a date for display, call
      date_default_ti mezone_set() with the user's timezone.
      Do I still use javascript to get the user's timezone? If so, how does
      that differ from my original idea? I'm still using the difference
      between my server's timezone and the user's timezone to figure out how
      to adjust the time, no?

      Sorry -- time/date stuff always sends my head spinning.



      ZeldorBlat wrote:
      bobkolk@gmail.c om wrote:
      I'm writing a backend web app for a company that only has locations in
      the US. Why can't I, at login, pull their getTimezoneOffs et() using
      javascript, cookie it, then when I need to show a local time compute
      the difference in their value in the cookie vs. my server's value?
      >
      You could do that, but it won't work in all cases (see below).
      >

      I've seen a million articles about factoring in DST, but when my server
      (which is in PA) switches to DST won't the difference value remain the
      same since everyone rolls into DST on the same date?
      >
      No -- because not everyone observes DST.
      >

      For example, in June the server offset is 4 and in California the
      offset is 7. But in December the server is at 5 and California it's 8.
      So it's always a difference of 3. No?
      >
      Your best bet is to figure out what timezone they're actually in then
      use timestamps appropriately when parsing and displaying dates and
      times. Timestamps are in UTC which doesn't have DST. The timezone
      setting of the machine will determine how dates are parsed (via
      strtotime()) and how they are displayed (with date()) and will take
      care of DST for you automatically.
      >
      Here's what you really want to do:
      >
      Call date_default_ti mezone_set() with your home timezone in PA at the
      top of all your pages. This is optional since PHP will take it from
      the server, but recommended nonetheless.
      >
      If you want the current date and time, get the timestamp from the
      time() function.
      >
      Before calling date() to format a date for display, call
      date_default_ti mezone_set() with the user's timezone.
      >
      This will take care of all the converting for you and accomdate DST
      automatically.

      Comment

      Working...