Using mktime to convert date to seconds since epoch - omitting elements from the tuple?
Barry Scott
barry at barrys-emacs.org
Thu Jan 3 18:46:55 EST 2013
On 2 Jan 2013, at 08:01, Victor Hooi <victorhooi at gmail.com> wrote:
> Hi,
>
> I'm using pysvn to checkout a specific revision based on date - pysvn will only accept a date in terms of seconds since the epoch.
>
> I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to seconds since epoch.
>
> According to the docs, mktime expects a 9-element tuple.
>
> My question is, how should I omit elements from this tuple? And what is the expected behaviour when I do that?
>
> For example, (zero-index), element 6 is the day of the week, and element 7 is the day in the year, out of 366 - if I specify the earlier elements, then I shouldn't really need to specify these.
>
> However, the docs don't seem to talk much about this.
>
> I just tried testing putting garbage numbers for element 6 and 7, whilst specifying the earlier elements:
>
>> time.mktime((2012, 5, 5, 23, 59, 59, 23424234, 5234234 ,0 ))
>
> It seems to have no effect what numbers I set 6 and 7 to - is that because the earlier elements are set?
>
> How should I properly omit them? Is this all documented somewhere? What is the minimum I need to specify? And what happens to the fields I don't specify?
See the python docs the tuple is fully documented.
6 and 7 are not needed to figure out the seconds so are ignored.
Did you notice the parse_datetime.py that is in the pysvn Client Example? Its a rather
over the top date and time parser I wrote a long long time ago. (Which is missing some imports,
hmm I cannot have tested this for a long time). It can parse things like "yesterday 10:34".
Barry
More information about the Python-list
mailing list