2 different time zones

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    2 different time zones

    I have 4 sites sharing an account on a server that is in the US Eastern
    time zone. 3 of those sites are for businesses/persons who live in the
    same time zone, but one is for a restaurant in the US Pacific time zone.

    For that site, I want to generate content via a script depending on the
    local Pacific time and day of week. The content will change at the same
    time every day: one page before 5:00am local time, a different page from
    5am until 10pm, then back to the first page after 10pm. The script
    should also generate appropriate last modified and expires headers. It'd
    be nice if this script were portable, in case I change hosting companies
    and wind up with a host in European time, or US central time, or what
    have you.

    At the moment, my script gets the local time of the server (US ET),
    converts it to UT with date("Z"), then converts it again to Pacific time:

    $utTimeStamp = time() - date("Z");
    $daylightSaving sTime = date("I");
    $PT = $utTimeStamp - (8*3600) + ($daylightSavin gsTime*3600);

    That's fine for the current time, but trying to work out expires times
    seems rather complicated, and I'm having a hard time getting everything
    to work. Is there an easier way to accomplish my tasks? Should I give up
    some portability and simply convert from one local time to another?

    --
    Brian (remove "invalid" to email me)

  • Alvaro G. Vicario

    #2
    Re: 2 different time zones

    *** Brian escribió/wrote (Wed, 29 Sep 2004 20:54:26 GMT):[color=blue]
    > I have 4 sites sharing an account on a server that is in the US Eastern
    > time zone. 3 of those sites are for businesses/persons who live in the
    > same time zone, but one is for a restaurant in the US Pacific time zone.[/color]

    I believe this task is usually solved using GMT internally for all dates
    and doing conversion to client time zone when printing. You have some
    functions to work with Greenwich time:

    gmdate - Format a GMT/UTC date/time
    gmmktime - Get UNIX timestamp for a GMT date
    gmstrftime - Format a GMT/UTC time/date according to locale settings


    --
    -+ Álvaro G. Vicario - Burgos, Spain
    +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
    ++ Las dudas informáticas recibidas por correo irán directas a la papelera
    -+ I'm not a free help desk, please don't e-mail me your questions
    --

    Comment

    • Pedro Graca

      #3
      Re: 2 different time zones

      Brian wrote:
      [snip][color=blue]
      > $utTimeStamp = time() - date("Z");
      > $daylightSaving sTime = date("I");
      > $PT = $utTimeStamp - (8*3600) + ($daylightSavin gsTime*3600);
      >
      > That's fine for the current time, but trying to work out expires times
      > seems rather complicated, and I'm having a hard time getting everything
      > to work. Is there an easier way to accomplish my tasks? Should I give up
      > some portability and simply convert from one local time to another?[/color]

      Use gmdate() for expiry headers

      // expire in half an hour (wherever you are)
      header('Expires : ' . gmdate('r', time()+1800));
      --
      USENET would be a better place if everybody read: | to email me: use |
      http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
      http://www.netmeister.org/news/learn2quote2.html | header, textonly |
      http://www.expita.com/nomime.html | no attachments. |

      Comment

      • Brian

        #4
        Re: 2 different time zones

        Pedro Graca wrote:[color=blue]
        > Brian wrote: [snip]
        >[color=green]
        >> trying to work out expires times seems rather complicated[/color]
        >
        > Use gmdate() for expiry headers
        >
        > // expire in half an hour (wherever you are)
        > header('Expires : ' . gmdate('r', time()+1800));[/color]

        That would work if the document didn't have a hard expires time, though
        in that case, a cache-control header would be more straight-forward:
        header('Cache-Control: max-age=1800');

        But the document expires according to the time of day US Pacific time.
        The page will show the dinner special. Since the kitchen closes at 10:00
        pm each night, the page showing that day's special expires at 10:00pm or
        22:00 each day. If someone views the page at 21:59, it is fresh for only
        1 minute. If they view it at 06:00 (6am), it is fresh for 14 hours.

        I need to get the time of day in Seattle using the server's clock, which
        is set to US eastern time. Then I need to create a date formatted for an
        http header, based on the current date, but using a hard time. For
        example, if I were to view the page at the time I write this article --
        Thursday, 30 September 2004 at 12:59pm US PDT -- the page should show
        Thursday's dinner special, and the expires header should be

        Expires: Thu, 30 Sep 2004 22:00:00 GMT

        --
        Brian (remove "invalid" to email me)

        Comment

        • Brian

          #5
          Re: 2 different time zones

          Alvaro G. Vicario wrote:[color=blue]
          > *** Brian escribió/wrote (Wed, 29 Sep 2004 20:54:26 GMT):
          >[color=green]
          >> I have 4 sites sharing an account on a server that is in the US
          >> Eastern time zone. 3 of those sites are for businesses/persons who
          >> live in the same time zone, but one is for a restaurant in the US
          >> Pacific time zone.[/color]
          >
          >
          > I believe this task is usually solved using GMT internally for all
          > dates and doing conversion to client time zone when printing. You
          > have some functions to work with Greenwich time:
          >
          > gmdate - Format a GMT/UTC date/time
          > gmmktime - Get UNIX timestamp for a GMT date
          > gmstrftime - Format a GMT/UTC time/date according to locale settings[/color]

          The documentation for gm* date functions on php.net is not terribly
          clear to me. gmmktime gets a unix timestampe for a GMT date, but I need
          to determine what to do based on a local time zone, and account for
          daylight savings. That's complicated by the fact that the server's
          localtime is not the restaurant's local time. I need to set an expires
          header based on the local time of the restaurant, but the time must be
          expressed in GMT. 2 examples:

          1. if it's between 05:00 and 22:00 US PT, the page should insert that
          day's dinner special, and the expires header should be set to 22:00
          local time. Since US PT is currently in daylight savings (GMT -0700),
          that means that for today, Thursday 30 September 2004, it should be

          Expires: Fri, 01 Oct 2004 05:00:00 GMT


          2. if it's after 22:00, the page should not show the special, and the
          page should expire the next day at 05:00. The expires header should thus be

          Expires: Fri, 01 Oct 2004 12:00:00 GMT

          What I find difficult is doing date calculations, while at the same time
          having to hardcode the time. For example 2, I'm trying to determine the
          current date, change it to tomorrow, and create a unix time stamp based
          on tomorrow at 05:00.

          I started this thread to see if I'm making this too complicated -- I
          suspect that I am -- and determine if there's an easier way to work in
          US PT or GMT.

          --
          Brian (remove "invalid" to email me)

          Comment

          Working...