DateTime-Lite
view release on metacpan or search on metacpan
$dt->datetime;
$dt->ymd; # "2026-04-10"
$dt->ymd('/'); # "2026/04/10"
$dt->hms; # "06:10:30"
$dt->dmy('.'); # "10.04.2026"
$dt->mdy('-'); # "10-04-2026"
$dt->rfc3339; # "2026-04-10T06:10:30+09:00"
$dt->strftime('%Y-%m-%d %H:%M:%S'); # "2026-04-10 06:10:30"
$dt->format_cldr('yyyy/MM/dd'); # "2026/04/10" (Unicode CLDR pattern)
"$dt"; # stringify via iso8601 (or formatter)
# Arithmetic
$dt->add( years => 1, months => 2, days => 3,
hours => 4, minutes => 5, seconds => 6 );
$dt->subtract( weeks => 2 );
my $dur = DateTime::Lite::Duration->new( months => 6 );
$dt->add_duration( $dur );
$dt->subtract_duration( $dur );
my $diff = $dt->subtract_datetime( $other ); # Duration
my $abs_diff = $dt->subtract_datetime_absolute( $other ); # clock-only Duration
my $dd = $dt->delta_days( $other );
my $dmd = $dt->delta_md( $other );
my $dms = $dt->delta_ms( $other );
# Mutators
$dt->set( year => 2027, month => 1, day => 1 );
$dt->set_year(2027);
$dt->set_month(1);
$dt->set_day(1);
$dt->set_hour(0);
$dt->set_minute(0);
$dt->set_second(0);
$dt->set_nanosecond(0);
$dt->set_time_zone('America/New_York');
$dt->set_locale('en-US'); # sets a new DateTime::Locale::FromCLDR object
$dt->set_formatter( $formatter );
$dt->truncate( to => 'day' ); # 'year','month','week','day','hour','minute','second'
# Works for second, minute, hour, day, week, local_week, month, quarter,
# year, decade, century
$dt->end_of( 'month' );
say $dt; # 2026-04-30T23:59:59.999999999
$dt->start_of( 'month' );
say $dt; # 2026-04-01T00:00:00
# Comparison
my @sorted = sort { $a <=> $b } @datetimes; # overloaded <=>
DateTime::Lite->compare( $dt1, $dt2 ); # -1, 0, 1
DateTime::Lite->compare_ignore_floating( $dt1, $dt2 );
$dt->is_between( $lower, $upper );
# Class-level settings
DateTime::Lite->DefaultLocale('fr-FR');
my $class = $dt->duration_class; # 'DateTime::Lite::Duration'
# Constants
DateTime::Lite::INFINITY(); # +Inf
DateTime::Lite::NEG_INFINITY(); # -Inf
DateTime::Lite::NAN(); # NaN
DateTime::Lite::MAX_NANOSECONDS(); # 1_000_000_000
DateTime::Lite::SECONDS_PER_DAY(); # 86400
# Error handling
my $dt2 = DateTime::Lite->new( %bad_args ) ||
die( DateTime::Lite->error );
# Chaining: bad calls return a NullObject so the chain continues safely;
# check the return value of the last call in the chain.
my $result = $dt->some_method->another_method ||
die( $dt->error );
VERSION
v0.6.1
DESCRIPTION
"DateTime::Lite" is a lightweight, memory-efficient, drop-in replacement
for DateTime with the following design goals:
Low dependency footprint
Runtime dependencies are limited to: DateTime::Lite::TimeZone
(bundled SQLite timezone data, with automatic fallback to
DateTime::TimeZone if DBD::SQLite is unavailable),
DateTime::Locale::FromCLDR (locale data via Locale::Unicode::Data's
SQLite backend), Locale::Unicode, and core modules.
The heavy Specio, Params::ValidationCompiler, Try::Tiny, and
"namespace::autoclean" are eliminated entirely.
Low memory footprint
"DateTime" loads a cascade of modules which inflates %INC
significantly. "DateTime::Lite" avoids this via selective lazy
loading.
Accurate timezone data from TZif binaries
"DateTime::TimeZone" derives its zone data from the IANA Olson
*source* files ("africa", "northamerica", etc.) via a custom text
parser ("DateTime::TimeZone::OlsonDB"), then pre-generates one ".pm"
file per zone at distribution build time. This introduces an extra
parsing step that is not part of the official IANA toolchain.
"DateTime::Lite::TimeZone" instead compiles the IANA source files
with zic(1), which is the official IANA compiler, and reads the
resulting TZif binary files directly, following RFC 9636
<https://www.rfc-editor.org/rfc/rfc9636> (TZif versions 1 through
4). Timestamps are stored as signed 64-bit integers, giving a range
of roughly "+/-" 292 billion years.
Crucially, the POSIX footer TZ string embedded in every TZif v2+
file, such as "EST5EDT,M3.2.0,M11.1.0", is extracted and stored in
the SQLite database.
This string encodes the recurring DST rule for all dates beyond the
last explicit transition. At runtime, "DateTime::Lite::TimeZone"
evaluates the footer rule via an XS implementation of the IANA
"tzcode" reference algorithm (see "dtl_posix.h", derived from
"tzcode2026a/localtime.c", public domain), ensuring correct timezone
calculations for any date in the future without expanding the full
transition table.
XS-accelerated hot paths
( run in 2.065 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )