DateTi...::Epoch(3pm)
๐ DateTime::Format::Epoch ๐
okay bestie, welcome to DateTime::Format::Epoch (the 3pm perl doc, you know the vibe) โ the module that converts DateTimes to and from epoch seconds. it's giving time-travel but make it math. ๐ฐ๏ธโจ
โจ NAME โจ
DateTime::Format::Epoch โ literally just here to convert DateTimes to/from epoch seconds. that's the whole job. slay. ๐
๐ธ SYNOPSIS ๐ธ
use DateTime::Format::Epoch;
my $dt = DateTime->new( year => 1970, month => 1, day => 1 );
my $formatter = DateTime::Format::Epoch->new(
epoch => $dt,
unit => 'seconds',
type => 'int', # or 'float', 'bigint'
skip_leap_seconds => 1,
start_at => 0,
local_epoch => undef,
);
my $dt2 = $formatter->parse_datetime( 1051488000 );
# 2003-04-28T00:00:00
$formatter->format_datetime($dt2);
# 1051488000
see? cute. 1051488000 in, 2003-04-28T00:00:00 out, and back again. it's giving reversible. ๐
๐ฆ DESCRIPTION ๐ฆ
so basically this module takes a DateTime object (or literally any object that can be converted into a DateTime object, we're not picky ๐ซถ) and turns it into the number of seconds since a given epoch. and it can do the reverse too. both directions. iconic behaviour. ๐
๐ METHODS ๐
๐ new( ... )
the constructor of the formatter/parser object. it can take these parameters: epoch, unit, type, skip_leap_seconds, start_at, local_epoch and dhms. yes, all seven. keep up bestie. โจ
the epoch parameter is the only required one. it should be a DateTime object (or at least, it has to be convertible to a DateTime object). this datetime is the starting point of the day count, and is usually numbered 0. if you want to start at a different value, you can use the start_at parameter. no cap. ๐
the unit parameter can be "seconds", "milliseconds, "microseconds" or "nanoseconds". the default is "seconds". if you need any other unit, you must specify the number of units per second. and if you specify a number of units per second below 1, the unit will be longer than a second. so that's how you can count days:
unit => 1/86_400
math ate, honestly. ๐งฎ๐
the type parameter specifies the type of the return value. it can be "int" (returns integer value), "float" (returns floating point value), or "bigint" (returns Math::BigInt value). the default is either "int" (if the unit is "seconds"), or "bigint" (if the unit is "nanoseconds"). choose wisely, main character. โจ
the default behaviour of this module is to skip leap seconds. this is what (most versions of?) UNIX do. if you want to include leap seconds, set skip_leap_seconds to false. ๐
some operating systems use an epoch defined in the local timezone of the computer. if you want to use such an epoch in this module, you have two options, bestie:
- submit a
DateTimeobject with the appropriate timezone. - set the
local_epochparameter to a true value. in this case, you should submit an epoch with a floating timezone. the exact epoch used informat_datetimewill then depend on the timezone of the object you pass toformat_datetime.
most often, the time since an epoch is given in seconds. in some circumstances however it is expressed as a number of days, hours, minutes and seconds. this is done by NASA, for the so called Mission Elapsed Time. for example, 2/03:45:18 MET means it has been 2 days, 3 hours, 45 minutes, and 18 seconds since liftoff. ๐ if you set the dhms parameter to true, format_datetime returns a four element list, containing the number of days, hours, minutes and seconds, and parse_datetime accepts the same four element list. so like, a little listy bestie. ๐
๐ง format_datetime($datetime)
given a DateTime object, this method returns the number of seconds since the epoch. that's it. that's the method. ๐
โญ parse_datetime($secs)
given a number of seconds, this method returns the corresponding DateTime object. the reverse girlie. ๐
๐ BUGS ๐
"I think there's a problem when you define a count that does not skip leap seconds, and uses the local timezone. Don't do that."
that's a direct quote from the author and honestly? respect the honesty. don't do that. ๐ซ๐ฐ๏ธ
๐ SUPPORT ๐
support for this module is provided via the datetime@perl.org email list. see http://lists.perl.org/ for more details. go bother the mailing list, they're nice. ๐งโจ
๐ AUTHOR ๐
Eugene van der Pijll <pijll@gmx.net>
a legend. fr fr. ๐ซถ
๐ COPYRIGHT ๐
Copyright (c) 2003-2006 Eugene van der Pijll. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
๐ฆ SEE ALSO ๐ฆ
DateTimedatetime@perl.orgmailing list
and that's the whole page bestie!! this wasDateTi...::Epoch(3pm)fromperl v5.34.0, dated2022-06-13. periodt. ๐โจ๐๐ฆ๐ธ๐ ๐ซถ
๐ฆ where this page comes from
- debian bookworm: libdatetime-format-epoch-perl 0.16-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdatetime-format-epoch-perl 0.16-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdatetime-format-epoch-perl 0.16-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdatetime-format-epoch-perl 0.16-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdatetime-format-epoch-perl 0.16-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms