Posts in this category

Sun, 11 Apr 2010

A Perl 6 Date Module

Permanent link

The Perl 6 specification talks, among other things, about built-in date/time classes. After much discussions back and forth it is now (and is likely staying that way) a subset of the excellent Perl 5 module DateTime.

The discussions on the perl6-language mailing list showed that Dave Rolsky, author of DateTime, wants us to learn from the shortcomings of DateTime, in particular having a date-only class looks like a good idea to him.

That encouraged me to implement such a module. There's also prior art for that on CPAN: Date::Simple.

It's really simple, as the name says: You can construct a Date::Simple object either from year, month, day or from a string in the form YYYY-MM-DD, subtracting two dates yields an integer, adding or subtracting an integer to a date gives another date, you can ++ or -- date objects to get the next/previous day, and you can query date objects for year, month, day and day of week.

With some good literature at hand (and the Date::Simple test suite for inspiration) that's rather straight forward to implement, so that's what I did. I called it Date, and the code is on github.

It works to the extent possible by current Rakudo: all the object oriented features work, overloading operators doesn't quite work yet. Still the logic for the operators is already there, and once the bug in Rakudo is fixed, the Date module will be nearly fully implemented.

I enjoyed doing some solid work in this area of continued bikeshedding, and I'll wait and see if people want such a class in Perl 6 or not.

[/perl-6] Permanent link