GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Handler::Delta(3) User Contributed Perl Documentation Handler::Delta(3)

Date::Handler::Delta - Time lapse object

  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)

Date::Handler::Delta is an object that represents a lapse of time. It's internal representation of a time lapse if reduced to months and seconds. A Date::Handler::Delta object is always relative to a Date::Handler object, it's calculation methods become active when the delta is applied to a date.

Implementation details

The new() constructor receives only one argument as an array reference or 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,
                                        });
  • As array reference, the order if years, months, days, minutes seconds
  • As hash reference, the keys are years, months, days, minutes, seconds.

You can access the data inside the object using any of the provided methods. These methods are detailed in the SYNOPSIS up above.

Since Date::Handler uses operator overloading, you can 'apply' a Delta object on an absolute date simply by using built-in operators.

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;

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.

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);
        }

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

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

If you find bugs with this module, do not hesitate to contact the author. Your comments and rants are welcomed :)

Refine reduction to simplest expression of the delta.

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

Benoit Beausejour <bbeausej@pobox.com>

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

Hey! The above document had some coding errors, which are explained below:
Around line 459:
Non-ASCII character seen before =encoding in 'Szabó,'. Assuming CP1252
2003-08-26 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.