DateTime-Lite

 view release on metacpan or  search on metacpan

README.md  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](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.

- No die() in normal operation

    Following the [Module::Generic](https://metacpan.org/pod/Module%3A%3AGeneric) / [Locale::Unicode](https://metacpan.org/pod/Locale%3A%3AUnicode) error-handling philosophy, `DateTime::Lite` never calls `die()` in normal error paths.

    Instead it sets a [DateTime::Lite::Exception](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3AException) object and returns `undef` in scalar context, or an empty list in list context.

    However, if you really want this module to `die` upon error, you can pass the `fatal` option with a true value upon object instantiation.

# KNOWN DIFFERENCES FROM DateTime

- Validation

    `DateTime` uses [Specio](https://metacpan.org/pod/Specio) / [Params::ValidationCompiler](https://metacpan.org/pod/Params%3A%3AValidationCompiler) for constructor validation. `DateTime::Lite` performs equivalent checks manually. Error messages are...

- No warnings::register abuse

    `DateTime::Lite` uses `warnings::enabled` consistently and does not depend on the `warnings::register` mechanism for user-facing output.

# METHODS NOT IMPLEMENTED

None at this time. If you encounter a method missing from the [DateTime](https://metacpan.org/pod/DateTime) API, please file a report.

# CONSTRUCTORS

## new

Accepted parameters are:

- `year` (required)
- `month`
- `day`
- `hour`
- `minute`
- `second`
- `nanosecond`
- `time_zone`

    The time zone for the datetime. Accepts:

    - A zone name string, such as `Asia/Tokyo`, a fixed-offset string such as `+09:00`, `UTC`, `floating`, or `local`.
    - A [DateTime::Lite::TimeZone](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ATimeZone) object.
    - A hash reference whose keys are passed directly to ["new" in DateTime::Lite::TimeZone](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3ATimeZone#new). This allows passing options that are not available on the string form, such as `extended => 1...

            time_zone => { name => 'JST', extended => 1 }
            time_zone => { latitude => 35.658558, longitude => 139.745504 }

    If omitted, and the `locale` argument carries a BCP47 `-u-tz-` extension, such as `he-IL-u-ca-hebrew-tz-jeruslm`, the corresponding IANA canonical timezone is resolved automatically. If neither is provided, the default floating timezone is used (...

- `locale`

    Any valid locale as defined by the Unicode CLDR (Common Locale Data Repository), and BCP47. See [Locale::Unicode](https://metacpan.org/pod/Locale%3A%3AUnicode)

- `formatter`
- `fatal`

Returns the new object upon success, or sets an [error](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3AException) and returns `undef` in scalar context, or an empty list in list context. In chaining (object context), it returns a dummy object (`Dat...

## from\_day\_of\_year

    my $dt2 = DateTime::Lite->from_day_of_year(
        year        => 2026,
        day_of_year => 100,
        time_zone   => 'UTC',
        locale      => 'fr-FR',
    );

Constructs from a year and day-of-year (1-366).

Returns the new object upon success, or sets an [error](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3AException) and returns `undef` in scalar context, or an empty list in list context. In chaining (object context), it returns a dummy object (`Dat...

## from\_epoch

    my $dt = DateTime::Lite->from_epoch(
        epoch     => 1775769030,
        time_zone => 'Asia/Tokyo',
        locale    => 'ja-JP',
        formatter => $formatter,
    );

Constructs from a Unix epoch value (integer or float). Non-integer values are rounded to the nearest microsecond.

It accepts the `time_zone`, `locale`, and `formatter` parameters.

The returned object will be in the `UTC` time zone.

If you provide the `time_zone` argument, it will be applied _after_ the object is instantiated. Thus, the epoch value provided will always be set in the UTC time zone.

For example:

    my $dt = DateTime::Lite->from_epoch(
        epoch     => 0,
        time_zone => 'Asia/Tokyo'
    );
    say $dt; # Prints 1970-01-01T09:00:00 as Asia/Tokyo is +09:00 from UTC.
    $dt->set_time_zone('UTC');
    say $dt; # Prints 1970-01-01T00:00:00

Returns the new object upon success, or sets an [error](https://metacpan.org/pod/DateTime%3A%3ALite%3A%3AException) and returns `undef` in scalar context, or an empty list in list context. In chaining (object context), it returns a dummy object (`Dat...

## from\_object

    my $dt1 = DateTime->new;



( run in 0.735 second using v1.01-cache-2.11-cpan-1bcd28dbaf1 )