Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56697
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'diff': 0.07; 'method,': 0.09; 'to:addr:pobox.com': 0.09; 'to:addr:skip': 0.09; 'cc:addr :python-list': 0.11; 'cleaner': 0.16; 'cleanly': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'delta': 0.24; 'replace': 0.24; 'skip': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'field,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'guess': 0.33; 'maybe': 0.34; 'skip:d 20': 0.34; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'two': 0.37; 'more': 0.64; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=S5uSbWpJWv9/sHfTl1fMRy7NOj4x/gOPHtjnBTjG9Ys=; b=xMPElEli/0hPgC7NAzbv4UjH56306FiYahX7W4zYmGurxZWnanQEmczPF2juOgb6uI k7dPDdwfqTO+STd9YkKqGOvLy26rarzO29OSrp/vGagx6yCl1gILiScFwDZxhFMkspeb ZDq0nS4flE4hZ4No6nLBpiTLLIIQ9EzjCBy1OuybR9zgbaToCcZ09vun+T1CBQoU0btK R/BrS6a8oqCc2qme1RSPV6tf/E/2JQ+7KBEHsmjVwDHwGPyDmVGIiSLbBPqfvoAcqCOA FFxH5hSv/+8WJ/k2Ps0EX+A0kzRMAcB/iZjtT/5cn/+W7hpqYuUAX/XEMoWd1RK8BDZh VL6w== |
| X-Received | by 10.112.57.49 with SMTP id f17mr17816202lbq.26.1381514219056; Fri, 11 Oct 2013 10:56:59 -0700 (PDT) |
| MIME-Version | 1.0 |
| Sender | joshua.landau.ws@gmail.com |
| In-Reply-To | <CANc-5Uy+XxZQTR16Q2Uxo3=5n-GfYMAvA1EyEOTN95wni2sUYA@mail.gmail.com> |
| References | <CANc-5Uy+XxZQTR16Q2Uxo3=5n-GfYMAvA1EyEOTN95wni2sUYA@mail.gmail.com> |
| From | Joshua Landau <joshua@landau.ws> |
| Date | Fri, 11 Oct 2013 18:56:18 +0100 |
| X-Google-Sender-Auth | RpUeM1na76XcD4W1mE9VYyDEn-8 |
| Subject | Re: datetime.timedelta.replace? |
| To | Skip Montanaro <skip@pobox.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | Python <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1009.1381514226.18130.python-list@python.org> (permalink) |
| Lines | 20 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1381514226 news.xs4all.nl 15864 [2001:888:2000:d::a6]:37523 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:56697 |
Show key headers only | View raw
On 9 October 2013 16:15, Skip Montanaro <skip@pobox.com> wrote:
> Datetime objects have a replace method, but timedelta objects don't.
> If I take the diff of two datetimes and want to zero out the
> microseconds field, is there some way to do it more cleanly than this?
>
> delta = dt1 - dt2
> zero_delta = datetime.timedelta(days=delta.days, seconds=delta.seconds)
>
> I guess that's not bad, but replace() seems cleaner (or at least more
> congruent with datetime objects).
Maybe one of
delta - datetime.timedelta(0, 0, delta.microseconds)
or
delta - delta % datetime.timedelta(seconds=1)
is clearer.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: datetime.timedelta.replace? Joshua Landau <joshua@landau.ws> - 2013-10-11 18:56 +0100
csiph-web