Handler::Delta(3)

๐Ÿ“ฆ
version 1.2 ยท 3 versions
, in fedora 43

๐Ÿฆ‹ NAME ๐Ÿฆ‹

okay bestie, welcome to Handler::Delta(3) ๐Ÿ’… โ€” aka Date::Handler::Delta, the Time lapse object โœจ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

no thoughts, just vibes, and also code:

  use Date::Handler::Delta;

   my $delta = new Date::Handler::Delta([3,1,10,2,5,5]);
   my $delta = new Date::Handler::Delta({
                                                        years => 3,
                                                        months => 1,
                                                        days => 10,
                                                        hours => 2,
                                                        minutes => 5,
                                                        seconds => 5,
                                                });

   $delta->new                          (More information in perldoc Date::Handler::Delta)
   $delta->Months()                     Number of months in delta
   $delta->Seconds()                    Number of seconds in delta
   $delta->AsScalar()                   "%d months and %d seconds"
   $delta->AsNumber()                   "%d-%d-%d"
   $delta->AsArray()                    [y,m,ss]
   $delta->AsHash()                     { months => m, seconds => ss }

   $date + $delta = Date::Handler
   $date - $delta = Date::Handler
   $date - $date2 = Date::Handler::Delta
   $date + n = (+n seconds)
   $date - n = (-n seconds)

   $delta + $delta = Date::Handler::Delta
   $delta - $delta = Date::Handler::Delta
   $delta * n = Date::Handler::Delta
   $delta / n = Date::Handler::Delta
   $delta + n = (+n seconds)
   $delta - n = (-n seconds)

like, look at all that math going on. it's giving calculator but make it fashion ๐Ÿงฎโœจ


๐ŸŽ€ DESCRIPTION ๐ŸŽ€

Date::Handler::Delta is an object that represents a lapse of time. a whole chunk of time, just vibing as a little object ๐Ÿ•ฐ๏ธ

its internal representation of a time lapse is reduced to months and seconds. that's it. that's the whole personality.

and here's the important part, bestie: a Date::Handler::Delta object is always relative to a Date::Handler object. its calculation methods don't wake up until the delta gets applied to a date. so it's lowkey just sitting there, waiting for its moment, main character energy, until you hand it a date. then it slays ๐Ÿ”ฅ


๐Ÿ’œ IMPLEMENTATION ๐Ÿ’œ

implementation details, come get y'all juice ๐Ÿงƒ

โœจ Creating a Date::Handler::Delta object โœจ

the new() constructor receives only one argument, and it has to be an array reference or a hash reference:

        my $delta = Date::Handler::Delta->new([1,3,5,0,0]);
        my $delta = Date::Handler::Delta->new({
                                                years => 1,
                                                months => 3,
                                                days => 5,
                                                minutes= > 0,
                                                seconds => 0,
                                        });
โš ๏ธ yes, that minutes= > 0 is exactly how it's written up in here, space and all. copying it character-for-character because that's the rule and also because we respect the source ๐Ÿ’…
  • As array reference, the order if years, months, days, minutes seconds
  • As hash reference, the keys are years, months, days, minutes, seconds.

so like, pick your fighter: array or hash. both valid, both iconic ๐Ÿซถ

๐ŸŒˆ Accessors ๐ŸŒˆ

you can access the data inside the object using any of the provided methods. these methods are detailed in the SYNOPSIS up above. yes, scroll up, they're right there, go look ๐Ÿ‘€

since Date::Handler uses operator overloading, you can 'apply' a Delta object on an absolute date simply by using built-in operators. no fancy method calls, just math. periodt โœจ

Example:

        #A Delta of 1 year.
        my $delta = new Date::Handler::Delta([1,0,0,0,0,0]);

        my $date = new Date::Handler({ date => time } );

        #$newdate is now one year in the furure.
        my $newdate = $date+$delta;

(and yes, "furure" โ€” that's the original's spelling, we keep it, we treasure it ๐Ÿ™ˆ)

๐Ÿฆ„ Operator overload special cases ๐Ÿฆ„

the Date::Handler overloaded operator have special cases. refer to the SYNOPSIS to get a description of each overloaded operator's behaviour.

one special case of the overload is when adding an integer n to a Date::Handler's reference. this is treated as if n was in seconds. same thing for substraction. so n is never, like, days. it's seconds. do not be fooled, bestie โฑ๏ธ

Example Uses of the overload:

        my $date = new Date::Handler({ date =>
                                        {
                                                year => 2001,
                                                month => 5,
                                                day => 14,
                                                hour => 5,
                                                min => 0,
                                                sec => 0,
                                        }});
        #Quoted string overload
        print "Current date is $date\n";

        my $delta = new Date::Handler::Delta({ days => 5, });

        #'+' overload, now, $date is 5 days in the future.
        $date += $delta;

        #Small clock. Not too accurate, but still ;)
        while(1)
        {
                #Add one second to the date. (same as $date + 1)
                $date++;
                print "$date\n";
                sleep(1);
        }

a whole little clock. not too accurate, but still ๐Ÿ˜Œ๐Ÿ• we love a humble icon.


๐Ÿ’€ BUGS (known) ๐Ÿ’€

๐Ÿšจ listen up, this is the important part ๐Ÿšจ

deltas going after 2038 are not handled by this module yet. (POSIX)

deltas before 1902 are not handled by this module. (POSIX)

so like, 1902 to 2038. that's the window. outside of it? no cap, it's not handled. plan accordingly bestie ๐Ÿ˜ญ

if you find bugs with this module, do not hesitate to contact the author. your comments and rants are welcomed :) โ€” yes, rants. they WANT your rants. go off, king ๐Ÿ‘‘


๐Ÿ“ TODO ๐Ÿ“

refine reduction to simplest expression of the delta.

that's it. one item. short and mysterious. it's giving "we'll get to it" โœจ


Copyright(c) 2001 Benoit Beausejour <bbeausej@pobox.com>

All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Portions Copyright (c) Philippe M. Chiasson <gozer@cpan.org>

Portions Copyright (c) Szabรณ, Balรกzs <dlux@kapu.hu>

Portions Copyright (c) Larry Rosler


๐ŸŒŸ AUTHOR ๐ŸŒŸ

Benoit Beausejour <bbeausej@pobox.com>


๐Ÿ” SEE ALSO ๐Ÿ”

  • Date::Handler(1).
  • Date::Handler::Range(1).
  • Class::Date(1).
  • Time::Object(1).
  • Date::Calc(1).
  • perl(1).

and that's the whole page, bestie ๐Ÿ’– this was Handler::Delta(3) from perl v5.42.0, dated 2025-07-25 โ€” literally the version and the date, right here, in a cute little sign-off, because we always cite our sources ๐ŸŽ€โœจ go forth and compute your deltas responsibly ๐Ÿฆ‹๐Ÿ’…

๐Ÿ“ฆ where this page comes from