On Apr 5, 2015, at 06:13, MRAB
On 2015-04-05 01:45, Alexander Belopolsky wrote:
On Sat, Apr 4, 2015 at 7:28 PM, MRAB
mailto:python@mrabarnett.plus.com> wrote: I am genuinely interested in the ways to improve date/time formatting in Python. There are certainly better ways than stftime. For example, ICU has a date/time format syntax that is much more readable: instead of "%Y-%m-%d %H:%M:%S", ICU format is "yyyy-MM-dd HH:mm:ss".
I don't think it is hard to find a way to introduce ICU format in datetime.__format__ while preserving backward compatibility. For example, we may require that % is always "escaped" as '%' in ICU format and the presence of unescaped % can trigger strftime interpretation.
[1] http://userguide.icu-project.org/formatparse/datetime
Personally, I prefer some kind of escaping, possibly in the style of .format, e.g. "{year}-{month}-{day} {hour}:{minute}:{second}". (It'll probably need a little tinkering to shorten it! :-))
Can someone explain to me why something like this or Anatoly's double-curly-brace variant is an improvement over
from datetime import * "{0.year}-{0.month}-{0.day} {0.hour}:{0.minute}:{0.second}".format(datetime.now()) '2015-4-4 20:43:23' Maybe it just needs the addition of attributes for '%A' and '%a' (name of day) and '%B' and '%b' (name of month).
It probably needs most of the fields in strftime. While some of them may only be there because one guy at one Unix company needed it one time, things like 12-hour time and AM/PM, tz offset, month abbreviation, week number, etc. are not exactly rare, just a little uncommon; it would less than ideal to write most of your program with format, but have to fall back to strftime a couple times with a comment explaining that datetime is insufficient. (On the other hand, it is nice that you can do things like 0 prefix the same as any other format element, instead of needing to remember separate codes for with and without prefix.)
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/