On Sat, Dec 24, 2011 at 5:04 PM, Jason Friedman wrote:
> Not particularly elegant, but I believe accurate and relying only on
> the stated struct_time contract:
Funny! But a binary search would be better, I think.
t = time.time()
time1 = time.localtime(t)
print("Local time is {}.".format(time1)
On Fri, Dec 16, 2011 at 10:44 AM, Chris Angelico wrote:
> On Fri, Dec 16, 2011 at 8:45 PM, Ulrich Eckhardt
> wrote:
>> I'm trying to create a struct_time that is e.g. one year ahead or a month
>> back in order to test some parsing/formatting code with different dates.
>
> Do you need it to be one
On Sat, Dec 17, 2011 at 12:32 AM, Ulrich Eckhardt
wrote:
> Concerning the idea to use seconds, I'd rather not, because already the
> number of seconds per minute ranges from 60 to 62, and it doesn't get better
> with things like months (28...31 days), years (365...366 days) and all other
> types b
Am 16.12.2011 10:45, schrieb Ulrich Eckhardt:
I'm trying to create a struct_time that is e.g. one year ahead or a
month back in order to test some parsing/formatting code with different
dates.
There is something I stumbled across that helps and that is the datetime
module, which seems more rea
On 16/12/2011 10:44, Steven D'Aprano wrote:
[ on time.struct_time ]
Not a bug, but it does seem a very old and inelegant API more suited to
hairy C programmers gathered around a smokey fire in a cave chewing on
old dinosaur bones, and not worthy of space-age Python coders flying
around on anti-g
On Fri, Dec 16, 2011 at 8:45 PM, Ulrich Eckhardt
wrote:
> I'm trying to create a struct_time that is e.g. one year ahead or a month
> back in order to test some parsing/formatting code with different dates.
Do you need it to be one exact calendar year, or would it make sense
to add/subtract integ
On Fri, 16 Dec 2011 10:45:22 +0100, Ulrich Eckhardt wrote:
> Hi!
>
> I'm trying to create a struct_time that is e.g. one year ahead or a
> month back in order to test some parsing/formatting code with different
> dates.
[...]
> The second approach is this:
>
>l = list(t) # convert to a seque
Hi,
Easiest way is to change the time to seconds, add as many seconds as a
year/month/week/day/hour/minutes represent and then transform it back.
E.g.
>>> time.time()
1324031491.026137
>>> time.time() + 3600 # Add an hour
1324035105.082003
>>> time.gmtime(time.time() + 3600)
time.struct_time(tm_
Hi!
I'm trying to create a struct_time that is e.g. one year ahead or a
month back in order to test some parsing/formatting code with different
dates.
Now, the straightforward approach is
t = time.localtime()
t.tm_year += 1
This fails with "TypeError: readonly attribute". This kind-of m