Let's talk about Time::Moment and round-trip of strings

In my previous blog post I wrote a lot more about Time::Moment, than appeared in the post (could have been my mistake due to a preview and error and a incomplete copy and a paste, but still very inconvenient). So I have decided to break down my original blogpost in several blogposts.

Time::Moment implements a subset of ISO 8601 (known as 4.3 Date and time of day, 4.3.2 Complete representations), Wikipedia has a good article regarding ISO 8601, but it's not an authoritative source for the ISO 8601:2004(E) standard.

Time::Moment is capable of parsing any string that purports to be formatted in ISO 8601:2004(E), 4.3.2 Complete representation.

Such formats includes the following:

Combinations of calendar date and time of day:

Basic format:
20140808T003146+0200
20140808T003146.705971+0200
20140808T0031+0200

Extended format:
2014-08-08T00:31:46+02:00
2014-08-08T00:31:46.705971+02:00
2014-08-08T00:31+02:00

Combinations of ordinal date and time of day:

Basic format:
2014220T003146+0200
2014220T003146.705971+0200
2014220T0031+0200

Extended format:
2014-220T00:31:46+02:00
2014-220T00:31:46.705971+02:00
2014-220T00:31+02:00

Combinations of week date and time of day:

Basic format:
2014W325T003146+0200
2014W325T003146.705971+0200
2014W325T0031+0200

Extended format:
2014-W32-5T00:31:46+02:00
2014-W32-5T00:31:46.705971+02:00
2014-W32-5T00:31+02:00

All of the above ISO 8601 formats can be round-trip'ed with excellent performance using Time::Moment->from_string()


Benchmarking parsing: '2013-12-24T12:34:56.123456+02:00'
Rate DT::F::ISO8601 DT::F::RFC3339 Time::Moment
DT::F::ISO8601 6938/s -- -37% -100%
DT::F::RFC3339 11019/s 59% -- -100%
Time::Moment 2715276/s 39037% 24542% --

It's worth noting thatTime::Moment->from_string(Time::Moment->now) round-trip without loss off precision!

Leave a comment

About Christian Hansen

user-pic I blog about Perl.