DateTime-Lite

 view release on metacpan or  search on metacpan

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

    unless( exists( $self->{utc_c}->{week_year} ) )
    {
        $self->{utc_c}->{week_year} = $self->_week_values;
    }
    return( @{$self->{utc_c}->{week_year}}[0, 1] );
}

sub week_number { ( $_[0]->week )[1] }

# ISO: first week of the month is the first week containing a Thursday.
# Direct formula - no clone, no add(), no recursion.
# NOTE: week_of_month is autoloaded

sub week_year { ( $_[0]->week )[0] }

# NOTE: weekday_of_month is autoloaded

sub year
{
    my $self = shift( @_ );
    return( $self->{local_c}->{year} );

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

        unless( $latitude >= -90 && $latitude <= 90 );
    return( $class->error( "Longitude must be between -180 and 180." ) )
        unless( $longitude >= -180 && $longitude <= 180 );

    my $sth;
    unless( $sth = $class->_get_cached_statement( 'nearest_zone' ) )
    {
        my $dbh = $class->_dbh || return( $class->pass_error );
        $class->_dbh_add_user_defined_functions( $dbh ) ||
            return( $class->pass_error );
        # Use the haversine formula entirely within SQLite to find the nearest zone.
        # Only canonical zones with coordinates are considered.
        # haversine(lat1, lon1, lat2, lon2):
        #   a = sin((lat2-lat1)/2)^2 + cos(lat1)*cos(lat2)*sin((lon2-lon1)/2)^2
        #   distance = 2 * asin(sqrt(a))
        # in radians; no need for Earth radius since we are only ranking, not computing
        # actual distance.
        my $query = <<'SQL';
SELECT
    name,
    (

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

=item Coordinates via C<latitude> and C<longitude> arguments.

As an alternative to a C<name>, you can pass decimal-degree coordinates to have C<DateTime::Lite::TimeZone> resolve the nearest IANA timezone automatically:

    my $tz = DateTime::Lite::TimeZone->new(
        latitude  => 35.658558,
        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 systeme 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>.

lib/DateTime/Lite/TimeZone/JA.pod  view on Meta::CPAN

=item C<latitude>およびC<longitude>引数による座標。

C<name>の代わりに10進度の座標を渡すことで、C<DateTime::Lite::TimeZone>に最も近いIANAタイムゾーンを自動解決させることができます。

    my $tz = DateTime::Lite::TimeZone->new(
        latitude  => 35.658558,
        longitude => 139.745504,
    );
    say $tz->name;  # Asia/Tokyo

解決にはIANAC<zone1970.tab>ファイルに保存された参照座標(正規ゾーンごとに1つの代表点)を使用し、L<haversine great-circle distance|https://en.wikipedia.org/wiki/Haversine_formula>により最も近いゾーンをæ...

C<latitude>はC<-90>からC<90>、C<longitude>はC<-180>からC<180>の範囲でなければなりません。値が範囲外である場合、またはデータベース内に座標付きゾーンが見つからない場合、L<エラーオブジェ...

haversine公式は、データベースがC<-DSQLITE_ENABLE_MATH_FUNCTIONS>付きでコンパイルされている場合、SQLite内で計算されます(SQLite version E<gt>= 3.35.0、L<2021å¹´3月リリース|https://sqlite.org/changes.html>)ã€...

古いシステム、または数学関数が存在しないビルドでは、必要な関数(C<sqrt>、C<sin>、C<cos>、C<asin>)が、初回使用時にL<DBD::SQLite/sqlite_create_function>経由でPerl UDF(User Defined Functions)としてè...

検出はバージョンを考慮して行われます。つまり:

=over 8



( run in 2.646 seconds using v1.01-cache-2.11-cpan-df04353d9ac )