Doing date/time + TZ math in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joshua J. Kugler

    Doing date/time + TZ math in python

    I've read docs (datetime, time, pytz, mx.DateTime), googled, and
    experimented. I still don't know how to accomplish what I want to
    accomplish.

    I'm loading up a bunch of date/time data that I then need to do math on to
    compare it to the current date/time. I can get the current time easily
    enough:

    currentTime = datetime.dateti me.now(pytz.tim ezone('America/Anchorage'))

    Then, I want to import data/time pairs that are in "%Y-%m-%d %H:%M:%S"
    format.

    So, I do:

    For each loop, extract time data, blah, blah, then:
    readingTime = datetime.dateti me(rYr, rMo, rDay, rHr, rMin, rSec,
    tzinfo=pytz.tim ezone('America/Anchorage'))

    The problem is, how do I create a datetime object and tell it that it's
    America/Anchorage *daylight savings time* instead of whatever the system is
    currently set at? pytz only has America/Anchorage, and I saw no way to
    tell it explicitly that the timezone is in Daylight instead of Standard
    time (e.g. using AKST vs. AKDT for the time zone).

    I'm sure there is a way to do it, and I'm sure it's quite simple, but it
    hasn't jumped out at me yet. Is there a module that I haven't seen that
    would be better suited for this?

    Thanks!

    j

    --
    Joshua Kugler
    Lead System Admin -- Senior Programmer

    PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

    --
    Posted via a free Usenet account from http://www.teranews.com

  • wittempj@hotmail.com

    #2
    Re: Doing date/time + TZ math in python


    Joshua J. Kugler wrote:
    I've read docs (datetime, time, pytz, mx.DateTime), googled, and
    experimented. I still don't know how to accomplish what I want to
    accomplish.
    >
    I'm loading up a bunch of date/time data that I then need to do math on to
    compare it to the current date/time. I can get the current time easily
    enough:
    >
    currentTime = datetime.dateti me.now(pytz.tim ezone('America/Anchorage'))
    >
    Then, I want to import data/time pairs that are in "%Y-%m-%d %H:%M:%S"
    format.
    >
    So, I do:
    >
    For each loop, extract time data, blah, blah, then:
    readingTime = datetime.dateti me(rYr, rMo, rDay, rHr, rMin, rSec,
    tzinfo=pytz.tim ezone('America/Anchorage'))
    >
    The problem is, how do I create a datetime object and tell it that it's
    America/Anchorage *daylight savings time* instead of whatever the system is
    currently set at? pytz only has America/Anchorage, and I saw no way to
    tell it explicitly that the timezone is in Daylight instead of Standard
    time (e.g. using AKST vs. AKDT for the time zone).
    >
    I'm sure there is a way to do it, and I'm sure it's quite simple, but it
    hasn't jumped out at me yet. Is there a module that I haven't seen that
    would be better suited for this?
    >
    Thanks!
    >
    j
    >
    --
    Joshua Kugler
    Lead System Admin -- Senior Programmer

    PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE
    >
    --
    Posted via a free Usenet account from http://www.teranews.com
    It looks like3 you're 9 hours in this example:
    http://docs.python.org/lib/datetime-tzinfo.html, see e.g.
    World Time Zones map and current time around the world and countries operating Daylight Savings Time sunclock map shows what part of the world is in darkness and what part is in daylight detailed time zone maps of the USA time Europe time Australia time Canada time Middle-East time Oceania time Russia time zone Interactive Time Map for 29th Winter Universiade 2019 opening ceremony will be held on March 2 2019 in Krasnoyarsk Russia Siberia date and time in relation to other locations around the world


    Comment

    • Joshua J. Kugler

      #3
      Re: Doing date/time + TZ math in python

      wittempj@hotmai l.com wrote:
      >The problem is, how do I create a datetime object and tell it that it's
      >America/Anchorage *daylight savings time* instead of whatever the system
      >is
      >currently set at? pytz only has America/Anchorage, and I saw no way to
      >tell it explicitly that the timezone is in Daylight instead of Standard
      >time (e.g. using AKST vs. AKDT for the time zone).
      >>
      >I'm sure there is a way to do it, and I'm sure it's quite simple, but it
      >hasn't jumped out at me yet. Is there a module that I haven't seen that
      >would be better suited for this?
      >
      It looks like3 you're 9 hours in this example:
      http://docs.python.org/lib/datetime-tzinfo.html, see e.g.
      http://www.worldtimezone.com/index12.php
      Right, I know I'm at GMT-9, and tzinfo correctly deduces that when it
      creates an object. But what if I were currently at GMT-8 (my time zone on
      daylight savings time) and I was importing data created during standard
      time? How would I create an object and tell it this is America/Anchorage
      on standard time, or conversely, how would I right now create and object
      and tell it to use daylight time? In other words, how can I explicitly
      specify whether or not the time object being created is daylight savings
      time or not? I did not see that option in the documentation reading I did.

      Thanks!

      j

      --
      Joshua Kugler
      Lead System Admin -- Senior Programmer

      PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

      --
      Posted via a free Usenet account from http://www.teranews.com

      Comment

      Working...