The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Util::Medley::DateTime - Class with various datetime methods.

VERSION

version 0.061

SYNOPSIS

my $dt = Util::Medley::DateTime->new;

#
# positional  
#
say $dt->localDateTime(time);

#
# named pair
#
say $dt->localDateTime(epoch => time);
 

DESCRIPTION

A small datetime library. This doesn't do any calculations itself, but provides some simple methods to call for getting the date/time in commonly used formats.

ATTRIBUTES

none

METHODS

iso8601DateTime

Returns a iso8601-date-time string.

usage:
$dt->iso8601DateTime([$epoch]);

$dt->iso8601DateTime([epoch => $epoch]);
args:
epoch [Int]

Epoch time used to generate iso8601-date-time string. Default is now.

iso8601DateTimeToEpoch

Returns the epoch of a given iso8601-date-time string.

usage:
$dt->iso8601DateTimeToEpoch([$dateTime]);

$dt->iso8601DateTime([dateTime => $dateTime]);
args:
dateTime [Str]

An iso8601-date-time string.

localDateTime

Returns the local-date-time in the format: YYYY-MM-DD HH:MM:SS.

usage:
$dt->localDateTime([time]);

$dt->localDateTime([epoch => time]);
args:
time [Int]

Epoch time used to generate date/time string. Default is now.

localDateTimeAdd

Adds days, hours, mins, and/or secs to a local-date-time string.

usage:
$newDateTime = $dt->localDateTimeAdd($dateTime, [0, 1, 0, 0]);

$newDateTime = $dt->localDateTimeAdd( dateTime => $dateTime,
                                     [days     => 0],
                                     [hours    => 1],
                                     [mins     => 0],
                                     [secs     => 0]);
args:
dateTime [Str]

A local-date-time string.

days [Int]

Days to add.

hours [Int]

Hours to add.

mins [Int]

Minutes to add.

secs [Int]

Seconds to add.

localDateTimeToEpoch

Converts a local-date-time string to epoch.

usage:
$epoch = $dt->localDateTimeToEpoch($dateTime);

$epoch = $dt->localDateTimeToEpoch(dateTime => $dateTime);
args:
dateTime [Str]

The local-date-time string to convert.

localDateTimeIsValid

Validates the date-time string against: YYYY-MM-DD HH:MM:SS. Also, checks if it is actually a valid date-time.

usage:
$dt->localDateTimeIsValid($dateTime);

$dt->localDateTime(dateTime => $dateTime);
args:
dateTime [Str]

The date-time string to validate.

timeMs

Returns the current epoch in milliseconds.

usage:
$ms = $dt->timeMs;