DateTime-Lite

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN

        - SQLite >= 3.35.0 (2021-03-12): pragma_function_list is queried for 'sqrt'.
          The check runs before any UDF is registered, so a hit is guaranteed to be a
          native function. A miss means the build omitted -DSQLITE_ENABLE_MATH_FUNCTIONS;
          Perl UDFs are registered as fallback.
        - SQLite >= 3.16.0 and < 3.35.0: pragma_function_list exists but the math
          functions cannot be present regardless of the build flags;
          Perl UDFs are registered unconditionally without querying the pragma.
        - SQLite < 3.16.0: pragma_function_list is not available as a table-valued
          function, so Perl UDFs are registered unconditionally.
      UDFs via sqlite_create_function() are available on all SQLite >= 3.0.0, so
      coordinate-based timezone resolution now works transparently on all supported
      SQLite versions.
      Reported via CPAN Testers on Perl 5.20.0, 5.22.2 and 5.24.0 on x86_64-linux
      (Debian Wheezy, system SQLite < 3.16.0).
      Thanks to Slaven Rezić for the detailed test reports.
    - Added .gitlab-ci.yml. The pipeline covers Perl 5.10.1 through 5.40 on Linux,
      plus a dedicated job that builds SQLite 3.15.2 from the official autoconf tarball
      (the last release before 3.16.0) to ensure the unconditional UDF registration path
      is exercised in CI.

v0.6.0 2026-04-17T22:30:20+0900

README  view on Meta::CPAN


            my $dt = DateTime::Lite->now( locale => 'en' );    # simple form
            my $dt = DateTime::Lite->now( locale => 'en-GB' ); # simple form
            # And more complex forms too
            my $dt = DateTime::Lite->now( locale => 'he-IL-u-ca-hebrew-tz-jeruslm' );
            my $dt = DateTime::Lite->now( locale => 'ja-Kana-t-it' );
            my $dt = DateTime::Lite->now( locale => 'ar-SA-u-nu-latn' );

        Locale data is resolved dynamically by DateTime::Locale::FromCLDR
        via Locale::Unicode::Data, so tags like
        "he-IL-u-ca-hebrew-tz-jeruslm" or "ja-Kana-t-it" work transparently
        without any additional installed modules.

        Additionally, if the locale tag carries a Unicode timezone extension
        ("-u-tz-"), and no explicit "time_zone" argument is provided to the
        constructor, "DateTime::Lite" will automatically resolve the
        corresponding IANA canonical timezone name from it:

            # time_zone is inferred as 'Asia/Jerusalem' from the -u-tz-jeruslm extension
            my $dt = DateTime::Lite->now( locale => 'he-IL-u-ca-hebrew-tz-jeruslm' );
            say $dt->time_zone;            # Asia/Jerusalem

