NAME

DateTimeX::Lite - A Low Calorie DateTime

SYNOPSIS

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";
}

DESCRIPTION

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.

RATIONALE

The aim of this module is as follows:

(1) Target those who do not need the full feature of DateTime.pm.

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.

(2) Target the newbies who are afraid of XS code.

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.

(3) Get better performance.

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.

(4) Make it easy to install on rental servers.

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.

(5) Bundle everything in one distribution, including timezones and locales

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.

(6) Be compatible enough with DateTime.pm

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.

COMPATIBILITY WITH DateTime.pm

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

NOTABLE DIFFERENCES

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

Non-essential methods are loaded on demand

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

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.

METHODS

am_or_pm

ce_year

clone

compare

compare_ignore_floating

date

datetime

day

day_abbr

day_name

day_of_month

day_of_quarter

day_of_week

day_of_year

dmy

doq

dow

doy

epoch

formatter

fractional_second

from_day_of_year

from_epoch

from_object

hires_epoch

hms

hour

hour_1

hour_12

is_dst

is_finite

is_infinite

is_leap_year

iso8601

jd

last_day_of_month

leap_seconds

local_day_of_week

local_rd_as_seconds

local_rd_values

locale

mday

mdy

microsecond

millisecond

min

minute

mjd

mon

month

month_abbr

month_name

nanosecond

new

now

offset

quarter

quarter_abbr

quarter_name

sec

second

set

set_day

set_formatter

set_hour

set_locale

set_minute

set_month

set_nanosecond

set_second

set_time_zone

set_year

time

time_zone

time_zone_long_name

time_zone_short_name

to_datetime

today

truncate

utc_rd_as_seconds

utc_rd_values

wday

week

week_number

week_of_month

week_year

weekday_of_month

year

ymd

TODO

Make it possible to separate locales and time zones
Create an easy way to install new locales or time zones.
The files for timezones/locales may not be safe-to-load. need to check

AUTHOR

Original DateTime.pm:

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.

DateTimeX::Lite tweaks

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.