[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-06 Thread Roundup Robot

Roundup Robot added the comment:

New changeset eb120f50df4a by Alexander Belopolsky in branch 'default':
Closes #19475: Added timespec to the datetime.isoformat() method.
https://hg.python.org/cpython/rev/eb120f50df4a

--
nosy: +python-dev
resolution:  -> fixed
stage: commit review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-02 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Alessandro, thank you very much for your work and perseverance.  I will do my 
best to commit this next weekend.

--
stage: patch review -> commit review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-02 Thread SilentGhost

Changes by SilentGhost :


--
nosy:  -SilentGhost

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-02 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Meanwhile I made corrections after @belopolsky latest review

--
Added file: http://bugs.python.org/file42063/issue19475_v17.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

I feel odd trying to advocate a POV that I disagree with, so let me just quote 
MAL:


"""
In practice you often don't know the resolution of
the timing source. Nowadays, the reverse of what you said
is usually true: the source resolution is higher than the
precision you use to print it.
..

For full seconds, truncation will add an error of +/- 1 second,
whereas rounding only adds +/- 0.5 seconds. This is what convinced
me to use rounding instead of truncation.
"""

I somehow missed this argument when Marc-Andre made it, so I want to make sure 
that it is properly considered before we finalize this issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread STINNER Victor

STINNER Victor added the comment:

> Personally, I don't rounding is that useful.

Nice, it looks like I agree with you on using ROUNDING_FLOOR :-)

I don't think that we should be prepared for theorical user requests, but 
rather focus on the concrete and well defined current existing user request: 
"Add timespec optional flag to datetime isoformat() to choose the precision".

Let's wait until users request a datetime.round() method to understand better 
concrete issues.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Personally, I don't rounding is that useful.  My working assumption is that 
users will select say timespec='millisecond' only when they know that their 
time source produces datetime instances with millisecond precision and they 
don't want to kill more trees by printing redundant 0's.

MAL's objection this this line of arguments was that some time sources have odd 
resolution (he reported MS SQL's use of 333 ms) and a user may want to have a 
perfect round-tripping when using a sub-usec timespec and such an odd time 
source or destination.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread STINNER Victor

STINNER Victor added the comment:

> Maybe a datetime.round() method along these lines will be a worthwhile 
> addition?

Sorry, what is the use case of this method?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Guido van Rossum

Guido van Rossum added the comment:

IIUC truncation traditionally means "towards zero" -- that's why we have 
separate "floor" and "ceiling" operations meaning "towards [negative] 
infinity". Fortunately we shouldn't have to deal with negative values here so 
floor and truncate mean the same thing. Agreed that isoformat() should also 
truncate.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Guido van Rossum

Guido van Rossum added the comment:

Except for the case where you're closer than half a usec from the next value, 
IMO rounding makes no sense when suppressing digits. I most definitely would 
never want 9:59:59 to be rounded to 10:00 when suppressing seconds. If you 
really think there are use cases for that you could add a 'round=True' flag (as 
long as it defaults to False). That seems better than supporting rounding on 
datetime objects themselves. But I think you're just speculating.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread STINNER Victor

STINNER Victor added the comment:

> But what should we do in your opinion?

Use ROUND_FLOOR rounding method.

time.time(), datetime.datetime.now(), etc. round the current time using the 
ROUND_FLOOR rounding method.

Only datetime.datetime.fromtimestamp() uses ROUND_HALF_EVEN, but it's more an 
exception than the rule: this function uses a float as input. To be consistent, 
we must use the same rounding method than other Python functions taking float 
as parameter, like round(), so use ROUND_HALF_EVEN.

So I suggest to also use ROUND_FLOOR for .isoformat().

Hopefully, we don't have to discuss about the exact rounding method for 
negative numbers, since the minimum datetime object is datetime.datetime(1, 1, 
1) which is "positive" ;-)

You have a similar rounding question for file timestamps. Depending on the file 
system, you may have a resolution of 2 seconds (FAT), 1 second (ext3) or 1 
nanosecond (ext4). But Linux syscalls accept subsecond resolution. The Linux 
kernel uses ROUND_FLOOR rounding method if I recall correctly. I guess that 
it's a requirement for makefiles. If you already experimented a system clock 
slew, you may understand me :-)


