Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17834
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.023 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'else:': 0.03; 'elegant,': 0.09; 'binary': 0.13; 'received:209.85.210.174': 0.13; 'received :mail-iy0-f174.google.com': 0.13; 'subject:skip:t 10': 0.15; 'cmp': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'later': 0.21; 'dec': 0.22; 'assume': 0.22; 'header:In-Reply-To:1': 0.22; 'sat,': 0.25; "i'm": 0.26; 'function': 0.27; 'exercise': 0.28; 'jason': 0.28; 'message- id:@mail.gmail.com': 0.28; '24,': 0.29; 'pm,': 0.29; '-1,': 0.30; "i'll": 0.31; 'does': 0.32; 'break': 0.32; 'to:addr:python-list': 0.34; 'dinner': 0.34; 'skip:i 40': 0.34; '(not': 0.35; 'but': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'received:209.85': 0.38; 'difficult': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'more': 0.61; '2011': 0.61; 'family': 0.63; 'believe': 0.65; 'stated': 0.68; 'valid)': 0.84; 'christmas': 0.97 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+WsDPsFLy/UBDnBpw5WuP5s++WWZ7s1SJXyE+fRL24Y=; b=WrdUgfRoYNdCfD2c+lh8DBV+eXT+JAOCd2FsEt6PE2mdn0uzUFBJjOo+emOXVDJiGf 8858L5Yl2VVM2jRwlxp0hLUP7EevZ6aJ9Ltj0kzdIXKH9MQTYviAQwrXqKBSPVbskKA8 rlRepqBXgcwf3glxZnqFd/QlIba9qJUyeoqJw= |
| MIME-Version | 1.0 |
| In-Reply-To | <CANy1k1iRrDS2SwJewv_gEs_tHrRzbdaKSJf+8SE5d+CC0PFdcg@mail.gmail.com> |
| References | <iigrr8-e96.ln1@satorlaser.homedns.org> <CAPTjJmrc4CLVotL=4JFrdyAZ9hstKSGXyjsyv2pjye4JVggK0Q@mail.gmail.com> <CANy1k1iRrDS2SwJewv_gEs_tHrRzbdaKSJf+8SE5d+CC0PFdcg@mail.gmail.com> |
| Date | Sat, 24 Dec 2011 18:13:13 +1100 |
| Subject | Re: modifying a time.struct_time |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4045.1324710802.27778.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1324710802 news.xs4all.nl 6949 [2001:888:2000:d::a6]:47337 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:17834 |
Show key headers only | View raw
On Sat, Dec 24, 2011 at 5:04 PM, Jason Friedman <jason@powerpull.net> 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))
est1 = t + 365*86400
est2 = est1 + 86400 # Assume that the year is between 365 and 366 days
long (widen this if assumption not valid)
while True:
est = (est1 + est2) / 2
time2 = time.localtime(t)
cmp = is_local_time_different_by_one_year(time1, time2):
if cmp<0: est1 = est
elif cmp>0: est2 = est
else:
print("One year later is {}".format(time2))
break
Could do with a few more improvements. Also, it requires that the
comparison function return -1, 0, or 1, in the same way that strcmp()
does (not a difficult enhancement, but I'm off to Christmas dinner
with the family so I'll leave it as an exercise for the reader).
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
modifying a time.struct_time Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-12-16 10:45 +0100
Re: modifying a time.struct_time Mazen Harake <mazen.harake@gmail.com> - 2011-12-16 11:32 +0100
Re: modifying a time.struct_time Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-16 10:44 +0000
Re: modifying a time.struct_time Tim Golden <mail@timgolden.me.uk> - 2011-12-16 10:50 +0000
Re: modifying a time.struct_time Chris Angelico <rosuav@gmail.com> - 2011-12-16 21:44 +1100
Re: modifying a time.struct_time Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-12-16 14:32 +0100
Re: modifying a time.struct_time Chris Angelico <rosuav@gmail.com> - 2011-12-17 01:24 +1100
Re: modifying a time.struct_time Jason Friedman <jason@powerpull.net> - 2011-12-24 06:04 +0000
Re: modifying a time.struct_time Chris Angelico <rosuav@gmail.com> - 2011-12-24 18:13 +1100
csiph-web