Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25054

Re: Confusing datetime.datetime

From Damjan <gdamjan@gmail.com>
Subject Re: Confusing datetime.datetime
Date 2012-07-08 23:49 +0200
References <jt4766$og9$1@dough.gmane.org> <mailman.1843.1341528901.4697.python-list@python.org> <4ff71557$0$6974$e4fe514c@news2.news.xs4all.nl>
Newsgroups comp.lang.python
Message-ID <mailman.1928.1341784133.4697.python-list@python.org> (permalink)

Show all headers | View raw


> Because x1 and x2 have different time zones.
>
> The tzinfo field in x2 is equal to TZ and has a UTC offset of 1 hour.
> The tzinfo field in x1 contains the DST version of that timezone,
> with a UTC offset of 2 hours, because Skopje is currently on DST.
>
> I think you want:
>
> x2 = TZ.localize(datetime(x1.year, x1.month, x1.day))
>
> That produces a datetime with the year, month and day set as indicated
> and tzinfo set to the correct UTC offset for that date, at 00:00 hours.
>
> Or maybe you need:
>
> x2 = TZ.localize(datetime(x1.year, x1.month, x1.day, 12))
> x2 = x2.replace(hour=0)
>
> That determines whether DST should be on at noon, and then resets the
> hour field to zero.  This produces the same outcome as the one liner,
> except on days when DST is switched on or off.


Thanks, I think this will help me.

Although these issues seem very much underdocumented in the datetime 
documentation. Are there any good references of using good times in Python?



-- 
damjan

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Confusing datetime.datetime Damjan <gdamjan@gmail.com> - 2012-07-06 00:55 +0200
  Re: Confusing datetime.datetime Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-06 01:28 +0000
    Re: Confusing datetime.datetime Damjan <gdamjan@gmail.com> - 2012-07-06 04:05 +0200
  Re: Confusing datetime.datetime Hans Mulder <hansmu@xs4all.nl> - 2012-07-06 18:41 +0200
    Re: Confusing datetime.datetime Damjan <gdamjan@gmail.com> - 2012-07-08 23:49 +0200

csiph-web