DP::Date - Date manipulation support
use DP::Date; ... ...
$DateObject = DP::Date->new( [ $Date_asString ] )
index of $DateObject [ blessed array ] 0 - date as string 1 - date as time() - secs since epoch 2 - weekday from local time 3 - yearday from local time
$Date_asString = $DateObject->asString( [ $SetDate_asString ] ) Get/Set string-of-numbers formatted value date-time value of B<$DateObject> to $SetDate_asString. B< $Date_asString > is string of date numbers without any punctuation, thus having the date-time '2003-12-24 20:00:00' produces date asString '20031224200000'
$Date_asTime = $DateObject->asTime( [ $setDate_asTime | time ] ) Get/Set date-time value of B<$DateObject> to $setDate_asTime. B< $Date_asTime > is compatible with perl's time(), ( eg. seconds elapsed since 1.1.1970? )
$Date_asISO = $DateObject->asISO( [ $setDate_asISO ] ) Get/Set ISO formatted date-time value of B<$DateObject> to $setDate_asTime. B< $Date_asISO > example: B<2003-12-24 20:00:00> ( no timezone, no 'T' letter as sometimes used 2003-12-24T20:00:00 )
# MUST be EXACTLY this format: 2002-12-24 12:34:56 (YYYY-MM-DD hh:mm:ss) # no checking, 2b faster =cut
sub asISO
{
my $self = shift();
my( $val ) = @_;
if( defined $val )
{
# MUST be EXACTLY this format: 2002-12-24 12:34:56 (YYYY-MM-DD hh:mm:ss)
# no checking, 2b faster
$self->asString( join('',unpack( 'A4xA2xA2xA2xA2xA2', $val )));
}
sprintf '%04d-%02d-%02d %02d:%02d:%02d', unpack( 'A4A2A2A2A2A2', $$self[0] );
}
$Date_asISO = $DateObject->GetAsISO() Get ISO formatted value of B<$DateObject> to $setDate_asTime. See also B<asISO()> method. =cut
sub GetAsISO
{
my $self = shift();
sprintf '%04d-%02d-%02d %02d:%02d:%02d', unpack( 'A4A2A2A2A2A2', $$self[0] );
}
@Date_array = $DateObject->GetAsISO() Get array of values of B<$DateObject> to $setDate_asTime, where @Date_array = ( $YYYY, $MM, $DD, $hh, $mm, $ss ) See also B<asISO()> method. =cut
sub GetAsArray
{
my $self = shift();
unpack( 'A4A2A2A2A2A2', $$self[0] );
}
$Date_asString = $DateObject->SetStringAtOffset( $offset, $newStringValue ) Example: want to change hour value of $DateObject
my $DateObject = DP::Date->new(); $DateObject->SetStringAtOffset( 8, '20' ); # initial date: 2003-12-24 12:34:56 $Date_asISO = $DateObject->GetAsISO(); # changed hour: 2003-12-24 20:34:56 Offsets: year...... 0 +4 month..... 4 +2 day....... 6 +2 hour...... 8 +2 min....... 10 +2 sec....... 12 +2
Get/Set
$DateObject->Year( [ $YYYY ] )
Get/Set
$MonthNr = $DateObject->Month( [ $Month_name_as_english_3letters_abbr ] )
Get/Set
$MonthNr = $DateObject->MonthNr( [ $Month_as_two_digits_based_JAN_eq_01 ] )
Get/Set
$Day = $DateObject->Day( [ $Day_of_month_as_two_digits ] )
Get/Set
$Hour = $DateObject->Hour( [ $Hour_as_two_digits ] )
Get/Set
$Minute = $DateObject->Minute( [ $Minute_as_two_digits ] )
Get/Set
$Second = $DateObject->Second( [ $Second_as_two_digits ] )
Get
$GetWeekDay = $DateObject->GetWeekDay
Get
$GetYearDay = $DateObject->GetYearDay
see source code, sorry
see source code, sorry
Compare $DateObject with $anotherDateObject
$bool = $DateObject->isSameDateAs( $anotherDateObject [, $comparingSize ] ) B< $comparingSize > is length of compared date-string .
see also asString and cmpString methods.
Get the time-value at which the specified month of the year begins. Very usefull! Values are cached as speed improvement.
$time_value = $DateObject->GetYearMonthBeginTime( $YYYY_or_YY_string, $MM_string ) see also B< asTime > method.
nothing
none
project started: 2002/06/04
$Id: Date.pm_rev 1.6 2003/12/12 11:00:15 root Exp root $
Daniel Peder <Daniel.Peder@InfoSet.COM> http://www.infoset.com Czech Republic national-flag: LeftSideBlueTriangleRightSideHorizontalSplitTopWhiteBottomRed
other date time modules at CPAN, http://www.CPAN.org