NAME

SIRTX::Datecode - module for interacting with SIRTX Datecodes

VERSION

version v0.04

SYNOPSIS

use SIRTX::Datecode;

This module provides support to convert between different date formats and SIRTX datecodes. SIRTX datecodes allow to encode dates in the range of years 1582 to 2440 into just 16 bits by using a variable precision. They also allow for numeric ordering over their full range.

This package inherits from Data::Identifier::Interface::Userdata (since v0.04), and Data::Identifier::Interface::Simple (experimental since v0.04).

METHODS

new

my SIRTX::Datecode $dc = SIRTX::Datecode->new($type => $value [, %opts ]);

Creates a new datecode object using $type and $value.

The following types are defined:

iso8601

An ISO-8601 date string (YYYY-MM-DD, YYYY-MM, or YYYY, all optionally suffixed with Z).

datecode

A datecode value (as integer).

epoch

An epoch value as returned by "time" in perlfunc.

The special value from is also supported as $type. If from is used an object can be passed that is automatically converted. In addition if the value is not reference (object) it is tried to be parsed as per iso8601. The special value now can be used to create an object for the current time. And the special value null to create an null-object (since v0.03).

Currently from supports at least the following types: SIRTX::Datecode (since v0.03), some Data::Identifier (since v0.03), DateTime (since v0.03), and any type that supports a epoch() method (since v0.03).

Currently no options are defined.

null

my SIRTX::Datecode $dc = SIRTX::Datecode->null;

(since v0.03)

Returns a null datecode.

Note: It is not defined if this method will always return the same object or create a new one each time.

See also: "is_null".

now

my SIRTX::Datecode $dc = SIRTX::Datecode->now;

(since v0.03)

Returns a new datecode object for the current time.

datecode

my $datecode = $dc->datecode;

Returns the datecode as an integer date code.

iso8601

my $iso8601 = $dc->iso8601;

Returns the datecode as an ISO-8601 date string.

as

my $res = $dc->as($as, %opts);

(experimental since v0.02)

This is a proxy for "as" in Data::Identifier.

is_utc

my $bool = $dc->is_utc;

(since v0.03)

Returns a true-ish value if the datecode is in UTC or a false-ish value if it is floating.

See also: "is_floating".

is_floating

my $bool = $dc->is_floating;

(since v0.03)

Returns a true-ish value if the datecode is floating or a false-ish value if it is in UTC.

See also: "is_utc".

is_null

my $bool = $dc->is_null;

(since v0.03)

Returns a true-ish value if the datecode is the null value and false-ish otherwise.

precision

my $precision = $dc->precision;

(since v0.03)

Returns the precision of the datecode. This is one of: null, year, month, or day.

year, month, day

my $year  = $dc->year( [ %opts ] );
my $month = $dc->month( [ %opts ] );
my $day   = $dc->day( [ %opts ] );

(since v0.04)

Returns the year, month, or day component individually.

If a value is not available those methods die.

The following options are supported:

default

A value that is returned if the value is not available. This can be set to undef to switch from dieing to returning undef.

no_defaults

Ignored. For compatibility with similar methods. May be supported in later releases.

AUTHOR

Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2025 by Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)