Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'string.': 0.05; 'url:pipermail': 0.05; 'json': 0.07; 'parser': 0.07; 'permitted': 0.07; 'suddenly': 0.07; 'seemed': 0.09; 'subject:Why': 0.09; 'thread': 0.14; 'api,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'ios': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'omitting': 0.16; 'received:192.168.1.4': 0.16; 'recorded': 0.16; 'travis': 0.16; 'two.': 0.16; 'wrote:': 0.18; 'app': 0.19; 'server,': 0.19; 'header:User-Agent:1': 0.23; 'format,': 0.24; 'parse': 0.24; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'leave': 0.29; 'returned': 0.30; 'getting': 0.31; 'pan': 0.31; 'url:python': 0.33; 'subject:the': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'consistent': 0.36; 'dates': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'being': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'skip:t 30': 0.61; 'today.': 0.61; 'simply': 0.61; 'times': 0.62; 'making': 0.63; 'hearing': 0.63; 'skip:n 10': 0.64; 'decided': 0.64; 'more': 0.64; 'love': 0.65; 'series': 0.66; 'side': 0.67; 'between': 0.67; 'i\xe2\x80\x99ll': 0.84; 'milliseconds': 0.84; 'points,': 0.84; 'resulted': 0.84; 'transmitting': 0.84; 'wasn\xe2\x80\x99t': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=d897yHTE c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=tLkI8qN_j18A:10 a=FVYEiijAwkEA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=1zgyL1JlD6MNsyiSsrkA:9 a=QEXdDO2ut3YA:10 a=piACmGDaGYgA:10 X-AUTH: mrabarnett:2500 Date: Wed, 23 Apr 2014 03:50:28 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Why does isoformat() optionally not print the fractional seconds? References: <06945DEA-7DCA-4C35-AD6F-0ECEE74CAAEC@gmail.com> In-Reply-To: <06945DEA-7DCA-4C35-AD6F-0ECEE74CAAEC@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398221430 news.xs4all.nl 2919 [2001:888:2000:d::a6]:42497 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70526 On 2014-04-23 01:05, Travis Griggs wrote: > Python(3) let me down today. Better to be explicit, and all that, didn’t pan out for me. > > I have time series data being recorded in a mongo database (I love pymongo). I have an iOS app that consumes the data. Since JSON doesn’t have a time format, I have to stringify the times when transmitting between the two. To parse it on the obj-c side, I use > > NSDateFormatter *parser = [NSDateFormatter new]; > parser = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; > [parser setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.S”]; > NSDate *date = [parser dateFromString: thatJsonString]; > > Which was working swimmingly, until I started getting occasional and infrequent nil dates at times. I thought I had a storage issue or something with my REST api, or the server, or something. But it was simply now and then again, why 1000’s of data points, I managed to get 0 milliseconds from time to time, which resulted in the isoformat() I was using to suddenly leave off the .S part of the string. And since the parse then failed, the iOS side decided it wasn’t valid and returned a nil. > > Haven’t decided where/how I’ll work around it yet, but the isoformat() seemed unpythonic to me today. > > Thanks for hearing me whine. > Omitting fractional seconds is permitted by the standard. There was a thread last year about it: Making datetime __str__ and isoformat more consistent https://mail.python.org/pipermail//python-ideas/2013-November/023913.html