Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'revision': 0.05; 'that?': 0.05; 'omit': 0.07; 'remaining': 0.07; 'see:': 0.07; 'garbage': 0.09; 'specifying': 0.09; 'tuple.': 0.09; 'properly': 0.15; 'elements,': 0.16; 'expects': 0.16; 'mktime': 0.16; 'subject: \n ': 0.16; 'url:time': 0.16; 'documented': 0.17; 'element': 0.17; "shouldn't": 0.17; 'specify': 0.17; 'string,': 0.17; '>>>': 0.18; 'input': 0.18; 'putting': 0.20; 'earlier': 0.21; 'cheers,': 0.23; 'elements': 0.23; 'seems': 0.23; 'testing': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; '(e.g.': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'attempting': 0.29; 'behaviour': 0.29; 'them?': 0.29; 'usable': 0.29; 'url:mailman': 0.29; 'convert': 0.29; 'handled': 0.29; 'this.': 0.29; "i'm": 0.29; 'initially': 0.30; 'function': 0.30; 'seconds': 0.30; 'year,': 0.30; 'url:python': 0.32; 'url:listinfo': 0.32; 'docs': 0.33; 'extract': 0.33; 'to:addr :python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'minimum': 0.34; 'expected': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'talk': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'information': 0.63; 'day': 0.73; 'elements:': 0.84; 'presumably': 0.84; 'subject:Using': 0.84; 'victor': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=6ceR28LAbZmDseW/S//Cac30NvVJEomTxntFbm2ZSJE=; b=PyzTPPRBlboZzpRkE5Bt17ZkQM+glicXjFdCiiSNR7+CmPreMvJTwXGHtXhY1uMQYj 1S2XshGPAv/oBPM7Xh213J0baYPAW0/dQjmyE0f+jxaKNGBj6s+RW/MwmuT2bfrw6qDe FKbiEI44O+ELuhsn8CFNP+Ep2mzfQQv967UsG9UqKtCtRqd7yL+LDRa9pVfHwkIzMW4a 3YBT2zZz9HzeDpfY6N2cM/BpvWCrWtqjkydnzWaPz8GpuePLWEraQdW336kxOj7/Qk4j ocoWy2J/0T/Unm+F90lLQ3+kDwJIi6c2+HN8YO96xVpVrfLpLX96lqDKHt7tPVZw9Y2c +rTg== MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 2 Jan 2013 09:33:39 +0100 Subject: Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? From: Vlastimil Brom To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357115628 news.xs4all.nl 6901 [2001:888:2000:d::a6]:59296 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35967 2013/1/2 Victor Hooi : > 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? > > Cheers, > Victor > -- > http://mail.python.org/mailman/listinfo/python-list Hi, if you initially have the time information as string, you might use time.strptime(...) to extract this based on the supplied format; the output of this function is usable as input for mktime, the remaining fields are presumably handled consistently. see: http://docs.python.org/2/library/time.html#time.strftime >>> time.strptime("2012-3-17", "%Y-%m-%d") time.struct_time(tm_year=2012, tm_mon=3, tm_mday=17, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=77, tm_isdst=-1) >>> time.mktime(time.strptime("2012-3-17", "%Y-%m-%d")) 1331938800.0 >>> hth, vbr