{"id":16306391,"url":"https://github.com/yanick/perl-class-date","last_synced_at":"2025-08-08T05:12:34.786Z","repository":{"id":56840355,"uuid":"38078797","full_name":"yanick/perl-class-date","owner":"yanick","description":"Easy date manipulation","archived":false,"fork":false,"pushed_at":"2018-06-01T13:10:39.000Z","size":166,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"releases","last_synced_at":"2025-04-12T14:46:37.864Z","etag":null,"topics":["date","perl"],"latest_commit_sha":null,"homepage":"https://metacpan.org/release/Class-Date","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanick.png","metadata":{"files":{"readme":"README.mkdn","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-25T22:59:21.000Z","updated_at":"2018-06-01T13:10:39.000Z","dependencies_parsed_at":"2022-08-28T22:00:13.670Z","dependency_job_id":null,"html_url":"https://github.com/yanick/perl-class-date","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/yanick/perl-class-date","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fperl-class-date","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fperl-class-date/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fperl-class-date/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fperl-class-date/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanick","download_url":"https://codeload.github.com/yanick/perl-class-date/tar.gz/refs/heads/releases","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fperl-class-date/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269366853,"owners_count":24405250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date","perl"],"created_at":"2024-10-10T21:10:30.435Z","updated_at":"2025-08-08T05:12:34.758Z","avatar_url":"https://github.com/yanick.png","language":"Perl","readme":"[![Build Status](https://travis-ci.org/yanick/perl-class-date.svg?branch=master)](https://travis-ci.org/yanick/perl-class-date)\n\n# NAME\n\nClass::Date - Class for easy date and time manipulation\n\n# VERSION\n\nversion 1.1.17\n\n# SYNOPSIS\n\n```perl\nuse Class::Date qw(:errors date localdate gmdate now -DateParse -EnvC);\n\n# creating absolute date object (local time)\n$date = Class::Date-\u003enew( [$year,$month,$day,$hour,$min,$sec]);\n$date = date [$year,$month,$day,$hour,$min,$sec]; \n  # ^- \"date\" is an exportable function, the same as Class::Date-\u003enew\n$date = date { year =\u003e $year, month =\u003e $month, day =\u003e $day,\n  hour =\u003e $hour, min =\u003e $min, sec =\u003e $sec };\n$date = date \"2001-11-12 07:13:12\";\n$date = localdate \"2001-12-11\";\n$date = now;                      #  the same as date(time)\n$date = date($other_date_object); # cloning\n...\n\n# creating absolute date object (GMT)\n$date = Class::Date-\u003enew( [$year,$month,$day,$hour,$min,$sec],'GMT');\n$date = gmdate \"2001-11-12 17:13\";\n...\n\n# creating absolute date object in any other timezone\n$date = Class::Date-\u003enew( [$year,$month,$day,$hour,$min,$sec],'Iceland' );\n$date = date \"2001-11-12 17:13\", 'Iceland';\n$date2 = $date-\u003enew([$y2, $m2, $d2, $h2, $m2, $s2]); \n  # ^- timezone is inherited from the $date object\n\n# creating relative date object\n# (normally you don't need to create this object explicitly)\n$reldate = Class::Date::Rel-\u003enew( \"3Y 1M 3D 6h 2m 4s\" );\n$reldate = Class::Date::Rel-\u003enew( \"6Y\" );\n$reldate = Class::Date::Rel-\u003enew( $secs );  # secs\n$reldate = Class::Date::Rel-\u003enew( [$year,$month,$day,$hour,$min,$sec] );\n$reldate = Class::Date::Rel-\u003enew( { year =\u003e $year, month =\u003e $month, day =\u003e $day,\n  hour =\u003e $hour, min =\u003e $min, sec =\u003e $sec } );\n$reldate = Class::Date::Rel-\u003enew( \"2001-11-12 07:13:12\" );\n$reldate = Class::Date::Rel-\u003enew( \"2001-12-11\" );\n\n# getting values of an absolute date object\n$date;              # prints the date in default output format (see below)\n$date-\u003eyear;        # year, e.g: 2001\n$date-\u003e_year;       # year - 1900, e.g. 101\n$date-\u003eyr;          # 2-digit year 0-99, e.g 1\n$date-\u003emon;         # month 1..12\n$date-\u003emonth;       # same as prev.\n$date-\u003e_mon;        # month 0..11\n$date-\u003e_month;      # same as prev.\n$date-\u003eday;         # day of month\n$date-\u003emday;        # day of month\n$date-\u003eday_of_month;# same as prev.\n$date-\u003ehour;\n$date-\u003emin;\n$date-\u003eminute;      # same as prev.\n$date-\u003esec;\n$date-\u003esecond;      # same as prev.\n$date-\u003ewday;        # 1 = Sunday\n$date-\u003e_wday;       # 0 = Sunday\n$date-\u003eday_of_week; # same as prev.\n$date-\u003eyday;        \n$date-\u003eday_of_year; # same as prev.\n$date-\u003eisdst;       # DST?\n$date-\u003edaylight_savings; # same as prev.\n$date-\u003eepoch;       # UNIX time_t\n$date-\u003emonname;     # name of month, eg: March\n$date-\u003emonthname;   # same as prev.\n$date-\u003ewdayname;    # Thursday\n$date-\u003eday_of_weekname # same as prev.\n$date-\u003ehms          # 01:23:45\n$date-\u003eymd          # 2000/02/29\n$date-\u003emdy          # 02/29/2000\n$date-\u003edmy          # 29/02/2000\n$date-\u003emeridiam     # 01:23 AM\n$date-\u003eampm         # AM/PM\n$date-\u003estring       # 2000-02-29 12:21:11 (format can be changed, look below)\n\"$date\"             # same as prev.\n$date-\u003etzoffset     # timezone-offset\n$date-\u003estrftime($format) # POSIX strftime (without the huge POSIX.pm)\n$date-\u003etz           # returns the base timezone as you specify, eg: CET\n$date-\u003etzdst        # returns the real timezone with dst information, eg: CEST\n\n($year,$month,$day,$hour,$min,$sec)=$date-\u003earray;\n($year,$month,$day,$hour,$min,$sec)=@{ $date-\u003earef };\n# !! $year: 1900-, $month: 1-12\n\n($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=$date-\u003estruct;\n($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=@{ $date-\u003esref };\n# !! $year: 0-, $month: 0-11\n\n$hash=$date-\u003ehref; # $href can be reused as a constructor\nprint $hash-\u003e{year}.\"-\".$hash-\u003e{month}. ... $hash-\u003e{sec} ... ;\n\n%hash=$date-\u003ehash;\n# !! $hash{year}: 1900-, $hash{month}: 1-12\n\n$date-\u003emonth_begin  # First day of the month (date object)\n$date-\u003emonth_end    # Last day of the month\n$date-\u003edays_in_month # 28..31\n\n# constructing new date based on an existing one:\n$new_date = $date-\u003eclone;\n$new_date = $date-\u003eclone( year =\u003e 1977, sec =\u003e 14 );\n# valid keys: year, _year, month, mon, _month, _mon, day, mday, day_of_month,\n#             hour, min, minute, sec, second, tz\n# constructing a new date, which is the same as the original, but in \n# another timezone:\n$new_date = $date-\u003eto_tz('Iceland');\n\n# changing date format\n{\n  local $Class::Date::DATE_FORMAT=\"%Y%m%d%H%M%S\";\n  print $date       # result: 20011222000000\n  $Class::Date::DATE_FORMAT=undef;\n  print $date       # result: Thu Oct 13 04:54:34 1994\n  $Class::Date::DATE_FORMAT=\"%Y/%m/%d\"\n  print $date       # result: 1994/10/13\n}\n\n# error handling\n$a = date($date_string);\nif ($a) { # valid date\n  ...\n} else { # invalid date\n  if ($a-\u003eerror == E_INVALID) { ... }\n  print $a-\u003eerrstr;\n}\n\n# adjusting DST in calculations  (see the doc)\n$Class::Date::DST_ADJUST = 1; # this is the default\n$Class::Date::DST_ADJUST = 0;\n\n# \"month-border adjust\" flag \n$Class::Date::MONTH_BORDER_ADJUST = 0; # this is the default\nprint date(\"2001-01-31\")+'1M'; # will print 2001-03-03\n$Class::Date::MONTH_BORDER_ADJUST = 1;\nprint date(\"2001-01-31\")+'1M'; # will print 2001-02-28\n\n# date range check\n$Class::Date::RANGE_CHECK = 0; # this is the default\nprint date(\"2001-02-31\"); # will print 2001-03-03\n$Class::Date::RANGE_CHECK = 1;\nprint date(\"2001-02-31\"); # will print nothing\n\n# getting values of a relative date object\n$reldate;              # reldate in seconds (assumed 1 month = 2_629_744 secs)\n$reldate-\u003eyear;\n$reldate-\u003emon;\n$reldate-\u003emonth;       # same as prev.\n$reldate-\u003eday;\n$reldate-\u003ehour;\n$reldate-\u003emin;\n$reldate-\u003eminute;      # same as prev.\n$reldate-\u003esec;         # same as $reldate\n$reldate-\u003esecond;      # same as prev.\n$reldate-\u003esec_part;    # \"second\" part of the relative date\n$reldate-\u003emon_part;    # \"month\"  part of the relative date\n\n# arithmetic with dates:\nprint date([2001,12,11,4,5,6])-\u003etruncate; \n                             # will print \"2001-12-11\"\n$new_date = $date+$reldate;\n$date2    = $date+'3Y 2D';   # 3 Years and 2 days\n$date3    = $date+[1,2,3];   # $date plus 1 year, 2 months, 3 days\n$date4    = $date+'3-1-5'    # $date plus 3 years, 1 months, 5 days\n\n$new_date = $date-$reldate;\n$date2    = $date-'3Y';      # 3 Yearss\n$date3    = $date-[1,2,3];   # $date minus 1 year, 2 months, 3 days\n$date4    = $date-'3-1-5'    # $date minus 3 years, 1 month, 5 days\n\n$new_reldate = $date1-$date2;\n$reldate2 = Class::Date-\u003enew('2000-11-12')-'2000-11-10';\n$reldate3    = $date3-'1977-11-10';\n\n$days_between = (Class::Date-\u003enew('2001-11-12')-'2001-07-04')-\u003eday;\n\n# comparison between absolute dates\nprint $date1 \u003e $date2 ? \"I am older\" : \"I am younger\";\n\n# comparison between relative dates\nprint $reldate1 \u003e $reldate2 ? \"I am faster\" : \"I am slower\";\n\n# Adding / Subtracting months and years are sometimes tricky:\nprint date(\"2001-01-29\") + '1M' - '1M'; # gives \"2001-02-01\"\nprint date(\"2000-02-29\") + '1Y' - '1Y'; # gives \"2000-03-01\"\n\n# Named interface ($date2 does not necessary to be a Class::Date object)\n$date1-\u003estring;               # same as $date1 in scalar context\n$date1-\u003esubtract($date2);     # same as $date1 - $date2\n$date1-\u003eadd($date2);          # same as $date1 + $date2\n$date1-\u003ecompare($date2);      # same as $date1 \u003c=\u003e $date2\n\n$reldate1-\u003esec;               # same as $reldate1 in numeric or scalar context\n$reldate1-\u003ecompare($reldate2);# same as $reldate1 \u003c=\u003e $reldate2\n$reldate1-\u003eadd($reldate2);    # same as $reldate1 + $reldate2\n$reldate1-\u003eneg                # used for subtraction\n\n# Disabling Class::Date warnings at load time\nBEGIN { $Class::Date::WARNINGS=0; }\nuse Class::Date;\n```\n\n# DESCRIPTION\n\nThis module is intended to provide a general-purpose date and datetime type\nfor perl. You have a Class::Date class for absolute date and datetime, and have \na Class::Date::Rel class for relative dates.\n\nYou can use \"+\", \"-\", \"\u003c\" and \"\u003e\" operators as with native perl data types.\n\nNote that this module is fairly ancient and dusty. You \nmight want to take a look at [DateTime](https://metacpan.org/pod/DateTime) and its related \nmodules for a more standard, and maintained, Perl date\nmanipulation solution.\n\n# USAGE\n\nIf you want to use a date object, you need to do the following:\n\n```\n- create a new object\n- do some operations (+, -, comparison)\n- get result back\n```\n\n## Creating a new date object\n\nYou can create a date object by the \"date\", \"localdate\" or \"gmdate\" function, \nor by calling the Class::Date constructor.\n\n\"date\" and \"Class::Date-\u003enew\" are equivalent, both has two arguments: The\ndate and the timezone.\n\n```\n$date1= date [2000,11,12];\n$date2= Class::Date-\u003enew([2000,06,11,13,11,22],'GMT');\n$date2= $date1-\u003enew([2000,06,11,13,11,22]);\n```\n\nIf the timezone information is omitted, then it first check if \"new\" is \ncalled as an object method or a class method. If it is an object method,\nthen it inherits the timezone from the base object, otherwise the default\ntimezone is used ($Class::Date::DEFAULT\\_TIMEZONE), which is usually set to\nthe local timezone (which is stored in $Class::Date::LOCAL\\_TIMEZONE). These\ntwo variables are set only once to the value, which is returned by the\nClass::Date::local\\_timezone() function. You can change these values\nwhenever you want.\n\n\"localdate $x\" is equivalent to \"date $x, $Class::Date::LOCAL\\_TIMEZONE\", \n\"gmdate $x\" is equivalent to \"date $x, $Class::Date::GMT\\_TIMEZONE\".\n\n$Class::Date::GMT\\_TIMEZONE is set to 'GMT' by default.\n\n```\n$date1= localdate [2000,11,12];\n$date2= gmdate [2000,4,2,3,33,33];\n\n$date = localdate(time);\n```\n\nThe format of the accepted input date can be:\n\n- \\[$year,$month,$day,$hour,$min,$sec\\]\n\n    An array reference with 6 elements. The missing elements have default\n    values (year: 2000, month, day: 1, hour, min, sec: 0)\n\n- { year =\u003e $year, month =\u003e $month, day =\u003e $day, hour =\u003e $hour, min =\u003e $min, sec =\u003e $sec }\n\n    A hash reference with the same 6 elements as above.\n\n- \"YYYYMMDDhhmmss\"\n\n    A mysql-style timestamp value, which consist of at least 14 digit.\n\n- \"973897262\"\n\n    A valid 32-bit integer: This is parsed as a unix time.\n\n- \"YYYY-MM-DD hh:mm:ss\"\n\n    A standard ISO(-like) date format. Additional \".fraction\" part is ignored, \n    \":ss\" can be omitted.\n\n- additional input formats\n\n    You can specify \"-DateParse\" as  an import parameter, e.g:\n\n    ```perl\n    use Class::Date qw(date -DateParse);\n    ```\n\n    With this, the module will try to load Date::Parse module, and if it find it then all \n    these formats can be used as an input. Please refer to the Date::Parse\n    documentation.\n\n## Operations\n\n- addition\n\n    You can add the following to a Class::Date object:\n\n    ```perl\n    - a valid Class::Date::Rel object\n    - anything, that can be used for creating a new Class::Date::Rel object\n    ```\n\n    It means that you don't need to create a new Class::Date::Rel object every\n    time when you add something to the Class::Date object, it creates them\n    automatically:\n\n    ```\n    $date= Class::Date-\u003enew('2001-12-11')+Class::Date::Rel-\u003enew('3Y');\n    ```\n\n    is the same as:\n\n    ```\n    $date= date('2001-12-11')+'3Y';\n    ```\n\n    You can provide a Class::Date::Rel object in the following form:\n\n    - array ref\n\n        The same format as seen in Class::Date format, except the default values are\n        different: all zero.\n\n    - hash ref\n\n        The same format as seen in Class::Date format, except the default values are\n        different: all zero.\n\n    - \"973897262\"\n\n        A valid 32-bit integer is parsed as seconds.\n\n    - \"YYYY-MM-DD hh:mm:ss\"\n\n        A standard ISO date format, but this is parsed as relative date date and time,\n        so month, day and year can be zero (and defaults to zero).\n\n    - \"12Y 6M 6D 20h 12m 5s\"\n\n        This special string can be used if you don't want to use the ISO format. This\n        string consists of whitespace separated tags, each tag consists of a number and\n        a unit. The units can be:\n\n        ```\n        Y: year\n        M: month\n        D: day\n        h: hour\n        m: min\n        s: sec\n        ```\n\n        The number and unit must be written with no space between them.\n\n- substraction\n\n    The same rules are true for substraction, except you can substract \n    two Class::Date object from each other, and you will get a Class::Date::Rel\n    object:\n\n    ```\n    $reldate=$date1-$date2;\n    $reldate=date('2001-11-12 12:11:07')-date('2001-10-07 10:3:21');\n    ```\n\n    In this case, the \"month\" field of the $reldate object will be 0,\n    and the other fields will contain the difference between two dates;\n\n- comparison\n\n    You can compare two Class::Date objects, or one Class::Date object and\n    another data, which can be used for creating a new Class::Data object.\n\n    It means that you don't need to bless both objects, one of them can be a\n    simple string, array ref, hash ref, etc (see how to create a date object).\n\n    ```\n    if ( date('2001-11-12') \u003e date('2000-11-11') ) { ... }\n    ```\n\n    or \n\n    ```\n    if ( date('2001-11-12') \u003e '2000-11-11' ) { ... }\n    ```\n\n- truncate\n\n    You can chop the time value from this object (set hour, min and sec to 0)\n    with the \"truncate\" or \"trunc\" method. It does not modify the specified\n    object, it returns with a new one.\n\n- clone\n\n    You can create new date object based on an existing one, by using the \"clone\"\n    method. Note, this DOES NOT modify the base object.\n\n    ```perl\n    $new_date = $date-\u003eclone( year =\u003e 2001, hour =\u003e 14 );\n    ```\n\n    The valid keys are: year, \\_year, month, mon, \\_month, \\_mon, day, mday, \n    day\\_of\\_month, hour, min, minute, sec, second, tz.\n\n    There is a \"set\" method, which does the same as the \"clone\", it exists \n    only for compatibility.\n\n- to\\_tz\n\n    You can use \"to\\_tz\" to create a new object, which means the same time as\n    the base object, but in the different timezone.\n\n    Note that $date-\u003eclone( tz =\u003e 'Iceland') and $date-\u003eto\\_tz('Iceland') is not\n    the same! Cloning a new object with setting timezone will preserve the\n    time information (hour, minute, second, etc.), but transfer the time into\n    other timezone, while to\\_tz usually change these values based on the\n    difference between the source and the destination timezone.\n\n- Operations with Class::Date::Rel\n\n    The Class::Date::Rel object consists of a month part and a day part. Most\n    people only use the \"day\" part of it. If you use both part, then you can get\n    these parts with the \"sec\\_part\" and \"mon\\_part\" method. If you use \"sec\",\n    \"month\", etc. methods or if you use this object in a mathematical context,\n    then this object is converted to one number, which is interpreted as second.\n    The conversion is based on a 30.436 days month. Don't use it too often,\n    because it is confusing...\n\n    If you use Class::Date::Rel in an expression with other Class::Date or\n    Class::Date::Rel objects, then it does what is expected: \n\n    ```\n    date('2001-11-12')+'1M' will be '2001-12-12'\n    ```\n\n    and\n\n    ```\n    date('1996-02-11')+'2M' will be '1996-04-11'\n    ```\n\n## Accessing data from a Class::Date and Class::Date::Rel object\n\nYou can use the methods methods described at the top of the document \nif you want to access parts of the data\nwhich is stored in a Class::Date and Class::Date::Rel object.\n\n## Error handling\n\nIf a date object became invalid, then the object will be reblessed to\nClass::Date::Invalid. This object is false in boolean environment, so you can\ntest the date validity like this:\n\n```\n$a = date($input_date);\nif ($a) { # valid date\n    ...\n} else { # invalid date\n    if ($a-\u003eerror == E_INVALID) { ... }\n    print $a-\u003eerrstr;\n}\n```\n\nNote even the date is invalid, the expression \"defined $a\" always returns\ntrue, so the following is wrong:\n\n```\n$a = date($input_date);\nif (defined $a) ... # WRONG!!!!\n```\n\nYou can test the error by getting the $date-\u003eerror value. You might import\nthe \":errors\" tag:\n\n```perl\nuse Class::Date qw(:errors);\n```\n\nPossible error values are:\n\n- E\\_OK\n\n    No errors.\n\n- E\\_INVALID\n\n    Invalid date. It is set when some of the parts of the date are invalid, and\n    Time::Local functions cannot convert them to a valid date.\n\n- E\\_RANGE\n\n    This error is set, when parts of the date are valid, but the whole date is\n    not valid, e.g. 2001-02-31. When the $Class::Date::RANGE\\_CHECK is not set, then\n    these date values are automatically converted to a valid date: 2001-03-03,\n    but the $date-\u003eerror value are set to E\\_RANGE. If $Class::Date::RANGE\\_CHECK\n    is set, then a date \"2001-02-31\" became invalid date.\n\n- E\\_UNPARSABLE\n\n    This error is set, when the constructor cannot be created from a scalar, e.g:\n\n    ```\n    $a = date(\"4kd sdlsdf lwekrmk\");\n    ```\n\n- E\\_UNDEFINED\n\n    This error is set, when you want to create a date object from an undefined\n    value:\n\n    ```\n    $a = Class::Date-\u003enew(undef);\n    ```\n\n    Note, that localdate(undef) will create a valid object, because it calls\n    $Class::Date(time).\n\nYou can get the error in string form by calling the \"errstr\" method.\n\n# DST\\_ADJUST\n\n$DST\\_ADJUST is an important configuration option.\n\nIf it is set to true (default), then the module adjusts the date and time\nwhen the operation switches the border of DST. With this setting, you are\nignoring the effect of DST.\n\nWhen $DST\\_ADJUST is set to false, then no adjustment is done, the\ncalculation will be based on the exact time difference.\n\nYou will see the difference through an example:\n\n```\n$Class::Date::DST_ADJUST=1;\n\nprint date(\"2000-10-29\", \"CET\") + \"1D\";\n# This will print 2000-10-30 00:00:00\n\nprint date(\"2001-03-24 23:00:00\", \"CET\") + \"1D\";\n# This will be 2001-03-25 23:00:00\n\nprint date(\"2001-03-25\", \"CET\") + \"1D\";\n# This will be 2001-03-26 00:00:00\n\n\n$Class::Date::DST_ADJUST=0;\n\nprint date(\"2000-10-29\", \"CET\") + \"1D\";\n# This will print 2000-10-29 23:00:00\n\nprint date(\"2001-03-24 23:00:00\", \"CET\") + \"1D\";\n# This will be 2001-03-26 00:00:00\n```\n\n# MONTHS AND YEARS\n\nIf you add or subtract \"months\" and \"years\" to a date, you may get wrong \ndates, e.g when you add one month to 2001-01-31, you expect to get\n2001-02-31, but this date is invalid and converted to 2001-03-03. Thats' why\n\n```\ndate(\"2001-01-31\") + '1M' - '1M' != \"2001-01-31\"\n```\n\nThis problem can occur only with months and years, because others can \neasily be converted to seconds.\n\n# MONTH\\_BORDER\\_ADJUST\n\n$MONTH\\_BORDER\\_ADJUST variable is used to switch on or off the \nmonth-adjust feature. This is used only when someone adds months or years to\na date and then the resulted date became invalid. An example: adding one\nmonth to \"2001-01-31\" will result \"2001-02-31\", and this is an invalid date.\n\nWhen $MONTH\\_BORDER\\_ADJUST is false, this result simply normalized, and\nbecomes \"2001-03-03\". This is the default behaviour.\n\nWhen $MONTH\\_BORDER\\_ADJUST is true, this result becomes \"2001-02-28\". So when\nthe date overflows, then it returns the last day insted.\n\nBoth settings keep the time information.\n\n# TIMEZONE SUPPORT\n\nSince 1.0.11, Class::Date handle timezones natively on most platforms (see\nthe BUGS AND LIMITATIONS section for more info).\n\nWhen the module is loaded, then it determines the local base timezone by\ncalling the Class::Date::local\\_timezone() function, and stores these values\ninto two variables, these are: $Class::Date::LOCAL\\_TIMEZONE and\n$Class::Date::DEFAULT\\_TIMEZONE. The first value is used, when you call the\n\"localdate\" function, the second value is used, when you call the \"date\"\nfunction and you don't specify the timezone. There is\na $Class::Date::GMT\\_TIMEZONE function also, which is used by the \"gmdate\"\nfunction, this is set to 'GMT'.\n\nYou can query the timezone of a date object by calling the $date-\u003etz\nmethod. Note this value returns the timezone as you specify, so if you\ncreate the object with an unknown timezone, you will get this back. If you\nwant to query the effective timezone, you can call the $date-\u003etzdst method.\nThis method returns only valid timezones, but it is not necessarily the\ntimezone which can be used to create a new object. For example\n$date-\u003etzdst can return 'CEST', which is not a valid base timezone, because\nit contains daylight savings information also. On Linux systems, you can\nsee the possible base timezones in the /usr/share/zoneinfo directory.\n\nIn Class::Date 1.1.6, a new environment variable is introduced:\n$Class::Date::NOTZ\\_TIMEZONE. This variable stores the local timezone, which\nis used, when the TZ environment variable is not set. It is introduced,\nbecause there are some systems, which cannot handle the queried timezone\nwell. For example the local timezone is CST, it is returned by the tzname()\nperl function, but when I set the TZ environment variable to CST, it\nworks like it would be GMT.  The workaround is NOTZ\\_TIMEZONE: if a date\nobject has a timezone, which is the same as NOTZ\\_TIMEZONE, then the TZ\nvariable will be removed before each calculation. In normal case, it would\nbe the same as setting TZ to $NOTZ\\_TIMEZONE, but some systems don't like\nit, so I decided to introduce this variable. The\n$Class::Date::NOTZ\\_TIMEZONE variable is set in the initialization of the\nmodule by removing the TZ variable from the environment and querying the\ntzname variable.\n\n# INTERNALS\n\nThis module uses operator overloading very heavily. I've found it quite stable,\nbut I am afraid of it a bit.\n\nA Class::Date object is an array reference.\n\nA Class::Date::Rel object is an array reference, which contains month and\nsecond information. I need to store it as an array ref, because array and month\nvalues cannot be converted into seconds, because of our super calendar.\n\nYou can add code references to the @Class::Date::NEW\\_FROM\\_SCALAR and\n@Class::Date::Rel::NEW\\_FROM\\_SCALAR. These arrays are iterated through when a\nscalar-format date must be parsed. These arrays only have one or two values\nat initialization. The parameters which the code references got are the same \nas the \"new\" method of each class. In this way, you can personalize the date\nparses as you want.\n\nAs of 0.90, the Class::Date has been rewritten. A lot of code and design\ndecision has been borrowed from Matt Sergeant's Time::Object, and there will\nbe some incompatibility with the previous public version (0.5). I tried to\nkeep compatibility methods in Class::Date. If you have problems regarding\nthis, please drop me an email with the description of the problem, and I will\nset the compatibility back.\n\nInvalid dates are Class::Date::Invalid objects. Every method call on this\nobject and every operation with this object returns undef or 0.\n\n# DEVELOPMENT FOCUS\n\nThis module tries to be as full-featured as can be. It currently lacks\nbusiness-day calculation, which is planned to be implemented in the 1.0.x\nseries.\n\nI try to keep this module not to depend on other modules and I want this\nmodule usable without a C compiler.\n\nCurrently the module uses the POSIX localtime function very extensively.\nThis makes the date calculation a bit slow, but provides a rich interface,\nwhich is not provided by any other module. When I tried to redesign the\ninternals to not depend on localtime, I failed, because there are no other\nway to determine the daylight savings information.\n\n# SPEED ISSUES\n\nThere are two kind of adjustment in this module, DST\\_ADJUST and\nMONTH\\_BORDER\\_ADJUST. Both of them makes the \"+\" and \"-\" operations slower. If\nyou don't need them, switch them off to achieve faster calculations.\n\nIn general, if you really need fast date and datetime calculation, don't use \nthis module. As you see in the previous section, the focus of development is \nnot the speed in 1.0.  For fast date and datetime calculations, use \nDate::Calc module instead.\n\n# THREAD SAFETY and MOD\\_PERL\n\nThis module is NOT thread-safe, since it uses C library functions, which\nare not thread-safe. Using this module in a multi-threaded environment can\ncause timezones to be messed up. I did not put any warning about it, you\nhave to make sure that you understand this!\n\nUnder some circumstances in a mod\\_perl environment, you require the Env::C\nmodule to set the TZ variable properly before calling the time functions. I\nadded the -EnvC import option to automatically load this module if it is\nnot loaded already. Please read the mod\\_perl documentation about the\nenvironment variables and mod\\_perl to get the idea why it is required\nsometimes:\n\n```perl\nhttp://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code\n```\n\nYou are sure have this problem if the $Class::Date::NOTZ\\_TIMEZONE variable\nis set to 'UTC', althought you are sure that your timezone is not that. Try\n\\-EnvC in this case, but make sure that you are not using it in a\nmulti-threaded environment!\n\n# OTHER BUGS AND LIMITATIONS\n\n- Not all date/time values can be expressed in all timezones. For example:\n\n    ```\n    print date(\"2010-10-03 02:00:00\", \"Australia/Sydney\")\n    # it will print 2010-10-03 03:00:00\n    ```\n\n    No matter how hard you try you, you are not going to be able to express the\n    time in the example in that timezone. If you don't need the timezone\n    information and you want to make sure that the calculations are always\n    correct, please use GMT as a timezone (the 'gmdate' function can be a\n    shortcut for it). In this case, you might also consider turning off\n    DST\\_ADJUST to speed up the calculation.\n\n- I cannot manage to get the timezone code working properly on ActivePerl\n5.8.0 on win XP and earlier versions possibly have this problem also. If\nyou have a system like this, then you will have only two timezones, the\nlocal and the GMT. Every timezone, which is not equal to\n$Class::Date::GMT\\_TIMEZONE is assumed to be local. This seems to be caused\nby the win32 implementation of timezone routines. I don't really know how\nto make this thing working, so I gave up this issue. If anyone know a\nworking solution, then I will integrate it into Class::Date, but until\nthen, the timezone support will not be available for these platforms.\n- Perl 5.8.0 and earlier versions has a bug in the strftime code on some\noperating systems (for example Linux), which is timezone related. I\nrecommend using the strftime, which is provided with Class::Date, so don't\ntry to use the module without the compiled part. The module will not work\nwith a buggy strftime - the test is hardcoded into the beginning of the\ncode. If you anyway want to use the module, remove the hardcoded \"die\" from\nthe module, but do it for your own risk.\n- This module uses the POSIX functions for date and\ntime calculations, so it is not working for dates beyond 2038 and before 1902.\n\n    I don't know what systems support dates in 1902-1970 range, it may not work on\n    your system. I know it works on the Linux glibc system with perl 5.6.1\n    and 5.7.2. I know it does not work with perl 5.005\\_03 (it may be the bug of\n    the Time::Local module). Please report if you know any system where it does\n    \\_not\\_ work with perl 5.6.1 or later.\n\n    I hope that someone will fix this with new time\\_t in libc. If you really need\n    dates over 2038 and before 1902, you need to completely rewrite this module or\n    use Date::Calc or other date modules.\n\n- This module uses Time::Local, and when it croaks, Class::Date returns\n\"Invalid date or time\" error message. Time::Local is different in the 5.005\nand 5.6.x (and even 5.7.x) version of perl, so the following code will\nreturn different results:\n\n    ```perl\n    $a = date(\"2006-11-11\")-\u003eclone(year =\u003e -1);\n    ```\n\n    In perl 5.6.1, it returns an invalid date with error message \"Invali date or\n    time\", in perl 5.005 it returns an invalid date with range check error. Both\n    are false if you use them in boolean context though, only the error message\n    is different, but don't rely on the error message in this case. It however\n    works in the same way if you change other fields than \"year\" to an invalid\n    field.\n\n# SUPPORT\n\nClass::Date is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.\n\nIf you have questions, you can send questions directly to me:\n\n```\ndlux@dlux.hu\n```\n\n# WIN32 notes\n\nYou can get a binary win32 version of Class::Date from Chris Winters' .ppd\nrepository with the following commands:\n\nFor people using PPM2:\n\n```\nc:\\\u003e ppm\nPPM\u003e set repository oi http://openinteract.sourceforge.net/ppmpackages/\nPPM\u003e set save\nPPM\u003e install Class-Date\n```\n\nFor people using PPM3:\n\n```\nc:\\\u003e ppm\nPPM\u003e repository http://openinteract.sourceforge.net/ppmpackages/\nPPM\u003e install Class-Date\n```\n\nThe first steps in PPM only needs to be done at the first time. Next time\nyou just run the 'install'.\n\n# COPYRIGHT\n\nCopyright (c) 2001 SzabÃ³, BalÃ¡zs (dLux)\n\nAll rights reserved. This program is free software; you can redistribute it \nand/or modify it under the same terms as Perl itself.\n\nPortions Copyright (c) Matt Sergeant\n\n# CREDITS\n\n```perl\n- Matt Sergeant \u003cmatt@sergeant.org\u003e\n  (Lots of code are borrowed from the Time::Object module)\n- Tatsuhiko Miyagawa \u003cmiyagawa@cpan.org\u003e (bugfixes)\n- Stas Bekman \u003cstas@stason.org\u003e (suggestions, bugfix)\n- Chris Winters \u003cchris@cwinters.com\u003e (win32 .ppd version)\n- Benoit Beausejour \u003cbbeausej@pobox.com\u003e\n  (Parts of the timezone code is borrowed from his Date::Handler module)\n```\n\n# SEE ALSO\n\nperl(1).\nDate::Calc(3pm).\nTime::Object(3pm).\nDate::Handler(3pm).\n\n# AUTHORS\n\n- dLux (SzabÃ³, BalÃ¡zs) \u003cdlux@dlux.hu\u003e\n- Gabor Szabo \u003cszabgab@gmail.com\u003e\n- Yanick Champoux \u003cyanick@cpan.org\u003e [![endorse](http://api.coderwall.com/yanick/endorsecount.png)](http://coderwall.com/yanick)\n\n# COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2018, 2014, 2010, 2003 by BalÃ¡zs SzabÃ³.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanick%2Fperl-class-date","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanick%2Fperl-class-date","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanick%2Fperl-class-date/lists"}