Fractional Hours from datetime?

W

W. eWatson

Maybe there's a more elegant way to do this. I want to express the
result of datetime.datetime.now() in fractional hours.

Here's one way.

dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
# now is in fractions of an hour
 
A

Austyn

How about:

import time
arizona_utc_offset = -7.00
h = (time.time() / 3600 + arizona_utc_offset) % 24

dt.timetuple()[6] is the day of the week; struct tm_time doesn't
include a sub-second field.
 
A

Austyn

Here's an improvement in case you want your code to work outside of
Arizona:

from time import time, timezone
h = ((time() - timezone) / 3600) % 24

How about:

import time
arizona_utc_offset = -7.00
h = (time.time() / 3600 + arizona_utc_offset) % 24

dt.timetuple()[6] is the day of the week; struct tm_time doesn't
include a sub-second field.

Maybe there's a more elegant way to do this. I want to express the
result of datetime.datetime.now() in fractional hours.
Here's one way.
dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
#  now is in fractions of an hour
 
M

Martin P. Hellwig

W. eWatson said:
Maybe there's a more elegant way to do this. I want to express the
result of datetime.datetime.now() in fractional hours.

Here's one way.

dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
# now is in fractions of an hour

Here is another (though personally I don't find this more elegant than
yours, perhaps a bit more readable):
/ 60.0
 
M

Martin P. Hellwig

Martin said:
W. eWatson said:
Maybe there's a more elegant way to do this. I want to express the
result of datetime.datetime.now() in fractional hours.

Here's one way.

dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
# now is in fractions of an hour

Here is another (though personally I don't find this more elegant than
yours, perhaps a bit more readable):
/ 60.0
Actually my version is overcomplicated:
 
W

W. eWatson

Austyn said:
Here's an improvement in case you want your code to work outside of
Arizona:

from time import time, timezone
h = ((time() - timezone) / 3600) % 24

How about:

import time
arizona_utc_offset = -7.00
h = (time.time() / 3600 + arizona_utc_offset) % 24

dt.timetuple()[6] is the day of the week; struct tm_time doesn't
include a sub-second field.

Maybe there's a more elegant way to do this. I want to express the
result of datetime.datetime.now() in fractional hours.
Here's one way.
dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
# now is in fractions of an hour
There seems to be some controversy about this and other matters of
datetime.
<http://blog.twinapex.fi/2008/06/30/...ortcomings-in-python-datetime-and-workaround/>
 
W

W. eWatson

Martin said:
Martin said:
W. eWatson said:
Maybe there's a more elegant way to do this. I want to express the
result of datetime.datetime.now() in fractional hours.

Here's one way.

dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
# now is in fractions of an hour

Here is another (though personally I don't find this more elegant than
yours, perhaps a bit more readable):
now = datetime.datetime.now()
fractional_hour = int(now.strftime('%H')) +
int(now.strftime('%M')) / 60.0
Actually my version is overcomplicated:
See my post about the datetime controversy about 3-4 posts up from yours.
 
W

W. eWatson

Martin said:
Martin said:
W. eWatson said:
Maybe there's a more elegant way to do this. I want to express the
result of datetime.datetime.now() in fractional hours.

Here's one way.

dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
# now is in fractions of an hour

Here is another (though personally I don't find this more elegant than
yours, perhaps a bit more readable):
now = datetime.datetime.now()
fractional_hour = int(now.strftime('%H')) +
int(now.strftime('%M')) / 60.0
Actually my version is overcomplicated:
See my post about the datetime controversy about 3-4 posts up from yours.
 
W

W. eWatson

A

Alf P. Steinbach

* W. eWatson:
Sort of like outer space I guess. No real direction. How would I find
the message ID?

In Thunderbird (the newsreader that you're using) there's a little '+' to the
left of the message subject line.

That shows the headers.

You can alternatively use [View -> Message Source], or keyboard [Ctrl U].

From that you find that the message id is

[email protected]

Then, kicking and cajoling your web browser to turn in the direction of Google
Groups' Usenet archive,

groups.google.com

you click the "Advanced search" button, paste the message id, and find that
Google is unable to find your article, he he.

It's common, it's a very very unreliable archive.

However, as with most things, the "Great Wall of Google" prevents you from
reporting this. There's no known way to report any bug to Google. As with
Microsoft in the old days (reportedly Microsoft employees weren't even allowed
to use the words "bug" or "error" with customers, only, at worst, "problems"),
there are Google web forms and whatnot, but they all end up in cul-de-sacs, so
that, together with the total impossibility of reaching any human at Google, one
very very strongly suspects that it's Google *policy* to never admit to bugs, or
waste time on fixing them. And so, I suspect, Google Earth still places Norway
in the middle of Sweden, and I know for a fact that Google Groups still actively
removes the space at the end of a valid signature delimiter, and Google Talk
acts up in various ways, and so on: quite serious bugs, but no way to report
them (thousands upon thousands have tried, at one time a movement was founded
with its own web site, but the "Great Wall of Google" lets no-one through).

And considering this, and the fact that Google's archive is now the main Usenet
archive, message id's are not that useful, really.

So asking for a Usenet article's message id is just showing off -- that one is
not up-to-date on current technology (it gets more unreliable year by year).

It's easier to place the comment here:

There seems to be some controversy about this and other matters of
datetime.
<http://blog.twinapex.fi/2008/06/30/...ortcomings-in-python-datetime-and-workaround/>

No, not at all. :)

Instead, just ignore silly requests for message id's.


Cheers & hth.,

- Alf
 
S

Steve Holden

Alf said:
* W. eWatson:

In Thunderbird (the newsreader that you're using) there's a little '+'
to the left of the message subject line.

That shows the headers.
It shows a very limited subset of the headers ...

regards
Steve
 
D

David Robinow

You've demonstrated only that Google is an unreliable Usenet archive.

One doesn't even need to use Usenet, in this case, since
comp.lang.python is a forum distributed both as a Usenet forum and a
mailing-list forum.

--
 \       “Two possibilities exist: Either we are alone in the Universe |
 `\   or we are not. Both are equally terrifying.” —Arthur C. Clarke, |
_o__)                                                             1999 |
Ben Finney
The archive at http://mail.python.org/pipermail/python-list/ doesn't
show the message id either.
However, the monthly gzip'ed text file does have them.

FWIW, for you google-haters, I read python-list using gmail and I
don't see any message id's.
Great spam detection though.
 
A

Alf P. Steinbach

* Steve Holden:
It shows a very limited subset of the headers ...

Really? My Thunderbird shows all headers. Perhaps you need to configure something.

Or do as I wrote next and you snipped, use [View -> Message Source].


Cheers & hth. (even if rather off-topic by now, not even direct response!),

- Alf
 
S

Steve Holden

Alf said:
* Steve Holden:

Really? My Thunderbird shows all headers. Perhaps you need to configure
something.
I don't need to configure anything, thank you very much, it's already
configured perfectly nicely as it is, thank you, toView | Headers | Normal.

I agree I can switch to View | Headers | All, but for the typical modern
newsgroup post this reveals a bug in Thunderbird, because the headers
view isn't scrollable: not only can you not see all the headers, but
none of the message is visible either!
Or do as I wrote next and you snipped, use [View -> Message Source].
Yup, when I need to see that crap (which is almost never) I just hit
Ctrl/U and look at the headers in the message source.
Cheers & hth. (even if rather off-topic by now, not even direct response!),
I've sucked a few eggs in my time. Thanks.

regards
Steve
 
M

Martin P. Hellwig

W. eWatson wrote:
See my post about the datetime controversy about 3-4 posts up from yours.

If timezones might be a problem area, than it might be worth while to
see it in the context of the actual application. For local, one user
only, use, the problem will be practically non-existent. Multiple users
across multiple machines will make it more difficult since you need a
verified source for each users timezone. But then again what about
travellers, wrongly set-up machines (right time wrong zone, wrong time
right zone and wrong zone with wrong time?) or people who just prefer to
do have their time set to UTC regardless of their location and season
(when I travelled alot, I just set my wristwatch, phone and laptop to UTC).
 
W

W. eWatson

Ben said:
You've demonstrated only that Google is an unreliable Usenet archive.

One doesn't even need to use Usenet, in this case, since
comp.lang.python is a forum distributed both as a Usenet forum and a
mailing-list forum.
Good Clarke quote. (Not present here.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,511
Latest member
svareza

Latest Threads

Top