Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70526 > unrolled thread

Re: Why does isoformat() optionally not print the fractional seconds?

Started byMRAB <python@mrabarnett.plus.com>
First post2014-04-23 03:50 +0100
Last post2014-04-23 03:50 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Why does isoformat() optionally not print the fractional seconds? MRAB <python@mrabarnett.plus.com> - 2014-04-23 03:50 +0100

#70526 — Re: Why does isoformat() optionally not print the fractional seconds?

FromMRAB <python@mrabarnett.plus.com>
Date2014-04-23 03:50 +0100
SubjectRe: Why does isoformat() optionally not print the fractional seconds?
Message-ID<mailman.9450.1398221430.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web