Re: simpler increment of time values?

2012-07-06 Thread Rick Johnson
On Jul 5, 12:16 pm, Chris Angelico ros...@gmail.com wrote: So it's even easier than I said. And bonus lesson for the day: Try things in the interactive interpreter before you post. :) but first: be sure to familiarize yourself with the many built-in python classes(sic). Re-inventing the wheel

Re: simpler increment of time values?

2012-07-06 Thread Vlastimil Brom
Thanks to all for further comments! Just for completeness and in case somebody would like to provide some suggestions or corrections; the following trivial class should be able to deal with the initial requirement of adding or subtracting dateless time values (hour:minute). regards, vbr # # # #

Re: simpler increment of time values?

2012-07-05 Thread Vlastimil Brom
Many thanks to all for your suggestions! @ChrisA Yes, the calculations with seconds since the Unix epoch is very convenient for real times, but trying to make it dateless seemed to make it more complicated for me. The expected output for the increments asked by Jason was already correctly stated

Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Thu, Jul 5, 2012 at 11:18 PM, Vlastimil Brom vlastimil.b...@gmail.com wrote: Yes, the calculations with seconds since the Unix epoch is very convenient for real times, but trying to make it dateless seemed to make it more complicated for me. The expected output for the increments asked by

Re: simpler increment of time values?

2012-07-05 Thread rurpy
On Wednesday, July 4, 2012 6:29:10 PM UTC-6, Vlastimil Brom wrote: Hi all, I'd like to ask about the possibilities to do some basic manipulation on timestamps - such as incrementing a given time (hour.minute - string) by some minutes. Very basic notion of time is assumed, i.e. dateless,

Re: simpler increment of time values?

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 23:56:37 +1000, Chris Angelico wrote: (The magic number 86400 is a well-known number, being seconds in a day. Does that include leap seconds? Feel free to replace it with 24*60*60 if it makes you feel better; I'm pretty sure Python will translate it into a constant at

Re: simpler increment of time values?

2012-07-05 Thread Rick Johnson
On Jul 5, 10:19 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: The number of seconds in a day (true solar day) varies by between 13 and 30 seconds depending on the time of the year and the position of the sun. Indeed. Which proves that a time keeping system based on the

Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Fri, Jul 6, 2012 at 1:19 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 05 Jul 2012 23:56:37 +1000, Chris Angelico wrote: (The magic number 86400 is a well-known number, being seconds in a day. Does that include leap seconds? No it doesn't, hence... Feel free

Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Fri, Jul 6, 2012 at 1:39 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Jul 5, 10:19 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: The number of seconds in a day (true solar day) varies by between 13 and 30 seconds depending on the time of the year and the

Re: simpler increment of time values?

2012-07-05 Thread Ian Kelly
On Thu, Jul 5, 2012 at 7:56 AM, Chris Angelico ros...@gmail.com wrote: I'm not familiar with the Python classes (I tend to think in terms of language-agnostic algorithms first, and specific libraries/modules/etc second), but if you're working with simple integer seconds, your datelessness is

Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Fri, Jul 6, 2012 at 3:06 AM, Ian Kelly ian.g.ke...@gmail.com wrote: The + 86400 is redundant; you'll get the same answer with or without it. There is nothing to fear from going negative when doing modulo arithmetic, because unlike C, Python actually has well-defined semantics regarding

Re: simpler increment of time values?

2012-07-05 Thread John Nagle
On 7/4/2012 5:29 PM, Vlastimil Brom wrote: Hi all, I'd like to ask about the possibilities to do some basic manipulation on timestamps - such as incrementing a given time (hour.minute - string) by some minutes. Very basic notion of time is assumed, i.e. dateless, timezone-unaware, DST-less etc.

Re: simpler increment of time values?

2012-07-05 Thread rurpy
On Thursday, July 5, 2012 11:34:16 AM UTC-6, John Nagle wrote: [...] You can also call time.time(), and get the number of seconds since the epoch (usually 1970-01-01 00:00:00 UTC). That's just a number, and you can do arithmetic on that. Adding a datetime.time to a datetime.timedelta

Re: simpler increment of time values?

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 11:15:04 -0700, rurpy wrote: On Thursday, July 5, 2012 11:34:16 AM UTC-6, John Nagle wrote: [...] You can also call time.time(), and get the number of seconds since the epoch (usually 1970-01-01 00:00:00 UTC). That's just a number, and you can do arithmetic on that.

simpler increment of time values?

2012-07-04 Thread Vlastimil Brom
Hi all, I'd like to ask about the possibilities to do some basic manipulation on timestamps - such as incrementing a given time (hour.minute - string) by some minutes. Very basic notion of time is assumed, i.e. dateless, timezone-unaware, DST-less etc. I first thought, it would be possible to just

Re: simpler increment of time values?

2012-07-04 Thread Chris Angelico
On Thu, Jul 5, 2012 at 10:29 AM, Vlastimil Brom vlastimil.b...@gmail.com wrote: I'd like to ask about the possibilities to do some basic manipulation on timestamps - such as incrementing a given time (hour.minute - string) by some minutes. Very basic notion of time is assumed, i.e. dateless,

Re: simpler increment of time values?

2012-07-04 Thread Mark Lawrence
On 05/07/2012 01:29, Vlastimil Brom wrote: Hi all, I'd like to ask about the possibilities to do some basic manipulation on timestamps - such as incrementing a given time (hour.minute - string) by some minutes. Very basic notion of time is assumed, i.e. dateless, timezone-unaware, DST-less etc.

Re: simpler increment of time values?

2012-07-04 Thread Jason Friedman
Hi all, I'd like to ask about the possibilities to do some basic manipulation on timestamps - such as incrementing a given time (hour.minute - string) by some minutes. Very basic notion of time is assumed, i.e. dateless, timezone-unaware, DST-less etc. I first thought, it would be possible

Re: simpler increment of time values?

2012-07-04 Thread Devin Jeanpierre
On Thu, Jul 5, 2012 at 12:57 AM, Jason Friedman ja...@powerpull.net wrote: I have some thoughts on a solution, but first, what is 12:45 plus 12 hours? What is 12:45 minus 13 hours? Is there anything unusual that can happen for a notion of time that is dateless, timezone-unaware, and DST-free?