README.md  view on Meta::CPAN


    `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
        my $dt = DateTime::Lite->now( locale => 'en-GB' ); # simple form
        # And more complex forms too
        my $dt = DateTime::Lite->now( locale => 'he-IL-u-ca-hebrew-tz-jeruslm' );
        my $dt = DateTime::Lite->now( locale => 'ja-Kana-t-it' );
        my $dt = DateTime::Lite->now( locale => 'ar-SA-u-nu-latn' );

    Locale data is resolved dynamically by [DateTime::Locale::FromCLDR](https://metacpan.org/pod/DateTime%3A%3ALocale%3A%3AFromCLDR) via [Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData), so tags like `he-IL-u-ca-hebrew-...

    Additionally, if the locale tag carries a [Unicode timezone extension](https://metacpan.org/pod/Locale%3A%3AUnicode#Unicode-extensions) (`-u-tz-`), and no explicit `time_zone` argument is provided to the constructor, `DateTime::Lite` will automat...

        # time_zone is inferred as 'Asia/Jerusalem' from the -u-tz-jeruslm extension
        my $dt = DateTime::Lite->now( locale => 'he-IL-u-ca-hebrew-tz-jeruslm' );
        say $dt->time_zone;            # Asia/Jerusalem
        say $dt->time_zone_long_name;  # Asia/Jerusalem

    An explicit `time_zone` argument always takes priority over the locale extension.

lib/DateTime/Lite.pm  view on Meta::CPAN


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
    my $dt = DateTime::Lite->now( locale => 'en-GB' ); # simple form
    # And more complex forms too
    my $dt = DateTime::Lite->now( locale => 'he-IL-u-ca-hebrew-tz-jeruslm' );
    my $dt = DateTime::Lite->now( locale => 'ja-Kana-t-it' );
    my $dt = DateTime::Lite->now( locale => 'ar-SA-u-nu-latn' );

Locale data is resolved dynamically by L<DateTime::Locale::FromCLDR> via L<Locale::Unicode::Data>, so tags like C<he-IL-u-ca-hebrew-tz-jeruslm> or C<ja-Kana-t-it> work transparently without any additional installed modules.

Additionally, if the locale tag carries a L<Unicode timezone extension|Locale::Unicode/"Unicode extensions"> (C<-u-tz->), and no explicit C<time_zone> argument is provided to the constructor, C<DateTime::Lite> will automatically resolve the correspon...

    # time_zone is inferred as 'Asia/Jerusalem' from the -u-tz-jeruslm extension
    my $dt = DateTime::Lite->now( locale => 'he-IL-u-ca-hebrew-tz-jeruslm' );
    say $dt->time_zone;            # Asia/Jerusalem
    say $dt->time_zone_long_name;  # Asia/Jerusalem

An explicit C<time_zone> argument always takes priority over the locale extension.

lib/DateTime/Lite/PP.pm  view on Meta::CPAN

=encoding utf8

=head1 NAME

DateTime::Lite::PP - Pure-Perl fallback for the DateTime::Lite XS layer

=head1 DESCRIPTION

This module is loaded automatically by L<DateTime::Lite> when the XS shared object cannot be loaded, such as when the distribution was installed without a C compiler, or when the environment variable C<PERL_DATETIME_LITE_PP> is set to a true value.

All functions defined here are injected directly into the C<DateTime::Lite> namespace so that callers see them transparently as methods.

You should not normally load or call this module directly.

=head1 VERSION

    v0.1.0

=head1 SEE ALSO

L<DateTime::Lite>

lib/DateTime/Lite/TimeZone.pm  view on Meta::CPAN


    # The bundled database lives next to this file
    {
        my( $vol, $parent, $file ) = File::Spec->splitpath( __FILE__ );
        $DB_FILE = File::Spec->catpath( $vol, $parent, 'tz.sqlite3' );
        $DB_FILE = File::Spec->rel2abs( $DB_FILE )
            unless( File::Spec->file_name_is_absolute( $DB_FILE ) );
    }

    # Detect whether DBD::SQLite is available. If not, we fall back to
    # DateTime::TimeZone transparently.
    $FALLBACK_TO_DT_TZ = 0;
    local $@;
    eval
    {
        require DBI;
        require DBD::SQLite;
    };
    if( $@ )
    {
        warn( "DateTime::Lite::TimeZone: DBD::SQLite not available, falling back to DateTime::TimeZone. Install DBD::SQLite for a lighter footprint." ) if( warnings::enabled( 'DateTime::Lite' ) );

lib/DateTime/Lite/TimeZone.pm  view on Meta::CPAN

Local time type records from the TZif files

=item C<zones>

Canonical IANA zone names with country codes and coordinates

=back

=head2 Fallback mode

If L<DBD::SQLite> is not available, or the bundled C<tz.sqlite3> cannot be found, C<DateTime::Lite::TimeZone> falls back transparently to L<DateTime::TimeZone> and emits a one-time warning, if warning is permitted.

If L<DateTime::TimeZone> is not available, then it dies.

=head1 CONSTRUCTOR

=head2 new

    my $zone = DateTime::Lite::TimeZone->new( 'Asia/Tokyo' );
    my $zone = DateTime::Lite::TimeZone->new(
        name  => 'Asia/Tokyo',

lib/DateTime/Lite/TimeZone.pm  view on Meta::CPAN

        longitude => 139.745504,
    );
    say $tz->name;  # Asia/Tokyo

The resolution uses the reference coordinates stored in the IANA C<zone1970.tab> file (one representative point per canonical zone) and finds the nearest zone by the L<haversine great-circle distance|https://en.wikipedia.org/wiki/Haversine_formula>. ...

C<latitude> must be in the range C<-90> to C<90>; C<longitude> in C<-180> to C<180>. An L<error object|DateTime::Lite::Exception> is set and C<undef> is returned in scalar context, or an empty list in list context, if the values are out of range or i...

The haversine formula is computed in SQLite when the database was compiled with C<-DSQLITE_ENABLE_MATH_FUNCTIONS> (SQLite version E<gt>= 3.35.0, L<released on March 2021|https://sqlite.org/changes.html>).

On older systems or builds where the math functions are absent, the required functions (C<sqrt>, C<sin>, C<cos>, C<asin>) are registered automatically as Perl UDFs (User Defined Functions) via L<DBD::SQLite/sqlite_create_function> on first use, so co...

Detection is version-aware. Thus:

=over 8

=item * on SQLite with version E<gt>= 3.35.0, the special système table C<pragma_function_list> is queried for C<sqrt> before any UDF is registered, to ensure a native function is used in priority.

=item * on SQLite with version E<lt> 3.35.0, where the math functions did not yet exist, UDFs are registered directly without querying C<pragma_function_list>.

=item * on SQLite version E<lt> 3.16.0, C<pragma_function_list> is not available as a table-valued function, so UDFs are registered directly.

=back

UDFs are available on all SQLite version E<gt>= 3.0.0.


On older systems that ships SQLite 3.31.1, the required functions (C<sqrt>, C<sin>, C<cos>, C<asin>) are registered automatically as Perl UDFs (User Defined Functions) via L<DBD::SQLite/sqlite_create_function> on first use, so coordinate resolution w...

=back

A boolean option C<use_cache_mem> set to a true value activates the process-level memory cache for this call. When set, subsequent calls with the same zone name (or its alias) return the cached object without a database query. See L</MEMORY CACHE> fo...

    # Each of these hits the cache after the first construction:
    my $tz = DateTime::Lite::TimeZone->new(
        name          => 'America/New_York',
        use_cache_mem => 1,
    );



( run in 2.779 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )