Affichage des articles dont le libellé est Brain. Afficher tous les articles
Affichage des articles dont le libellé est Brain. Afficher tous les articles

mercredi 29 janvier 2014

Re: UTC "timezone" causing brain explosions topic




On 01/29/2014 01:52 PM, Skip Montanaro wrote:
> Following up on my earlier note about UTC v. GMT, I am having some
> trouble grokking attempts to convert a datetime into UTC.
>
> Okay, let's see what GMT does for us:
>
>>>> GMT = pytz.timezone("GMT")
>>>> u = GMT.normalize(s)
>>>> u

> datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=<StaticTzInfo 'GMT'>)
>>>> u.hour

> 21
>
> That looks correct, but I don't understand why I don't get hour==21
> out of the UTC.normalize call. It's like it's a no-op.


Having not examined the code, I can't tell you why UTC is different. I can say that .astimezone seems to work in all cases:

--> GMT
<StaticTzInfo 'GMT'>

--> UTC
<UTC>

--> LOCAL_TZ = pytz.timezone("America/Los_Angeles")

--> now = datetime.datetime.now()

--> s = LOCAL_TZ.localize(now)
--> s
datetime.datetime(2014, 1, 29, 14, 9, 56, 494967, tzinfo=<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>)

--> s.astimezone(UTC)
datetime.datetime(2014, 1, 29, 22, 9, 56, 494967, tzinfo=<UTC>)

--> s.astimezone(GMT)
datetime.datetime(2014, 1, 29, 22, 9, 56, 494967, tzinfo=<StaticTzInfo 'GMT'>)

--
~Ethan~





Re: UTC "timezone" causing brain explosions topic




On Wed, Jan 29, 2014 at 1:52 PM, Skip Montanaro <(E-Mail Removed)> wrote:
> Following up on my earlier note about UTC v. GMT, I am having some
> trouble grokking attempts to convert a datetime into UTC. Consider
> these three values:
>
>>>> import pytz
>>>> UTC = pytz.timezone("UTC")
>>>> LOCAL_TZ = pytz.timezone("America/Chicago")
>>>> LOCAL_TZ

> <DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>
>>>> now = datetime.datetime.now()
>>>> now

> datetime.datetime(2014, 1, 29, 15, 39, 35, 263666)
>
> All well and good, right? The variable "now" is a naive datetime
> object. I happen to be sitting in a chair in the city of Chicago, so
> let's call it what it is, a datetime in the America/Chicago timezone:
>
>>>> s = LOCAL_TZ.localize(now)
>>>> s

> datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=<DstTzInfo
> 'America/Chicago' CST-1 day, 18:00:00 STD>)
>
> That looks good to me. Now, let's normalize it to UTC:


I don't think .normalize() doesn't do what you think it does; it's
related to timezones with DST.
I believe you want datetime.astimezone() instead.

>>>> t = UTC.normalize(s)
>>>> t

> datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=<UTC>)
>>>> t.hour

> 15
>
> WTF? Why isn't the t.hour == 21?


Because you didn't actually perform a proper timezone conversion:
>>> t = s.astimezone(UTC)
>>> t

datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=<UTC>)
>>> t.hour == 21

True

<snip>
> That looks correct, but I don't understand why I don't get hour==21
> out of the UTC.normalize call. It's like it's a no-op.


It is indeed a no-op:
"You can take shortcuts when dealing with the UTC side of timezone
conversions. normalize() and localize() are not really necessary when
there are no daylight savings time transitions to deal with."
-- http://pytz.sourceforge.net

Cheers,
Chris





UTC "timezone" causing brain explosions topic




Following up on my earlier note about UTC v. GMT, I am having some
trouble grokking attempts to convert a datetime into UTC. Consider
these three values:

>>> import pytz
>>> UTC = pytz.timezone("UTC")
>>> UTC

<UTC>
>>> LOCAL_TZ = pytz.timezone("America/Chicago")
>>> LOCAL_TZ

<DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>
>>> now = datetime.datetime.now()
>>> now

datetime.datetime(2014, 1, 29, 15, 39, 35, 263666)

All well and good, right? The variable "now" is a naive datetime
object. I happen to be sitting in a chair in the city of Chicago, so
let's call it what it is, a datetime in the America/Chicago timezone:

>>> s = LOCAL_TZ.localize(now)
>>> s

datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=<DstTzInfo
'America/Chicago' CST-1 day, 18:00:00 STD>)

That looks good to me. Now, let's normalize it to UTC:

>>> t = UTC.normalize(s)
>>> t

datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=<UTC>)
>>> t.hour

15

WTF? Why isn't the t.hour == 21?

Okay, let's see what GMT does for us:

>>> GMT = pytz.timezone("GMT")
>>> u = GMT.normalize(s)
>>> u

datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=<StaticTzInfo 'GMT'>)
>>> u.hour

21

That looks correct, but I don't understand why I don't get hour==21
out of the UTC.normalize call. It's like it's a no-op.

Skip





mardi 28 janvier 2014

[GAME, puzzle][2.2+] Riddles, Brain Teasers 2. Check your IQ topic




Hi.
Check my new app "Riddles, Brain Teasers 2". This is a continuation of the first part of the game "Riddles, Brain Teasers, Logic" that has more than 1 000 000 downloads. I hope you enjoy new app as older one. What's new in this app:
1. New teasers and riddles
2. Now you can give an answer, not just read it.
3. For each right answer you will get a scores.
4. You will be compete for the title of the most cleverest person

link: https://play.google.com/store/apps/d...rainteasers&hl








Attached Thumbnails


Click image for larger version<br/><br/>Name:	FIVE-CATEG.png<br/>Views:	N/A<br/>Size:	42.8 KB<br/>ID:	2544943
 

Click image for larger version<br/><br/>Name:	EXPLORE.png<br/>Views:	N/A<br/>Size:	55.8 KB<br/>ID:	2544944
 

Click image for larger version<br/><br/>Name:	type-the-answer.png<br/>Views:	N/A<br/>Size:	53.2 KB<br/>ID:	2544945
 

Click image for larger version<br/><br/>Name:	GET-SCORES.png<br/>Views:	N/A<br/>Size:	70.6 KB<br/>ID:	2544946