> For full seconds, truncation will add an error of +/- 1 second,
> whereas rounding only adds +/- 0.5 seconds. This is what convinced
> me to use rounding instead of truncation.

What is truncation? Is it the ROUND_FLOOR (towards -inf) rounding method? Like 
math.floor(float).

Python int(float) uses ROUND_DOWN (towards zero) which is different than 
ROUND_FLOOR, but only different for negative numbers. int(-0.9) returns 0, 
whereas math.floor(-0.9) returns -1.

I guess that "rounding" means ROUND_HALF_EVEN here? The funny "Round to nearest 
with ties going to nearest even integer" rounding method. Like round(float).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

I hope my prediction "I am afraid that the rounding issues may kill this 
proposal" (see msg202276) will not come true.

I think the correct way to view "timespec" is a way to suppress/enforce 
printing of trailing digits.

Users that choose printing less than full usec format should make sure that 
their datetime instances are properly rounded before printing.

Unfortunately, I does not look like the datetime module makes rounding easy.  
The best I can think of is something like

def round_datetime(dt, delta):
dt0 = datetime.combine(dt.date(), time(0))
return dt0 + round((dt - dt0) / delta) * delta

Maybe a datetime.round() method along these lines will be a worthwhile addition?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Guido van Rossum

Guido van Rossum added the comment:

But what should we do in your opinion?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread STINNER Victor

STINNER Victor added the comment:

> Given that we're talking about what to do when we're suppressing the usecs I 
> don't think roundtripping matters. :-)

I changed many times how Python rounds nanoseconds in the private PyTime API, 
and I got a bug report because of that! => issue #23517.

By the way, I wrote an article to explain the history the private PyTime API, 
especially changes on rounding ;-) https://haypo.github.io/pytime.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Guido van Rossum

Guido van Rossum added the comment:

Given that we're talking about what to do when we're suppressing the usecs I 
don't think roundtripping matters. :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Another argument for truncation is that this is what GNU date does:

$ date --iso-8601=seconds --date="2016-03-01 15:00:00.999"
2016-03-01T15:00:00-0500

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Guido,

Did you consider MAL's msg202274?  I am still in favor of truncation, but would 
like to make sure we are not missing something that MAL knows from experience.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-03-01 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-25 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

We discussed truncation vs. rounding some time ago.  See msg202270 and the 
posts around it.  The consensus was the same as Guido's current advise: do the 
truncation.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-25 Thread Guido van Rossum

Guido van Rossum added the comment:

Out of context here, but regarding round vs. truncate, IIUC for time
truncating down is the norm. My digital clock shows "12:00" for the
duration of the minute starting at noon. People look for clocks to
flip to know when it is exactly a given time (if the clock is accurate
enough).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-25 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Oh, now I see your point.

I've uploaded a new patch with a note for that.

--
Added file: http://bugs.python.org/file42031/issue19475_v16.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-23 Thread Martin Panter

Martin Panter added the comment:

About rounding: I’m not too sure what people would expect. Obviously it is much 
easier to implement truncating to zero. But it is different to many other 
rounding cases in Python; that is why I thought to make it explicit.

>>> datetime.fromtimestamp(59.999).isoformat(timespec="microseconds")
'1970-01-01T00:01:00.00'
>>> datetime.fromtimestamp(59.99).isoformat(timespec="milliseconds")
'1970-01-01T00:00:59.999'
>>> format(59.99, ".3f")
'60.000'

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-22 Thread Alessandro Cucci

Alessandro Cucci added the comment:

New patch after @martin.panter comments on Rietveld. I left only this:

- ``'milliseconds'``: Append the hours, minutes, seconds and milliseconds.

> vadmium 2016/02/21 23:30:20
> I think this should explain that fractions are truncated to zero, never 
> rounded
> up. At least for fractions of milliseconds, although this could apply 
> to the
> other options as well.

I think is quite obvious that a datetime.now() can't be rounded to the future 
if microseconds are 999500.

--
Added file: http://bugs.python.org/file42007/issue19475_v15.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-22 Thread Andrei Dorian Duma

Changes by Andrei Dorian Duma :


--
nosy:  -andrei.duma

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-21 Thread Martin Panter

Martin Panter added the comment:

