Date & Time Literals

Published: 2021-09-16
Discussion on: Acmion (on this website), or Reddit.

Nearly all programming languages feature literals for a multitude of data types, but support for date and time literals is very rare at the least. However, such literals could provide certain benefits.

Some examples of literals used in "real world" programming languages:

int_literal    = 0
float_literal  = 0.0f
string_literal = "Hello world"
list_literal   = [ 1, 2, 3 ]
object_literal = { a = 1, b = 2, c = "hello" }

A potential date and time literal syntax:

time = <18:12:57.89>
date = <2021-09-16>
time_zone = <+01:00>
time_zone_region <us/pacific>

date_time = <2021-09-16 18:12:57.89>
date_time_zone = <2021-09-16 18:12:57.89 +01:00>
date_time_zone_region = <2021-09-16 18:12:57.89 us/pacific>

interpolated_date_time_zone_region = <@date @time @time_zone_region>

The motivation behind this is that one would not have to depend on certain imported or global functions or constructors to create relatively widely used data types. For example, few if any programming languages, require the following declaration for integers: i = new int(1). Additionally, in the name of consistency one could define literals for all of the most basic data types (ints, floats, lists, dicts, objects, etc.).

This would not only be a nice feature in a programming language, but also in a separate serialization format. For example, how does JSON serialize dates? The answer is as strings, but this is quite an error prone approach. Certain languages even default to using strings as dates (or maybe its just the programmers that use strings for convenience), which is also quite problematic.

Maybe this will someday be implemented more widely in existing programming languages.


Discuss this post here! You may also discuss it on or Reddit.

Post a Comment

Error! Incorrect value.
Note: Commenting is completely anonymous, thus, comments can not be edited.

No one has posted a comment yet. Be the first one to comment!