DateTimeX::Lite - A Low Calorie DateTime
use DateTimeX::Lite; my $dt = DateTimeX::Lite->new(year => 2008, month => 12, day => 1); $dt->year; $dt->month; $dt->day; $dt->hour; $dt->minuute; $dt->second; # Arithmetic doesn't come with DateTimeX::Lite by default use DateTimeX::Lite qw(Arithmetic); $dt->add( DateTimeX::Lite::Duration->new(days => 5) ); # Strftime doesn't come with DateTimeX::Lite by default use DateTimeX::Lite qw(Strftime); $dt->strftime('%Y %m %d'); # ZeroBase accessors doesn't come with DateTimeX::Lite by default use DateTimeX::Lite qw(ZeroBase); $dt->month_0; # Overloading is disabled by default use DateTimeX::Lite qw(Overload); print "the date is $dt\n"; if ($dt1 < $dt2) { print "dt1 is less than dt2\n"; }
This is a lightweight version of DateTime.pm, which requires no XS, and aims to be light(er) than the original, for a given subset of the problems that the original DateTime.pm can solve.
The idea is to encourage light users to use DateTime compatible API, while adapting to realistic environments (such as people without access to C compilers, people on rental servers who can't install modules, people who needs to convince pointy-haired bosses that they're not sacrificing performance), so later when they find engineering freedom, they can switch back to the more reliable DateTime.pm.
Please make no mistake: THIS IS NOT A REPLACEMENT FOR Datetime.pm. I will try to keep up with DateTime.pm, but DateTime.pm is the referece implementation. This is just stripped down version.
Please also note that internally, this module is a complete rip-off of the original DateTime.pm module. The author simply copied and pasted about 90% of the code, tweaked it and repackaged it. All credits go to the original DateTime.pm's authors.
The aim of this module is as follows:
In particular, I'm thinking of people who wants to simply grab a date, maybe do some date arithmetic on it, and print the year/month/date or store those values somewhere. These people do not use advanced date logic, sets, or calendars.
Let's face it, /we/ the developers know how to deal with XS. But we can't expect that out of everybody. DateTime.pm doesn't require XS, but to get decent performance it's sort of a requirement. We do our best to get there without XS.
In particular,
* Reduce the amount of memory consumed, and * Reduce the time it takes to load the module
Again, /we/ know why it's worth it to use DateTime. Some people don't, and will judge DateTime (and worse yet, maybe perl itself) unusable simply because it takes more memory to load DateTime. We want to avoid that.
This also ties into (2). No XS code, becuse compilers may not be available, or people simply wouldn't know how to use compilers.
If we can simply copy the DateTimeX::Lite files over via FTP instead of 'make install', that's even better.
This goes with (4). We like time zones and locales. However, we would like to limit the number of dependencies. It would be even better if we can choose which locales and timezones to install.
While given all of the above, we would like to leave a way for users to easily (relatively speaking) switch back to DateTime.pm, when they so choose to. Hence, the API needs to remain mostly compatible.
As stated elsewhere, DateTimeX::Lite does not intend to be a drop-in replacement for DateTime.pm.
You should not expect other DateTime::* modules (such as Format and Calendar) to work with it. It might, but we won't guarantee it.
We feel that if you use the extended features of the DateTime family, you should be using the original DateTime.pm
DateTimeX::Lite tries to be as compatible as possible with DateTime.pm, but there are a few places it deliberately changed from DateTime.pm. Some notable differences from DateTime.pm are as follows
For example, A lot of times you don't even need to do date time arithmetic. These methods are separated out onto a different file, so you need to load it on demand. To load, include "Arithmetic" in the use line.
use DateTimeX::Lite qw(Arithmetic);
Similarly, strftime() imposes a lot of code on DateTime. So if ymd(), iso8601() or the like is sufficient, it would be best not to load it. To load, include "Strftime" in the use line.
use DateTimeX::Lite qw(Strftime);
A lot of methods in original DateTime have aliases. They are not loaded unless you ask for them:
use DateTimeX::Lite qw(Aliases);
Zero-based accessors are also taken out of the core DateTimeX::Lite code.
use DateTimeX::Lite qw(ZeroBase);
Overload operators are also taken out. If you want to automatically compare or stringify two DateTimeX::Lite objects using standard operators, you need to include Overload:
use DateTimeX::Lite qw(Overload);
And finally, if you want every because you're using pretty much all of DateTime.pm but want to migrate, you can do
use DateTimeX::Lite qw(All);
DateTimeX::Lite::TimeZone and DateTimeX::Lite::Locale have big changes from their original counterparts.
First, you do NOT call new() on these objects (unless this is something you explicitly want to do). Instead, you need to call load(). So if you were mucking with DateTimeX::Lite::TimeZone and DateTime::Locale, you need to find out every occurance of
DateTime::TimeZone->new( name => 'Asia/Tokyo' );
and change them to
DateTimeX::Lite::TimeZone->load( name => 'Asia/Tokyo' );
Singletons are okay, they serve a particular purpose. But besides being a memory hog of relative low benefit, I've had claims from users questioning the benefit of timezones and locales when they saw that those two distributions installed hundreds of singleton classes.
With this version, the objects are just regular objects, and the exact definition for each timezone/locale is stored in data files. (TODO: They can be located anywhere DateTimeX::Lite can find them)
TODO: We want to make it easy to pick and choose which locales/timezones to be available -- DateTime::TimeZone and Locale comes with the full-set, and normally we don't need this feature. For example, I only use Asia/Tokyo and UTC time zones for my dayjob. When we ask casual users to install a datetime package, we do not want to overwhelm then with 100+ timezones and locales.
Copyright (c) 2003-2008 David Rolsky <autarch@urth.org>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
<autarch@urth.org>
Daisuke Maki <daisuke@endeworks.jp> This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
<daisuke@endeworks.jp>
To install DateTimeX::Lite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTimeX::Lite
CPAN shell
perl -MCPAN -e shell install DateTimeX::Lite
For more information on module installation, please visit the detailed CPAN module installation guide.