Left some review suggestions

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-02-21 Thread Alessandro Cucci

Alessandro Cucci added the comment:

New patch

--
Added file: http://bugs.python.org/file41988/issue19475_v13.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread Guido van Rossum

Guido van Rossum added the comment:

I think Alexander has commit rights, he did most of the review, I trust him
to commit it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

I left some comments on Rietveld.

--
stage: commit review -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
assignee:  -> belopolsky
stage: patch review -> commit review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread SilentGhost

SilentGhost added the comment:

Yes, version 12 is the final patch. It doesn't add those options. To copy my 
opinion from the rietveld (https://bugs.python.org/review/19475/#msg14): 

> I don't really think nanoseconds belong here. If they don't
> exist anywhere else in the module, why should they be suddenly introduced 
> here?
> of all places. It would be fine to use some generic solution that would enable
> or ease their addition in the future, but they shall not be added at this 
> time.

(there are altogether 27 messages there, which everyone's naturally CCed on).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

> I don't really think nanoseconds belong here.

What about milliseconds?  I'll leave it for Guido to make a call on 
nanoseconds.  My vote is +0.5.

> If they don't
> exist anywhere else in the module, why should they be suddenly 
> introduced here?

The timespec feature is modeled after GNU date --iso-8601[=timespec] option 
which does support nanoseconds.  It is fairly common to support nanoseconds 
these days and it does not cost much to implement.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Is issue19475_v12.patch the final patch?  I don't see it addressing Guido's 
suggestion in msg256470 to add milli- and nanoseconds options.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread Guido van Rossum

Guido van Rossum added the comment:

You can leave out the nanoseconds but please do add the milliseconds. I'm sure 
they would find more use than the option to show only the hours.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-17 Thread SilentGhost

SilentGhost added the comment:

> I there anything else I can do for this?
I think you've done all you could, it's just someone needs to commit it.  I 
don't think they're being rude on purpose - it's just that there are so many 
committers in the nosy list that no one is feeling like it's their job.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-15 Thread Alessandro Cucci

Alessandro Cucci added the comment:

I there anything else I can do for this?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-15 Thread R. David Murray

Changes by R. David Murray :


--
nosy:  -r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-05 Thread Alessandro Cucci

Alessandro Cucci added the comment:

up

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-01 Thread Martin Panter

Martin Panter added the comment:

I think there is a memory leak in the C code. I left some other minor 
suggestions as well, but it almost looks ready.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2016-01-01 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Thanks @martin.panter, here is another patch made after your comments.

--
Added file: http://bugs.python.org/file41464/issue19475_v12.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-29 Thread SilentGhost

Changes by SilentGhost :


--
stage: patch review -> commit review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-29 Thread Berker Peksag

Berker Peksag added the comment:

Thanks for the patch, Alessandro. I left some comments about documentation part 
of the patch, but I can fix them myself if you don't have time.

--
stage: commit review -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-29 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Berker, thank you. 
In the last patch, I removed details about timespec options in Python and C 
docstrings, corrected the rst quotes, and checked PEP7 in the c file.

The only problem now is about versionchanged vs versionadded. I leave it as it 
was, as Silent and the official doc say, if you want to change it, i'll leave 
it to you. 

Again, many many thanks to all. This was my first issue here, I learnt a lot!

--
Added file: http://bugs.python.org/file41448/issue19475_v11.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-29 Thread Alessandro Cucci

Alessandro Cucci added the comment:

what about the comment left by SilentGhost about versionadded?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-25 Thread Alessandro Cucci

Alessandro Cucci added the comment:

> I think timespec= option should also be added to the time.isoformat method.

@belopolsky I've done it in my last patch.

--
Added file: http://bugs.python.org/file41420/issue19475_v10_datetime_time.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-23 Thread Skip Montanaro

Changes by Skip Montanaro :


--
nosy:  -skip.montanaro

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-22 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Thanks SilentGhost!

--
Added file: http://bugs.python.org/file41391/issue19475_v9.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-22 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Sorry @SilentGhost, I didn't seen your comment at the bottom of the review. 
With this patch is microsecond is 0, the time will display 6 zeroes.

--
Added file: http://bugs.python.org/file41388/issue19475_v8.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-22 Thread Alessandro Cucci

Changes by Alessandro Cucci :


Added file: http://bugs.python.org/file41387/issue19475_v7.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-22 Thread SilentGhost

SilentGhost added the comment:

I think the patch is nearly finalised, but I'd appreciate if someone else would 
carefully go over the new C code. After that, I think, the patch could be 
committed.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-21 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Uploaded a new patch after SilentGhost review comments.

As he told me, I've left out milliseconds and nanoseconds, but refactored both 
python and c code so we could easily add support for them when they will be 
available.

--
Added file: http://bugs.python.org/file41381/issue19475_v6.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-20 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Uploaded a new patch. 

This time I ran tests using:
$ ./python -m test -v test_datetime

and got no errors.

I've written the c docstring, updated docs, and rewrote _format_time function.

I know it's boring review this another time, but I'm doing my best.

Thanks to all.

--
Added file: http://bugs.python.org/file41371/issue19475_v5.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-17 Thread Martin Panter

Martin Panter added the comment:

If the timespec allowed any arbitrary number of digits after the decimal point, 
that would remove any argument about nanoseconds not being supported. It would 
also mean I could use this in one case where I currently format to two decimal 
places (my compromise between accurate timestamps and excessive information). 
Just a suggestion :)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-16 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +SilentGhost

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-16 Thread Martin Panter

Martin Panter added the comment:

With patch v4 many tests still fail for me. How are you running the test suite? 
Some excerpts:

  File "/media/disk/home/proj/python/cpython/Lib/test/datetimetester.py", line 
1567, in test_isoformat
self.assertEqual(t.isoformat(timespec='milliseconds'), 
"0001-02-03T04:05:01.000")
AssertionError: '0001-02-03T04:05:01.00' != '0001-02-03T04:05:01.000'

  File "/media/disk/home/proj/python/cpython/Lib/test/datetimetester.py", line 
2310, in test_isoformat
self.assertEqual(t.isoformat(), "00:00:00")
AssertionError: '00:00:00.00' != '00:00:00'

  File "/media/disk/home/proj/python/cpython/Lib/test/datetimetester.py", line 
2379, in test_str
self.assertEqual(str(self.theclass(12, 2, 3, 0)), "12:02:03")
AssertionError: '12:02:03.00' != '12:02:03'

The C module doc string I referred to is this one; I left a review comment at 
the source:

>>> print(datetime.isoformat.__doc__)
[sep] -> string in ISO 8601 format, -MM-DDTHH:MM:SS[.mm][+HH:MM].

sep is used to separate the year from the time, and defaults to 'T'.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-16 Thread SilentGhost

SilentGhost added the comment:

Even that produces 3 failures on my setup, though the full list would be 
available when running: ./python -m test -v test_datetime

It is obvious, however, that the tests would fail: you've changed "if us:" to 
"if us is None:".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-16 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Uploaded a new patch (v4):
DONE:
- now all tests work (I also added one more)
- removed non ascii chars
- added milliseconds and nanoseconds as multiple of microseconds
- removed code duplication in the datetime.py
- update the docstring.

TODO:
> The doc string in the C module needs updating. 
Where? I guess "Macros to extract fields from datetime objects." in 
c-api/datetime.rst Tell me if I'm wrong

> I think timespec= option should also be added to the time.isoformat method.
I'll do it when I'm sure that the datetime.isoformat method is correct.

--
Added file: http://bugs.python.org/file41329/issue19475_v4.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-16 Thread Alessandro Cucci

Alessandro Cucci added the comment:

I just did that...

~/Documenti/cpython$ ./configure --with-pydebug
~/Documenti/cpython$ make -s -j2
~/Documenti/cpython$ ./python -m test -v datetimetester
...
...

--
Ran 325 tests in 1.128s

OK (skipped=1)
1 test OK.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Guido van Rossum

Guido van Rossum added the comment:

I like the idea. I have one suggestion: can we add 'milliseconds' as an option 
too? And might a well add 'nanoseconds' too, for future-proofing. I suppose 
there isn't a real use case for 'hours' but it seems silly to  leave it out. I 
expect that 'minutes' will be the most popular option, since HH:MM is the 
precision that most people care about for meetings and stuff.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

It looks like issue19475_v3.patch uses some fancy Unicode quotes in the 
docstrings and .rst docs.  Please change them to ASCII.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

GvR> I suppose there isn't a real use case for 'hours' but it seems silly to  
leave it out.

Shouldn't we also have 'none' to leave out the time component entirely?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

> The problem here is that millisecond and nanosecond seems not to be 
> attributes of the datetime object.

millisecond = dt.microsecond // 1000

nanosecond = 0  # until we add it to datetime.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Guido van Rossum

Guido van Rossum added the comment:

Actually, nanosecond = dt.microsecond*1000.

I don't think we need 'none' -- you should just extract the date component
and call its isoformat() method if that's what you want.

On Tue, Dec 15, 2015 at 12:01 PM, Alexander Belopolsky <
rep...@bugs.python.org> wrote:

>
> Alexander Belopolsky added the comment:
>
> > The problem here is that millisecond and nanosecond seems not to be
> attributes of the datetime object.
>
> millisecond = dt.microsecond // 1000
>
> nanosecond = 0  # until we add it to datetime.
>
> --
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alessandro Cucci

Alessandro Cucci added the comment:

I can work on that, although I'll need help from some senior dev. The problem 
here is that millisecond and nanosecond seems not to be attributes of the 
datetime object. What about open a new issue if we have to add them? Is not 
about adding an optional flag anymore...
Anyway, as I said, any help is appreciated!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

> Actually, nanosecond = dt.microsecond*1000.

I was thinking in terms breaking the fractional part of say

00:00:00.123456789

into

mili = 123
micro = 456
nano = 789

but you are right, a correct analogy for dt.microsecond in this case will be 
nanosecond=123456789 or 123456000 until we start storing enough precision.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Martin Panter

Martin Panter added the comment:

Alessandro, did you try running the test suite? It is broken for me. One of the 
bugs is that it now omits zero hours, minutes, and seconds in addition to 
microseconds. (Kind of the reverse of what the bug was originally about :).

Other failures look like this:

==
ERROR: test_isoformat (test.datetimetester.TestDateTime)
--
Traceback (most recent call last):
  File "/media/disk/home/proj/python/cpython/Lib/test/datetimetester.py", line 
1560, in test_isoformat
timespec_error = self.time()
AttributeError: 'TestDateTime_Pure' object has no attribute 'time'

I will leave some review comments.

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Martin Panter

Martin Panter added the comment:

The doc string in the C module needs updating.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Please can I have an update on this? It's already 4 months old, I'd like to see 
it closed. :)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread STINNER Victor

