[Python-ideas] Date/time literals

Marcos Bonci marcos.bonci at gmail.com
Sun May 30 03:05:17 CEST 2010


Hi!

I've been working a lot with date/time variables lately, and maybe it's just
me, and
maybe I just don't get it yet, but it sure doesn't feel like there's
one-and-only-one
elegant, obvious way to work with them. Feels like working with strings in
C.

So I was thinking, have date and time literals ever been seriously
discussed anywhere
in these discussion lists? (If so, I apologize in advance for reviving this
subject.)

Is there any chance we could ever see date/time literals in Python? Perhaps
as a top-level
abstraction itself, or as a subclass of numbers.Number, or even as common
float or int
(by adding attributes regarding specific properties of a number's date/time
interpretation,
e.g. "<2010-12-31>.incr_month(2) == <2011-02-28>" -- just an example though,
i don't really
think this exact method would be practical).

If we adopt a standard like ISO 8601, then we automatically get
an unambiguous one-to-one
relationship between (date+time) and (amount of time elapsed from <epoch>),
over a continuous,
infinite domain (towards +inf and -inf). Very often the "time elapsed" value
is what we really
want (or at least the absolute difference between two values, which is of
course easier to find
in this form), and besides being more compact and flexible, no functionality
is lost.

I guess the most controversial point here would be the meaning of arithmetic
operations
between dates (or the very validity of such operations).

Another (not so obvious) problem is leap seconds (btw, who the hell invented
that?!..).
It's a weird and complicated problem, but I think it's not impossible to
turn this "complicated"
into just "complex", keeping the tricky concepts buried inside the
implementation.

Anyway, here's a couple of suggestions for a syntax:

2010.05.29 + 20.06.17
2010.05.29d + 20.06.17t

(just like complex literals)

So, what do you guys think? I'd love to hear others' opinions, even if it's
just for me
to understand what I got wrong and see the obvious way that's already there
:)

PS: Just for fun, is there a standard way I could experiment with creating
new types of literals?

-- Marcos --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100529/8e135d57/attachment.html>


More information about the Python-ideas mailing list