Class::Date(3pm)
โจ Class::Date โ the manual page, bestie edition ๐
okay so. this is Class::Date(3pm) from the User Contributed Perl Documentation โ a whole class for easy date and time manipulation, and honestly? it ate. let's get into it, no skips, every single flag and line accounted for. ๐
๐ธ NAME ๐ธ
Class::Date โ a class for easy date and time manipulation. periodt.
๐ VERSION ๐
version 1.1.17 โ that's the one we're reading, bestie. ๐ฆ
โจ SYNOPSIS โจ
okay so here's the whole vibe in code. look at it, love it, don't skip a line, i will know. ๐
use Class::Date qw(:errors date localdate gmdate now -DateParse -EnvC);
# creating absolute date object (local time)
$date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec]);
$date = date [$year,$month,$day,$hour,$min,$sec];
# ^- "date" is an exportable function, the same as Class::Date->new
$date = date { year => $year, month => $month, day => $day,
hour => $hour, min => $min, sec => $sec };
$date = date "2001-11-12 07:13:12";
$date = localdate "2001-12-11";
$date = now; # the same as date(time)
$date = date($other_date_object); # cloning
...
# creating absolute date object (GMT)
$date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec],'GMT');
$date = gmdate "2001-11-12 17:13";
...
# creating absolute date object in any other timezone
$date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec],'Iceland' );
$date = date "2001-11-12 17:13", 'Iceland';
$date2 = $date->new([$y2, $m2, $d2, $h2, $m2, $s2]);
# ^- timezone is inherited from the $date object
# creating relative date object
# (normally you don't need to create this object explicitly)
$reldate = Class::Date::Rel->new( "3Y 1M 3D 6h 2m 4s" );
$reldate = Class::Date::Rel->new( "6Y" );
$reldate = Class::Date::Rel->new( $secs ); # secs
$reldate = Class::Date::Rel->new( [$year,$month,$day,$hour,$min,$sec] );
$reldate = Class::Date::Rel->new( { year => $year, month => $month, day => $day,
hour => $hour, min => $min, sec => $sec } );
$reldate = Class::Date::Rel->new( "2001-11-12 07:13:12" );
$reldate = Class::Date::Rel->new( "2001-12-11" );
# getting values of an absolute date object
$date; # prints the date in default output format (see below)
$date->year; # year, e.g: 2001
$date->_year; # year - 1900, e.g. 101
$date->yr; # 2-digit year 0-99, e.g 1
$date->mon; # month 1..12
$date->month; # same as prev.
$date->_mon; # month 0..11
$date->_month; # same as prev.
$date->day; # day of month
$date->mday; # day of month
$date->day_of_month;# same as prev.
$date->hour;
$date->min;
$date->minute; # same as prev.
$date->sec;
$date->second; # same as prev.
$date->wday; # 1 = Sunday
$date->_wday; # 0 = Sunday
$date->day_of_week; # same as prev.
$date->yday;
$date->day_of_year; # same as prev.
$date->isdst; # DST?
$date->daylight_savings; # same as prev.
$date->epoch; # UNIX time_t
$date->monname; # name of month, eg: March
$date->monthname; # same as prev.
$date->wdayname; # Thursday
$date->day_of_weekname # same as prev.
$date->hms # 01:23:45
$date->ymd # 2000/02/29
$date->mdy # 02/29/2000
$date->dmy # 29/02/2000
$date->meridiam # 01:23 AM
$date->ampm # AM/PM
$date->string # 2000-02-29 12:21:11 (format can be changed, look below)
"$date" # same as prev.
$date->tzoffset # timezone-offset
$date->strftime($format) # POSIX strftime (without the huge POSIX.pm)
$date->tz # returns the base timezone as you specify, eg: CET
$date->tzdst # returns the real timezone with dst information, eg: CEST
($year,$month,$day,$hour,$min,$sec)=$date->array;
($year,$month,$day,$hour,$min,$sec)=@{ $date->aref };
# !! $year: 1900-, $month: 1-12
($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=$date->struct;
($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=@{ $date->sref };
# !! $year: 0-, $month: 0-11
$hash=$date->href; # $href can be reused as a constructor
print $hash->{year}."-".$hash->{month}. ... $hash->{sec} ... ;
%hash=$date->hash;
# !! $hash{year}: 1900-, $hash{month}: 1-12
$date->month_begin # First day of the month (date object)
$date->month_end # Last day of the month
$date->days_in_month # 28..31
# constructing new date based on an existing one:
$new_date = $date->clone;
$new_date = $date->clone( year => 1977, sec => 14 );
# valid keys: year, _year, month, mon, _month, _mon, day, mday, day_of_month,
# hour, min, minute, sec, second, tz
# constructing a new date, which is the same as the original, but in
# another timezone:
$new_date = $date->to_tz('Iceland');
# changing date format
{
local $Class::Date::DATE_FORMAT="%Y%m%d%H%M%S";
print $date # result: 20011222000000
$Class::Date::DATE_FORMAT=undef;
print $date # result: Thu Oct 13 04:54:34 1994
$Class::Date::DATE_FORMAT="%Y/%m/%d"
print $date # result: 1994/10/13
}
# error handling
$a = date($date_string);
if ($a) { # valid date
...
} else { # invalid date
if ($a->error == E_INVALID) { ... }
print $a->errstr;
}
# adjusting DST in calculations (see the doc)
$Class::Date::DST_ADJUST = 1; # this is the default
$Class::Date::DST_ADJUST = 0;
# "month-border adjust" flag
$Class::Date::MONTH_BORDER_ADJUST = 0; # this is the default
print date("2001-01-31")+'1M'; # will print 2001-03-03
$Class::Date::MONTH_BORDER_ADJUST = 1;
print date("2001-01-31")+'1M'; # will print 2001-02-28
# date range check
$Class::Date::RANGE_CHECK = 0; # this is the default
print date("2001-02-31"); # will print 2001-03-03
$Class::Date::RANGE_CHECK = 1;
print date("2001-02-31"); # will print nothing
# getting values of a relative date object
$reldate; # reldate in seconds (assumed 1 month = 2_629_744 secs)
$reldate->year;
$reldate->mon;
$reldate->month; # same as prev.
$reldate->day;
$reldate->hour;
$reldate->min;
$reldate->minute; # same as prev.
$reldate->sec; # same as $reldate
$reldate->second; # same as prev.
$reldate->sec_part; # "second" part of the relative date
$reldate->mon_part; # "month" part of the relative date
# arithmetic with dates:
print date([2001,12,11,4,5,6])->truncate;
# will print "2001-12-11"
$new_date = $date+$reldate;
$date2 = $date+'3Y 2D'; # 3 Years and 2 days
$date3 = $date+[1,2,3]; # $date plus 1 year, 2 months, 3 days
$date4 = $date+'3-1-5' # $date plus 3 years, 1 months, 5 days
$new_date = $date-$reldate;
$date2 = $date-'3Y'; # 3 Yearss
$date3 = $date-[1,2,3]; # $date minus 1 year, 2 months, 3 days
$date4 = $date-'3-1-5' # $date minus 3 years, 1 month, 5 days
$new_reldate = $date1-$date2;
$reldate2 = Class::Date->new('2000-11-12')-'2000-11-10';
$reldate3 = $date3-'1977-11-10';
$days_between = (Class::Date->new('2001-11-12')-'2001-07-04')->day;
# comparison between absolute dates
print $date1 > $date2 ? "I am older" : "I am younger";
# comparison between relative dates
print $reldate1 > $reldate2 ? "I am faster" : "I am slower";
# Adding / Subtracting months and years are sometimes tricky:
print date("2001-01-29") + '1M' - '1M'; # gives "2001-02-01"
print date("2000-02-29") + '1Y' - '1Y'; # gives "2000-03-01"
# Named interface ($date2 does not necessary to be a Class::Date object)
$date1->string; # same as $date1 in scalar context
$date1->subtract($date2); # same as $date1 - $date2
$date1->add($date2); # same as $date1 + $date2
$date1->compare($date2); # same as $date1 <=> $date2
$reldate1->sec; # same as $reldate1 in numeric or scalar context
$reldate1->compare($reldate2);# same as $reldate1 <=> $reldate2
$reldate1->add($reldate2); # same as $reldate1 + $reldate2
$reldate1->neg # used for subtraction
# Disabling Class::Date warnings at load time
BEGIN { $Class::Date::WARNINGS=0; }
use Class::Date;
that's a lot of lines but every single one is doing its little job, and we respect them all. ๐
๐ DESCRIPTION ๐
so bestie, here's the tea. this module is intended to provide a general-purpose date and datetime type for perl. you've got a Class::Date class for absolute date and datetime, and you've got a Class::Date::Rel class for relative dates. two icons, both serving. ๐
you can use "+", "-", "<" and ">" operators as with native perl data types. yes, math with dates like it's nothing. it's giving main character energy fr fr. ๐ฅ
โ ๏ธ okay so important heads up, no cap: note that this module is fairly ancient and dusty. you might want to take a look at DateTime and its related modules for a more standard, and maintained, Perl date manipulation solution. this is not me being mean, this is the module itself being honest. ๐
and that's part 1, bestie โ there's more coming, so don't go anywhere. ๐ฆ
โจ USAGE โจ
okay bestie so if you actually wanna use a date object, here's the whole lil ritual:
- create a new object
- do some operations (
+,-, comparison) - get result back
๐ Creating a new date object
You can make a date object with the date, localdate or gmdate function, or by calling the Class::Date constructor. slay.
date and Class::Date->new are literally equivalent, and both take two arguments: the date and the timezone.
$date1= date [2000,11,12];
$date2= Class::Date->new([2000,06,11,13,11,22],'GMT');
$date2= $date1->new([2000,06,11,13,11,22]);
If you leave the timezone info out, then it first checks whether new got called as an object method or a class method. If it's an object method, it inherits the timezone from the base object ๐. Otherwise the default timezone is used ($Class::Date::DEFAULT_TIMEZONE), which is usually set to the local timezone (stored over in $Class::Date::LOCAL_TIMEZONE). These two variables get set only once, to the value returned by the Class::Date::local_timezone() function. You can change these values whenever you want tho ๐
localdate $x is equivalent to date $x, $Class::Date::LOCAL_TIMEZONE, and gmdate $x is equivalent to date $x, $Class::Date::GMT_TIMEZONE.
$Class::Date::GMT_TIMEZONE is set to 'GMT' by default.
$date1= localdate [2000,11,12];
$date2= gmdate [2000,4,2,3,33,33];
$date = localdate(time);
The format of the accepted input date can be:
[$year,$month,$day,$hour,$min,$sec]โ an array reference with 6 elements. The missing elements have default values (year: 2000, month, day: 1, hour, min, sec: 0){ year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec }โ a hash reference with the same 6 elements as above"YYYYMMDDhhmmss"โ a mysql-style timestamp value, which consists of at least 14 digits"973897262"โ a valid 32-bit integer; this is parsed as a unix time โจ"YYYY-MM-DD hh:mm:ss"โ a standard ISO(-like) date format. The additional.fractionpart is ignored, and the:sscan be omitted- additional input formats โ you can specify
-DateParseas an import parameter, like:
use Class::Date qw(date -DateParse);
With this, the module will try to load the Date::Parse module, and if it finds it then all these formats can be used as an input. Please go read the Date::Parse documentation bestie ๐
๐ซ Operations
๐ addition
You can add the following to a Class::Date object:
- a valid
Class::Date::Relobject - anything that can be used for creating a new
Class::Date::Relobject
Which means you do not need to create a new Class::Date::Rel object every single time you add something to a Class::Date object โ it creates them automatically for you ๐:
$date= Class::Date->new('2001-12-11')+Class::Date::Rel->new('3Y');
is the same as:
$date= date('2001-12-11')+'3Y';
You can provide a Class::Date::Rel object in the following form:
- array ref โ the same format as seen in
Class::Dateformat, except the default values are different: all zero. - hash ref โ the same format as seen in
Class::Dateformat, except the default values are different: all zero. "973897262"โ a valid 32-bit integer is parsed as seconds."YYYY-MM-DD hh:mm:ss"โ a standard ISO date format, but this is parsed as a relative date and time, so month, day and year can be zero (and default to zero)."12Y 6M 6D 20h 12m 5s"โ this special string can be used if you don't wanna use the ISO format. This string consists of whitespace separated tags, and each tag consists of a number and a unit. The units can be:
Y: year
M: month
D: day
h: hour
m: min
s: sec
The number and unit must be written with no space between them.
๐ฆ subtraction
The same rules are true for subtraction, except you can subtract two Class::Date objects from each other, and you will get a Class::Date::Rel object:
$reldate=$date1-$date2;
$reldate=date('2001-11-12 12:11:07')-date('2001-10-07 10:3:21');
In this case, the "month" field of the $reldate object will be 0, and the other fields will contain the difference between two dates;
๐ comparison
You can compare two Class::Date objects, or one Class::Date object and another piece of data which can be used for creating a new Class::Date object.
It means you don't need to bless both objects โ one of them can be a simple string, array ref, hash ref, etc (see how to create a date object).
if ( date('2001-11-12') > date('2000-11-11') ) { ... }
or
if ( date('2001-11-12') > '2000-11-11' ) { ... }
โ๏ธ truncate
You can chop the time value from this object (set hour, min and sec to 0) with the truncate or trunc method. It does not modify the specified object, it returns a new one ๐ซถ
๐ธ clone
You can create a new date object based on an existing one by using the clone method. Note, this DOES NOT modify the base object.
$new_date = $date->clone( year => 2001, hour => 14 );
The valid keys are: year, _year, month, mon, _month, _mon, day, mday, day_of_month, hour, min, minute, sec, second, tz.
There's also a set method which does the same as the clone โ it exists only for compatibility, no cap.
๐ง to_tz
You can use to_tz to create a new object, which means the same time as the base object, but in a different timezone.
Note that$date->clone( tz => 'Iceland')and$date->to_tz('Iceland')are not the same! Cloning a new object with the timezone set will preserve the time information (hour, minute, second, etc.), but transfer the time into the other timezone, whileto_tzusually changes these values based on the difference between the source and the destination timezone. iykyk ๐
๐ Operations with Class::Date::Rel
The Class::Date::Rel object consists of a month part and a day part. Most people only use the "day" part of it. If you use both parts, then you can get these parts with the sec_part and mon_part methods. If you use sec, month, etc. methods, or if you use this object in a mathematical context, then this object is converted to one number, which is interpreted as seconds. The conversion is based on a 30.436 days month. Don't use it too often, because it is confusing...
If you use Class::Date::Rel in an expression with other Class::Date or Class::Date::Rel objects, then it does what is expected:
date('2001-11-12')+'1M' will be '2001-12-12'
and
date('1996-02-11')+'2M' will be '1996-04-11'
๐ Accessing data from a Class::Date and Class::Date::Rel object
You can use the method methods described at the top of the document if you want to access parts of the data which is stored in a Class::Date and Class::Date::Rel object ๐
๐ญ Error handling
If a date object becomes invalid, then the object will be reblessed to Class::Date::Invalid. This object is false in a boolean environment, so you can test the date validity like this:
$a = date($input_date);
if ($a) { # valid date
...
} else { # invalid date
if ($a->error == E_INVALID) { ... }
print $a->errstr;
}
Note: even if the date is invalid, the expression defined $a always returns true, so the following is wrong:
$a = date($input_date);
if (defined $a) ... # WRONG!!!!
You can test the error by getting the $date->error value. You might import the :errors tag:
use Class::Date qw(:errors);
Possible error values are:
E_OKโ no errors. blessed.E_INVALIDโ invalid date. It's set when some of the parts of the date are invalid, andTime::Localfunctions cannot convert them to a valid date.E_RANGEโ this error is set when parts of the date are valid, but the whole date is not valid, e.g. 2001-02-31. When the$Class::Date::RANGE_CHECKis not set, then these date values are automatically converted to a valid date: 2001-03-03, but the$date->errorvalue is set toE_RANGE. If$Class::Date::RANGE_CHECKis set, then a date"2001-02-31"becomes an invalid date.E_UNPARSABLEโ this error is set when the constructor cannot be created from a scalar, e.g:
$a = date("4kd sdlsdf lwekrmk");
E_UNDEFINEDโ this error is set when you want to create a date object from an undefined value:
$a = Class::Date->new(undef);
Note that localdate(undef) will create a valid object, because it calls $Class::Date(time).
You can get the error in string form by calling the errstr method ๐
๐ DST_ADJUST ๐
$DST_ADJUST is an important configuration option.
If it's set to true (the default), then the module adjusts the date and time when the operation switches the border of DST. With this setting, you are ignoring the effect of DST.
When $DST_ADJUST is set to false, then no adjustment is done, and the calculation will be based on the exact time difference.
You'll see the difference through an example:
$Class::Date::DST_ADJUST=1;
print date("2000-10-29", "CET") + "1D";
# This will print 2000-10-30 00:00:00
print date("2001-03-24 23:00:00", "CET") + "1D";
# This will be 2001-03-25 23:00:00
print date("2001-03-25", "CET") + "1D";
# This will be 2001-03-26 00:00:00
$Class::Date::DST_ADJUST=0;
print date("2000-10-29", "CET") + "1D";
# This will print 2000-10-29 23:00:00
print date("2001-03-24 23:00:00", "CET") + "1D";
# This will be 2001-03-26 00:00:00
๐ MONTHS AND YEARS ๐
If you add or subtract "months" and "years" to a date, you may get wrong dates, e.g. when you add one month to 2001-01-31, you expect to get 2001-02-31, but this date is invalid and gets converted to 2001-03-03. That's why
date("2001-01-31") + '1M' - '1M' != "2001-01-31"
This problem can occur only with months and years, because others can easily be converted to seconds.
๐ MONTH_BORDER_ADJUST ๐
$MONTH_BORDER_ADJUST variable is used to switch on or off the month-adjust feature. This is used only when someone adds months or years to a date and then the resulting date became invalid. An example: adding one month to "2001-01-31" will result in "2001-02-31", and this is an invalid date.
When $MONTH_BORDER_ADJUST is false, this result is simply normalized, and becomes "2001-03-03". This is the default behaviour.
When $MONTH_BORDER_ADJUST is true, this result becomes "2001-02-28". So when the date overflows, then it returns the last day instead ๐ซถ
Both settings keep the time information. periodt ๐
๐ TIMEZONE SUPPORT ๐
okay so since 1.0.11, Class::Date handles timezones natively on most platforms (peep the BUGS AND LIMITATIONS section for the tea on that "most" okay ๐
).
When the module gets loaded, it figures out your local base timezone by calling the Class::Date::local_timezone() function, and it stashes those values into two variables, namely:
$Class::Date::LOCAL_TIMEZONEโ this one gets used whenever you call thelocaldatefunction ๐$Class::Date::DEFAULT_TIMEZONEโ this one gets used whenever you call thedatefunction and you don't specify a timezone
There's also a $Class::Date::GMT_TIMEZONE function (yes bestie, function), which the gmdate function uses, and it's set to 'GMT'. iconic. โจ
You can query the timezone of a date object by calling the $date->tz method. Heads up tho: this value returns the timezone as you specified it, so if you create the object with an unknown timezone, that's literally what you'll get back ๐ญ. If you want the effective timezone instead, call the $date->tzdst method. That one returns only valid timezones, but it's not necessarily a timezone you can use to create a new object. For example $date->tzdst can return 'CEST', which is not a valid base timezone, because it also carries daylight savings information with it. On Linux systems, you can see the possible base timezones chilling in the /usr/share/zoneinfo directory ๐ฆ.
In Class::Date 1.1.6, a new environment variable entered the chat: $Class::Date::NOTZ_TIMEZONE. This variable stores the local timezone, which is the one used when the TZ environment variable is not set. Why does it exist? Because some systems just cannot handle the queried timezone well, periodt. For example, the local timezone might be CST โ that's what the tzname() perl function returns โ but the moment you set the TZ environment variable to CST, it behaves like it's GMT ๐. The workaround is NOTZ_TIMEZONE: if a date object has a timezone that is the same as NOTZ_TIMEZONE, then the TZ variable gets removed before each calculation. In the normal case, that'd be the same as setting TZ to $NOTZ_TIMEZONE, but some systems just don't vibe with that, so the variable was introduced instead. The $Class::Date::NOTZ_TIMEZONE variable is set during the module's initialization, by removing the TZ variable from the environment and querying the tzname variable. slay. ๐
๐ฎ INTERNALS ๐ฎ
This module uses operator overloading very heavily. It's been found quite stable, but ngl, it's also a little bit scary ๐.
A Class::Date object is an array reference.
A Class::Date::Rel object is an array reference too, and it contains month and second information. It has to be stored as an array ref because array and month values cannot be converted into seconds โ all thanks to our super calendar ๐๏ธโจ.
You can add code references to @Class::Date::NEW_FROM_SCALAR and @Class::Date::Rel::NEW_FROM_SCALAR. These arrays get iterated through whenever a scalar-format date must be parsed. At initialization, these arrays only have one or two values. The parameters which the code references receive are the same as the new method of each class. So basically, you can personalize the date parsing however you want ๐ซถ.
As of 0.90, Class::Date got a full rewrite. A lot of code and design decisions were borrowed from Matt Sergeant's Time::Object, and there will be some incompatibility with the previous public version (0.5). Compatibility methods were kept in Class::Date on purpose. If you run into problems with this, please drop an email with a description of the problem, and the compatibility will be set back ๐.
Invalid dates are Class::Date::Invalid objects. Every method call on this object, and every operation with this object, returns undef or 0. that's it, that's the whole personality ๐
๐ DEVELOPMENT FOCUS ๐
This module tries to be as full-featured as it can possibly be. It currently lacks business-day calculation, which is planned to be implemented in the 1.0.x series. coming soon bestie ๐
The goal is to keep this module from depending on other modules, and to keep it usable without a C compiler.
Currently the module uses the POSIX localtime function very extensively. This makes date calculation a bit slow, but it provides a rich interface that no other module provides. When an attempt was made to redesign the internals to not depend on localtime, it failed ๐ญ โ because there is no other way to determine the daylight savings information.
โก SPEED ISSUES โก
There are two kinds of adjustment in this module: DST_ADJUST and MONTH_BORDER_ADJUST. Both of them make the "+" and "-" operations slower. If you don't need them, switch them off to get faster calculations ๐จ.
In general, if you genuinely need fast date and datetime calculation, don't use this module. As you can see in the previous section, the focus of development is not speed in 1.0. For fast date and datetime calculations, use the Date::Calc module instead. no cap ๐คทโโ๏ธ
๐งต THREAD SAFETY and MOD_PERL ๐งต
This module is NOT thread-safe, because it uses C library functions which are not thread-safe. Using this module in a multi-threaded environment can cause timezones to get messed up ๐ตโ๐ซ. No warning about this was added anywhere โ you have to make sure that you understand this! fr fr.
โ ๏ธ bestie this is not a drill: NOT thread-safe. proceed with the knowledge. ๐
Under some circumstances in a mod_perl environment, you require the Env::C module to set the TZ variable properly before calling the time functions. That's why the -EnvC import option exists โ it automatically loads this module if it isn't loaded already โจ. Please read the mod_perl documentation about environment variables and mod_perl to get the idea of why it's required sometimes:
http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code
You're sure you have this problem if the $Class::Date::NOTZ_TIMEZONE variable is set to 'UTC', even though you're sure your timezone is not that ๐. Try -EnvC in this case, but make sure you're not using it in a multi-threaded environment!
๐ OTHER BUGS AND LIMITATIONS ๐
- Not all date/time values can be expressed in all timezones. For example:
print date("2010-10-03 02:00:00", "Australia/Sydney")
# it will print 2010-10-03 03:00:00
No matter how hard you try, you are not going to be able to express the time in that example in that timezone. If you don't need the timezone information and you want to make sure the calculations are always correct, please use GMT as a timezone (the 'gmdate' function can be a shortcut for it ๐ซ). In that case, you might also consider turning off DST_ADJUST to speed up the calculation.
- The timezone code cannot be made to work properly on ActivePerl 5.8.0 on win XP, and earlier versions possibly have this problem too. If you have a system like this, then you'll have only two timezones: the local one and
GMT. Every timezone which is not equal to$Class::Date::GMT_TIMEZONEis assumed to be local. This seems to be caused by the win32 implementation of timezone routines. There's no real known way to make this thing work, so that issue was given up on. If anyone knows a working solution, it will be integrated intoClass::Dateโ but until then, timezone support will not be available for these platforms ๐. - Perl 5.8.0 and earlier versions have a bug in the
strftimecode on some operating systems (for example Linux), which is timezone related. The recommendation is to use thestrftimewhich is provided withClass::Date, so don't try to use the module without the compiled part. The module will not work with a buggystrftimeโ the test for this is hardcoded into the beginning of the code ๐. If you anyway want to use the module, remove the hardcoded"die"from the module, but do it at your own risk โ ๏ธ. - This module uses the
POSIXfunctions for date and time calculations, so it is not working for dates beyond 2038 and before 1902.
It's unknown which systems support dates in the 1902โ1970 range โ it may not work on your system. It is known to work on the Linux glibc system with perl 5.6.1 and 5.7.2. It is known to not work with perl 5.005_03 (it may be the bug of the Time::Local module). Please report if you know any system where it does not work with perl 5.6.1 or later ๐ข.
Hopefully someone will fix this with the new time_t in libc ๐ค. If you really need dates over 2038 and before 1902, you need to completely rewrite this module, or use Date::Calc or other date modules.
- This module uses
Time::Local, and when it croaks,Class::Datereturns the"Invalid date or time"error message.Time::Localis different in the 5.005 and 5.6.x (and even 5.7.x) version of perl, so the following code will return different results:
$a = date("2006-11-11")->clone(year => -1);
In perl 5.6.1, it returns an invalid date with the error message "Invalid date or time". In perl 5.005 it returns an invalid date with a range check error. Both are false if you use them in boolean context though โ only the error message is different, but don't rely on the error message in this case ๐. It however works in the same way if you change other fields than "year" to an invalid field.
๐ SUPPORT ๐
Class::Date is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
If you have questions, you can send questions directly:
dlux@dlux.hu
๐ช WIN32 notes ๐ช
You can get a binary win32 version of Class::Date from Chris Winters' .ppd repository with the following commands:
For people using PPM2:
c:\> ppm
PPM> set repository oi http://openinteract.sourceforge.net/ppmpackages/
PPM> set save
PPM> install Class-Date
For people using PPM3:
c:\> ppm
PPM> repository http://openinteract.sourceforge.net/ppmpackages/
PPM> install Class-Date
The first steps in PPM only need to be done the first time. Next time you just run the 'install' ๐.
ยฉ๏ธ COPYRIGHT ยฉ๏ธ
Copyright (c) 2001 Szabรณ, Balรกzs (dLux)
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) Matt Sergeant
๐ CREDITS ๐
- Matt Sergeant <matt@sergeant.org> โ (Lots of code are borrowed from the
Time::Objectmodule) - Tatsuhiko Miyagawa <miyagawa@cpan.org> โ (bugfixes)
- Stas Bekman <stas@stason.org> โ (suggestions, bugfix)
- Chris Winters <chris@cwinters.com> โ (win32
.ppdversion) - Benoit Beausejour <bbeausej@pobox.com> โ (Parts of the timezone code is borrowed from his
Date::Handlermodule)
๐ SEE ALSO ๐
perl(1). Date::Calc(3pm). Time::Object(3pm). Date::Handler(3pm).
๐ AUTHORS ๐
- dLux (Szabรณ, Balรกzs) <dlux@dlux.hu>
- Gabor Szabo <szabgab@gmail.com>
- Yanick Champoux <yanick@cpan.org>
๐ COPYRIGHT AND LICENSE ๐
okay so legal bit bestie, but it's short and it's cute, don't skip it:
- This software is copyright (c)
2018,2014,2010,2003by Balรกzs Szabรณ. ๐ซถ - This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt ๐
that's it, that's the whole license. go forth and remix, just keep the terms the same as Perl 5's. no cap. โจ
real talk though: it's literally free software, so no weird vibes, no surprise clauses, just the same terms as Perl 5 itself. iconic behaviour fr fr. ๐
and that's a wrap on the whole Class::Date page, bestie!! ๐ you made it all the way to the end, main character energy honestly ๐
if you're ever wondering which version of this page you're reading, it came from the perl v5.40.0 toolchain, dated 2024-10-29, and it's the manual page for Class::Date in section 3pm. ๐
now go write some dates that actually know what timezone they're in. slay. ๐ฆ๐๐ธ
๐ฆ where this page comes from
- debian trixie: libclass-date-perl 1.1.17-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-date-perl 1.1.17-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-date-perl 1.1.17-3 ยท 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