Changes by STINNER Victor :


--
nosy: +matrixise

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

I think timespec= option should also be added to the time.isoformat method.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-12-15 Thread Alessandro Cucci

Alessandro Cucci added the comment:

Thanks for all the comments, here and on Rietveld. I'll keep working on it. 
Hope to upload a new patch soon.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-08-03 Thread Alessandro Cucci

Alessandro Cucci added the comment:

uploaded a new patch!

--
Added file: http://bugs.python.org/file40117/issue19475_v3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-07-30 Thread Berker Peksag

Berker Peksag added the comment:

Thanks, Alessandro! I left some additional comments on Rietveld: 
https://bugs.python.org/review/19475/#ps15278

--
nosy: +berker.peksag
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-07-26 Thread Alessandro Cucci

Alessandro Cucci added the comment:

udloaded a new patch, hope i had all bugs fixed!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-07-25 Thread Alessandro Cucci

Changes by Alessandro Cucci alessandro.cu...@gmail.com:


--
keywords: +patch
Added file: http://bugs.python.org/file40018/issue19475.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-07-25 Thread STINNER Victor

STINNER Victor added the comment:

@acucci: Nice first try, but your patch contains multiple bugs.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-07-25 Thread Alessandro Cucci

Alessandro Cucci added the comment:

@haypo thanks for the review and the suggestions, I'll correct the code soon

--
nosy: +acucci

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-07-25 Thread Alessandro Cucci

Changes by Alessandro Cucci alessandro.cu...@gmail.com:


Added file: http://bugs.python.org/file40024/issue19475_v2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19475] Add timespec optional flag to datetime isoformat() to choose the precision

2015-07-24 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
title: Add microsecond flag to datetime isoformat() - Add timespec optional 
flag to datetime isoformat() to choose the precision

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19475
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com