NAME

Date::Handler::Delta - Time lapse object

SYNOPSIS

  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)

DESCRIPTION

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

Implementation details

Creating a Date::Handler::Delta object

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.

Accessors

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;

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.

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

BUGS (known)

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 :)

TODO

Refine reduction to simplest expression of the delta.

COPYRIGHT

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).

1 POD Error

The following errors were encountered while parsing the POD:

Around line 459:

Non-ASCII character seen before =encoding in 'Szabó,'. Assuming CP1252