view release on metacpan or search on metacpan
when use_cache_mem => 1 or enable_mem_cache() is set:
Layer 1 - object cache: TimeZone->new() returns the cached object
keyed by zone name and canonical name, bypassing SQLite entirely.
Layer 2 - span cache: _lookup_span() and _lookup_span_local() store
the last matched span boundaries per cached TZ object. Subsequent
calls within the same span return the cached result in ~0.5 us
instead of ~45 us (SQL query). SQL extended with utc_start/utc_end
and local_start/local_end columns for range checks.
Layer 3 - POSIX footer cache: For zones with a footer TZ string
(e.g. America/New_York), the DST rule calculation result is cached
by calendar day. Pre-check added BEFORE the SQL query so future
dates skip the database entirely on subsequent calls.
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
The XS layer covers all CPU-intensive calendar arithmetic
("_rd2ymd", "_ymd2rd", "_seconds_as_components", all leap-second
helpers), plus new functions not in the original: "_rd_to_epoch",
"_epoch_to_rd", "_normalize_nanoseconds", and "_compare_rd".
Compatible API
The public API mirrors DateTime as closely as possible, so existing
code using "DateTime" should work with "DateTime::Lite" as a drop-in
replacement.
Full Unicode CLDR / BCP 47 locale support
week_number
my $wn = $dt->week_number;
Returns the ISO 8601 week number (1-53).
week_year
my $wy = $dt->week_year;
Returns the year that the ISO 8601 week belongs to. This may differ from
"year" for days near the start or end of the calendar year.
quarter
my $q = $dt->quarter;
Returns the quarter of the year (1-4).
epoch
my $ts = $dt->epoch;
Returns the Unix timestamp (seconds since 1970-01-01T00:00:00 UTC) as an
Returns $self to allow chaining.
subtract_duration( $dur )
$dt->subtract_duration( $dur );
Subtracts a DateTime::Lite::Duration object from the datetime in-place
(mutates $self). Equivalent to "$dt->add_duration( $dur->inverse )".
subtract_datetime( $dt )
Returns a DateTime::Lite::Duration representing the difference between
two "DateTime::Lite" objects (calendar-aware).
subtract_datetime_absolute( $dt )
Returns a DateTime::Lite::Duration representing the absolute UTC
difference in seconds/nanoseconds.
delta_days( $dt )
my $dur = $dt1->delta_days( $dt2 );
printf "%d days apart\n", $dur->days;
Returns a DateTime::Lite::Duration containing only a "days" component
representing the number of whole days between $self and $dt.
delta_md( $dt )
my $dur = $dt1->delta_md( $dt2 );
Returns a DateTime::Lite::Duration with "months" and "days" components
(calendar-aware difference).
delta_ms( $dt )
my $dur = $dt1->delta_ms( $dt2 );
Returns a DateTime::Lite::Duration with "minutes" and "seconds"
components (absolute clock difference).
SETTERS
set
$dt->set( hour => 0, minute => 0, second => 0 );
my $p2 = q{'It is now' h 'o''clock' a}; # "It is now 9 o'clock AM"
Pattern length and padding
Most patterns pad with leading zeroes when the specifier is longer than
one character. For example, "h" gives 9 but "hh" gives 09. The exception
is that five of a letter usually means the narrow form, such as "EEEEE"
gives "T" for Thursday, not a five-character wide value.
Format vs. stand-alone forms
Many tokens have a *format* form (used inside a larger string) and a
*stand-alone* form (used alone, such as in a calendar header). They are
distinguished by case: "M" is format, "L" is stand-alone for months;
"E"/"e" is format, "c" is stand-alone for weekdays.
Token reference
Era
G{1,3} abbreviated era (BC, AD)
GGGG wide era (Before Christ, Anno Domini)
GGGGG narrow era
Year
y year, zero-padded as needed
yy two-digit year (special case)
Y{1,} week-of-year calendar year (from week_year)
u{1,} same as y, but yy is not special
Quarter
Q{1,2} quarter as number (1-4)
QQQ abbreviated format quarter
QQQQ wide format quarter
q{1,2} quarter as number (stand-alone)
qqq abbreviated stand-alone quarter
qqqq wide stand-alone quarter
# Interval formatting:
my $fmt2 = DateTime::Format::Unicode->new(
locale => 'en',
pattern => 'GyMMMd',
);
say $fmt2->format_interval( $dt1, $dt2 ); # e.g. "Apr 9 - 12, 2026"
HOW DATETIME MATH WORKS
Date math in "DateTime::Lite" follows the same model as DateTime. The
key distinction is between *calendar units* (months, days) and *clock
units* (minutes, seconds, nanoseconds). Understanding this distinction
is essential for correct results.
Duration buckets
A DateTime::Lite::Duration stores its components in five independent
*buckets*: months, days, minutes, seconds, nanoseconds. Each bucket is
kept as a signed integer. The buckets are not normalised against each
other: a duration of "{ months => 1, days => 31 }" is distinct from "{
months => 2, days => 0 }" because the number of days in a month varies.
Calendar vs. clock units
*Calendar units* (months, days) are relative: their real duration
depends on the datetime to which they are applied. *Clock units*
(minutes, seconds, nanoseconds) are absolute.
When add applies a duration, calendar units are applied first, then
clock units:
$dt->add( months => 1, hours => 2 );
# Step 1: advance by 1 month (calendar)
# Step 2: advance by 2 hours (clock)
End-of-month handling
Adding months to a date whose day is beyond the end of the target month
requires a policy decision. DateTime::Lite::Duration supports three
"end_of_month" modes:
* "wrap" (default) - wrap into the next month. January 31 + 1 month =
March 3 (or 2 in leap years).
* "limit" - clamp to the last day of the target month. January 31 + 1
month = February 28 (or 29 in leap years).
* "preserve" - like "limit", but remember that the original day was at
the end of month, so a further addition of one month will also land
on the last day.
Subtraction
"$dt1->subtract_datetime( $dt2 )" returns a duration representing the
difference. The calendar part is computed in months and days (from the
local dates), and the clock part in seconds and nanoseconds (from the
UTC representations). This is the most commonly useful result.
"$dt1->subtract_datetime_absolute( $dt2 )" returns a duration in pure
clock units (seconds and nanoseconds), based on the UTC epoch
difference. This is useful when you need an exact elapsed time
independent of DST changes.
Leap seconds
"DateTime::Lite" handles leap seconds when the time zone is not
`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 i...
`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 ...
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`, d...
- XS-accelerated hot paths
The XS layer covers all CPU-intensive calendar arithmetic (`_rd2ymd`, `_ymd2rd`, `_seconds_as_components`, all leap-second helpers), plus new functions not in the original: `_rd_to_epoch`, `_epoch_to_rd`, `_normalize_nanoseconds`, and `_compare_r...
- Compatible API
The public API mirrors [DateTime](https://metacpan.org/pod/DateTime) as closely as possible, so existing code using `DateTime` should work with `DateTime::Lite` as a drop-in replacement.
- Full Unicode CLDR / BCP 47 locale support
`DateTime` is limited to the set of pre-generated `DateTime::Locale::*` modules, one per locale. `DateTime::Lite` accepts any valid Unicode CLDR / BCP 47 locale tag, including complex forms with Unicode extensions (`-u-`), transform extensions (`...
my $dt = DateTime::Lite->now( locale => 'en' ); # simple form
## week\_number
my $wn = $dt->week_number;
Returns the ISO 8601 week number (1-53).
## week\_year
my $wy = $dt->week_year;
Returns the year that the ISO 8601 week belongs to. This may differ from ["year"](#year) for days near the start or end of the calendar year.
## quarter
my $q = $dt->quarter;
Returns the quarter of the year (1-4).
## epoch
my $ts = $dt->epoch;
Returns `$self` to allow chaining.
## subtract\_duration( $dur )
$dt->subtract_duration( $dur );
Subtracts a [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) object from the datetime in-place (mutates `$self`). Equivalent to `$dt->add_duration( $dur->inverse )`.
## subtract\_datetime( $dt )
Returns a [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) representing the difference between two `DateTime::Lite` objects (calendar-aware).
## subtract\_datetime\_absolute( $dt )
Returns a [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) representing the absolute UTC difference in seconds/nanoseconds.
## delta\_days( $dt )
my $dur = $dt1->delta_days( $dt2 );
printf "%d days apart\n", $dur->days;
Returns a [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) containing only a `days` component representing the number of whole days between `$self` and `$dt`.
## delta\_md( $dt )
my $dur = $dt1->delta_md( $dt2 );
Returns a [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) with `months` and `days` components (calendar-aware difference).
## delta\_ms( $dt )
my $dur = $dt1->delta_ms( $dt2 );
Returns a [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) with `minutes` and `seconds` components (absolute clock difference).
# SETTERS
## set
my $p1 = q{'Today is ' EEEE}; # "Today is Thursday"
my $p2 = q{'It is now' h 'o''clock' a}; # "It is now 9 o'clock AM"
## Pattern length and padding
Most patterns pad with leading zeroes when the specifier is longer than one character. For example, `h` gives `9` but `hh` gives `09`. The exception is that **five** of a letter usually means the narrow form, such as `EEEEE` gives `T` for Thursday, n...
## Format vs. stand-alone forms
Many tokens have a _format_ form (used inside a larger string) and a _stand-alone_ form (used alone, such as in a calendar header). They are distinguished by case: `M` is format, `L` is stand-alone for months; `E`/`e` is format, `c` is stand-alone fo...
## Token reference
Era
G{1,3} abbreviated era (BC, AD)
GGGG wide era (Before Christ, Anno Domini)
GGGGG narrow era
Year
y year, zero-padded as needed
yy two-digit year (special case)
Y{1,} week-of-year calendar year (from week_year)
u{1,} same as y, but yy is not special
Quarter
Q{1,2} quarter as number (1-4)
QQQ abbreviated format quarter
QQQQ wide format quarter
q{1,2} quarter as number (stand-alone)
qqq abbreviated stand-alone quarter
qqqq wide stand-alone quarter
# Interval formatting:
my $fmt2 = DateTime::Format::Unicode->new(
locale => 'en',
pattern => 'GyMMMd',
);
say $fmt2->format_interval( $dt1, $dt2 ); # e.g. "Apr 9 - 12, 2026"
# HOW DATETIME MATH WORKS
Date math in `DateTime::Lite` follows the same model as [DateTime](https://metacpan.org/pod/DateTime). The key distinction is between _calendar units_ (months, days) and _clock units_ (minutes, seconds, nanoseconds). Understanding this distinction is...
## Duration buckets
A [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) stores its components in five independent _buckets_: months, days, minutes, seconds, nanoseconds. Each bucket is kept as a signed integer. The buckets are **not n...
## Calendar vs. clock units
_Calendar units_ (months, days) are relative: their real duration depends on the datetime to which they are applied. _Clock units_ (minutes, seconds, nanoseconds) are absolute.
When [add](#add) applies a duration, calendar units are applied first, then clock units:
$dt->add( months => 1, hours => 2 );
# Step 1: advance by 1 month (calendar)
# Step 2: advance by 2 hours (clock)
## End-of-month handling
Adding months to a date whose day is beyond the end of the target month requires a policy decision. [DateTime::Lite::Duration](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ADuration) supports three `end_of_month` modes:
- `wrap` (default) - wrap into the next month. January 31 + 1 month = March 3 (or 2 in leap years).
- `limit` - clamp to the last day of the target month. January 31 + 1 month = February 28 (or 29 in leap years).
- `preserve` - like `limit`, but remember that the original day was at the end of month, so a further addition of one month will also land on the last day.
## Subtraction
`$dt1->subtract_datetime( $dt2 )` returns a duration representing the difference. The calendar part is computed in months and days (from the local dates), and the clock part in seconds and nanoseconds (from the UTC representations). This is the most ...
`$dt1->subtract_datetime_absolute( $dt2 )` returns a duration in pure clock units (seconds and nanoseconds), based on the UTC epoch difference. This is useful when you need an exact elapsed time independent of DST changes.
## Leap seconds
`DateTime::Lite` handles leap seconds when the time zone is not floating.
Adding a duration in clock units across a leap second boundary will correctly account for the extra second.
# SEE ALSO
lib/DateTime/Lite.pm view on Meta::CPAN
C<DateTime::TimeZone> derives its zone data from the IANA Olson I<source> files (C<africa>, C<northamerica>, etc.) via a custom text parser (C<DateTime::TimeZone::OlsonDB>), then pre-generates one C<.pm> file per zone at distribution build time. This...
C<DateTime::Lite::TimeZone> instead compiles the IANA source files with C<zic(1)>, which is the official IANA compiler, and reads the resulting TZif binary files directly, following L<RFC 9636|https://www.rfc-editor.org/rfc/rfc9636> (TZif versions 1 ...
Crucially, the POSIX footer TZ string embedded in every TZif v2+ file, such as C<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, C<DateTime::Lite::TimeZone> evaluates the footer rule via an XS implementation of the IANA C<tzcode> reference algorithm (see C<dtl_posix.h>, de...
=item XS-accelerated hot paths
The XS layer covers all CPU-intensive calendar arithmetic (C<_rd2ymd>, C<_ymd2rd>, C<_seconds_as_components>, all leap-second helpers), plus new functions not in the original: C<_rd_to_epoch>, C<_epoch_to_rd>, C<_normalize_nanoseconds>, and C<_compar...
=item Compatible API
The public API mirrors L<DateTime> as closely as possible, so existing code using C<DateTime> should work with C<DateTime::Lite> as a drop-in replacement.
=item Full Unicode CLDR / BCP 47 locale support
C<DateTime> is limited to the set of pre-generated C<DateTime::Locale::*> modules, one per locale. C<DateTime::Lite> accepts any valid Unicode CLDR / BCP 47 locale tag, including complex forms with Unicode extensions (C<-u->), transform extensions (C...
my $dt = DateTime::Lite->now( locale => 'en' ); # simple form
lib/DateTime/Lite.pm view on Meta::CPAN
=head2 week_number
my $wn = $dt->week_number;
Returns the ISO 8601 week number (1-53).
=head2 week_year
my $wy = $dt->week_year;
Returns the year that the ISO 8601 week belongs to. This may differ from L</year> for days near the start or end of the calendar year.
=head2 quarter
my $q = $dt->quarter;
Returns the quarter of the year (1-4).
=head2 epoch
my $ts = $dt->epoch;
lib/DateTime/Lite.pm view on Meta::CPAN
Returns C<$self> to allow chaining.
=head2 subtract_duration( $dur )
$dt->subtract_duration( $dur );
Subtracts a L<DateTime::Lite::Duration> object from the datetime in-place (mutates C<$self>). Equivalent to C<< $dt->add_duration( $dur->inverse ) >>.
=head2 subtract_datetime( $dt )
Returns a L<DateTime::Lite::Duration> representing the difference between two C<DateTime::Lite> objects (calendar-aware).
=head2 subtract_datetime_absolute( $dt )
Returns a L<DateTime::Lite::Duration> representing the absolute UTC difference in seconds/nanoseconds.
=head2 delta_days( $dt )
my $dur = $dt1->delta_days( $dt2 );
printf "%d days apart\n", $dur->days;
Returns a L<DateTime::Lite::Duration> containing only a C<days> component representing the number of whole days between C<$self> and C<$dt>.
=head2 delta_md( $dt )
my $dur = $dt1->delta_md( $dt2 );
Returns a L<DateTime::Lite::Duration> with C<months> and C<days> components (calendar-aware difference).
=head2 delta_ms( $dt )
my $dur = $dt1->delta_ms( $dt2 );
Returns a L<DateTime::Lite::Duration> with C<minutes> and C<seconds> components (absolute clock difference).
=head1 SETTERS
=head2 set
lib/DateTime/Lite.pm view on Meta::CPAN
my $p1 = q{'Today is ' EEEE}; # "Today is Thursday"
my $p2 = q{'It is now' h 'o''clock' a}; # "It is now 9 o'clock AM"
=head2 Pattern length and padding
Most patterns pad with leading zeroes when the specifier is longer than one character. For example, C<h> gives C<9> but C<hh> gives C<09>. The exception is that B<five> of a letter usually means the narrow form, such as C<EEEEE> gives C<T> for Thursd...
=head2 Format vs. stand-alone forms
Many tokens have a I<format> form (used inside a larger string) and a I<stand-alone> form (used alone, such as in a calendar header). They are distinguished by case: C<M> is format, C<L> is stand-alone for months; C<E>/C<e> is format, C<c> is stand-a...
=head2 Token reference
Era
G{1,3} abbreviated era (BC, AD)
GGGG wide era (Before Christ, Anno Domini)
GGGGG narrow era
Year
y year, zero-padded as needed
yy two-digit year (special case)
Y{1,} week-of-year calendar year (from week_year)
u{1,} same as y, but yy is not special
Quarter
Q{1,2} quarter as number (1-4)
QQQ abbreviated format quarter
QQQQ wide format quarter
q{1,2} quarter as number (stand-alone)
qqq abbreviated stand-alone quarter
qqqq wide stand-alone quarter
lib/DateTime/Lite.pm view on Meta::CPAN
# Interval formatting:
my $fmt2 = DateTime::Format::Unicode->new(
locale => 'en',
pattern => 'GyMMMd',
);
say $fmt2->format_interval( $dt1, $dt2 ); # e.g. "Apr 9 - 12, 2026"
=head1 HOW DATETIME MATH WORKS
Date math in C<DateTime::Lite> follows the same model as L<DateTime>. The key distinction is between I<calendar units> (months, days) and I<clock units> (minutes, seconds, nanoseconds). Understanding this distinction is essential for correct results.
=head2 Duration buckets
A L<DateTime::Lite::Duration> stores its components in five independent I<buckets>: months, days, minutes, seconds, nanoseconds. Each bucket is kept as a signed integer. The buckets are B<not normalised> against each other: a duration of C<< { months...
=head2 Calendar vs. clock units
I<Calendar units> (months, days) are relative: their real duration depends on the datetime to which they are applied. I<Clock units> (minutes, seconds, nanoseconds) are absolute.
When L<add|/add> applies a duration, calendar units are applied first, then clock units:
$dt->add( months => 1, hours => 2 );
# Step 1: advance by 1 month (calendar)
# Step 2: advance by 2 hours (clock)
=head2 End-of-month handling
Adding months to a date whose day is beyond the end of the target month requires a policy decision. L<DateTime::Lite::Duration> supports three C<end_of_month> modes:
=over 4
=item * C<wrap> (default) - wrap into the next month. January 31 + 1 month = March 3 (or 2 in leap years).
=item * C<limit> - clamp to the last day of the target month. January 31 + 1 month = February 28 (or 29 in leap years).
=item * C<preserve> - like C<limit>, but remember that the original day was at the end of month, so a further addition of one month will also land on the last day.
=back
=head2 Subtraction
C<< $dt1->subtract_datetime( $dt2 ) >> returns a duration representing the difference. The calendar part is computed in months and days (from the local dates), and the clock part in seconds and nanoseconds (from the UTC representations). This is the ...
C<< $dt1->subtract_datetime_absolute( $dt2 ) >> returns a duration in pure clock units (seconds and nanoseconds), based on the UTC epoch difference. This is useful when you need an exact elapsed time independent of DST changes.
=head2 Leap seconds
C<DateTime::Lite> handles leap seconds when the time zone is not floating.
Adding a duration in clock units across a leap second boundary will correctly account for the extra second.
=head1 SEE ALSO
lib/DateTime/Lite/Duration.pm view on Meta::CPAN
}
foreach my $unit ( @UNITS )
{
$self->{ $unit } += $dur->{ $unit };
}
$self->_normalise_nanoseconds;
return( $self );
}
sub calendar_duration
{
my $self = shift( @_ );
return( ref( $self )->new(
months => $self->{months},
days => $self->{days},
end_of_month => $self->{end_of_month},
) );
}
sub clock_duration
lib/DateTime/Lite/Duration.pm view on Meta::CPAN
$dur->delta_months; # signed months (years * 12 + months)
$dur->delta_days; # signed days
$dur->delta_minutes; # signed minutes (hours * 60 + minutes)
$dur->delta_seconds; # signed seconds
$dur->delta_nanoseconds; # signed nanoseconds
# All signed components at once
my %d = $dur->deltas; # keys: months days minutes seconds nanoseconds
# Calendar / clock sub-durations
my $cal = $dur->calendar_duration; # months + days only
my $clock = $dur->clock_duration; # minutes + seconds + nanoseconds only
# Arithmetic on durations
$dur->add( months => 1, days => 7 );
$dur->subtract( hours => 2 );
$dur->add_duration( $other_dur );
$dur->subtract_duration( $other_dur );
my $inverse = $dur->inverse; # negate all components
my $neg = $dur->inverse( end_of_month => 'wrap' );
lib/DateTime/Lite/Duration.pm view on Meta::CPAN
my $err = $dur->error;
=head1 VERSION
v0.1.0
=head1 DESCRIPTION
C<DateTime::Lite::Duration> is a lightweight port of L<DateTime::Duration>, used exclusively with L<DateTime::Lite>. It stores durations in five independent "buckets": C<months>, C<days>, C<minutes>, C<seconds>, and C<nanoseconds>.
The month/day buckets are C<calendar> units, whose real length depends on the date to which the duration is applied. The minute/second/nanosecond buckets are absolute (C<clock>) units.
Unlike L<DateTime>, C<DateTime::Lite> never calls C<die()> unexpectedly.
Errors set an exception object accessible via C<< $dur->error >> and return C<undef> in scalar context, or an empty list in list context. In chaining (object context), it returns a dummy object (C<DateTime::Lite::Null>) to avoid the typical C<Can't c...
=head1 CONSTRUCTOR
=head2 new( %args )
Accepted keys:
lib/DateTime/Lite/Duration.pm view on Meta::CPAN
=head1 METHODS
=head2 Accessors (absolute values)
C<years>, C<months>, C<weeks>, C<days>, C<hours>, C<minutes>, C<seconds>, C<nanoseconds> all return the absolute (unsigned) portion of the duration in the given unit, after stripping larger units. For instance C<months()> returns the months component...
=head2 Signed delta accessors
C<delta_months>, C<delta_days>, C<delta_minutes>, C<delta_seconds>, C<delta_nanoseconds> return the raw signed internal values.
=head2 calendar_duration / clock_duration
Return new duration objects containing only the calendar (months, days) or clock (minutes, seconds, nanoseconds) components respectively.
=head2 clone
Returns a shallow copy.
=head2 compare( $dur1, $dur2 )
Class method. Compares two durations unit by unit. Returns -1, 0, or 1.
=head2 deltas
lib/DateTime/Lite/Infinite.pm view on Meta::CPAN
# Mutating methods are no-ops on infinite objects
foreach my $m ( qw( set set_time_zone truncate ) )
{
no strict 'refs';
*{ 'DateTime::Lite::Infinite::' . $m } = sub{ return( $_[0] ) };
}
sub is_finite { 0 }
sub is_infinite { 1 }
# Override the XS/PP calendar decomposition to just propagate the
# infinity value through without any arithmetic
sub _rd2ymd
{
return( $_[2] ? ( $_[1] ) x 7 : ( $_[1] ) x 3 );
}
sub _seconds_as_components
{
return( ( $_[1] ) x 3 );
}
lib/DateTime/Lite/TimeZone.pm view on Meta::CPAN
Returns the new object on success. On error, sets the L<exception object|DateTime::Lite::Exception> with C<error()> and returns C<undef> in scalar context, or an empty list in list context. In method-chaining (object) context, returns a C<DateTime::L...
=head1 MEMORY CACHE
By default, each call to L</new> constructs a fresh object with a SQLite query. For applications that construct C<DateTime::Lite::TimeZone> objects repeatedly with the same zone name, a three-layer cache is available.
B<Layer 1 - Object cache>: When enabled, the second and subsequent calls for the same zone name return the original object directly from a hash, bypassing the database entirely.
B<Layer 2 - Span cache>: Each cached TimeZone object stores the last matched UTC and local time span. Calls to C<offset_for_datetime> and C<offset_for_local_datetime> skip the SQLite query when the timestamp falls within the cached span's C<[utc_star...
B<Layer 3 - POSIX footer cache>: For zones where current dates are governed by a recurring DST rule (POSIX TZ footer string), the result of the footer calculation is cached by calendar day. DST transitions happen twice a year; on all other days the c...
Together these three layers reduce the per-call cost of C<< DateTime::Lite->new( time_zone => 'America/New_York' ) >> from ~430 µs to ~25 µs, putting it on par with C<DateTime>.
Cache entries are keyed by the name passed to L</new>, plus the canonical name (after alias resolution). Both C<US/Eastern> and C<America/New_York> therefore map to the same cached object.
Cached objects are immutable in normal use. All public accessors are read-only, so sharing an object across callers is safe.
=head2 enable_mem_cache
Class method. Activates the memory cache for all subsequent L</new> calls.
t/05.duration.t view on Meta::CPAN
# NOTE: deltas() hash
subtest 'deltas() hash' => sub
{
my $dur = DateTime::Lite::Duration->new( days => 3, seconds => 10 );
my %d = $dur->deltas;
is( $d{days}, 3, 'deltas: days' );
is( $d{seconds}, 10, 'deltas: seconds' );
is( $d{months}, 0, 'deltas: months defaults to 0' );
};
# NOTE: calendar_duration / clock_duration
subtest 'calendar_duration / clock_duration' => sub
{
my $dur = DateTime::Lite::Duration->new(
months => 2, days => 5, hours => 3, seconds => 10
);
my $cal = $dur->calendar_duration;
is( $cal->delta_months, 2, 'calendar_duration: months' );
is( $cal->delta_days, 5, 'calendar_duration: days' );
is( $cal->delta_minutes, 0, 'calendar_duration: no minutes' );
my $clk = $dur->clock_duration;
is( $clk->delta_minutes, 180, 'clock_duration: minutes (3h)' );
is( $clk->delta_seconds, 10, 'clock_duration: seconds' );
is( $clk->delta_months, 0, 'clock_duration: no months' );
};
# NOTE: end_of_month modes
subtest 'end_of_month modes' => sub
{