Date
view release on metacpan or search on metacpan
lib/Date.pod view on Meta::CPAN
$yday is c_yday() [0-365]
=head4 clone(%diff | @diff)
Returns copy of the date.
If you pass a hash-list or array then date is cloned with changes described in the hash/array.
Hash keys: year (YYYY), month [1-12], day, hour, min, sec, mksec, tz
Array: [$year (YYYY), $month [1-12], $day, $hour, $min, $sec, $mksec, $tz]
If any values in hash or array are absent (or = undef or = -1) the appropriate field of source date is not changed.
If C<tz> parameter is absent (or undef or ""), newly created date will use current date's timezone.
Otherwise constructed date is converted to specified timezone preserving YMDhms information.
=head4 month_begin_new()
Returns the beggining of month. Only day of month is changed, HMS are preserved.
=head4 month_begin()
Same as C<month_begin_new()> but changes current object instead of cloning.
=head4 month_end_new()
Returns the end of month. Only day of month is changed, HMS are preserved.
=head4 month_end()
Same as C<month_end_new()> but changes current object instead of cloning.
=head4 days_in_month()
Returns the number of days in month
=head4 week_of_month()
Returns the week of the month [0..5]. The first week of the month is the first week that contains a Thursday.
A day in the week before the week with the first Thursday will be week 0.
=head4 weeks_in_year()
Returns total number of weeks in the current year (52 or 53).
=head4 week_of_year()
my $week_number = $date->week_of_year();
my ($week_year, $week_number) = $date->week_of_year();
Returns information about the calendar week which contains this date object [1..53].
The first week of the year is defined by ISO as the one which contains the fourth day of January, which is equivalent to saying that it's the first week to overlap the new year by at least four days.
Typically the week year will be the same as the year that the object is in, but dates at the very beginning of a calendar year often end up in the last week of the prior year, and similarly, the final few days of the year may be placed in the first w...
=head4 error()
Returns error occured during creating or cloning object (if any) as L<XS::STL::ErrorCode> object.
=head4 truncated()
Return copy of the current date with HMS set to 0. Same as C<clone(hour => 0, min => 0, sec => 0)>, but runs faster.
=head4 truncate()
Same as C<truncated()> but changes current object instead of cloning.
=head4 '<=>', 'cmp', compare($arg)
Converts C<$arg> to date, compares 2 dates and returns -1, 0 or 1.
$date <=> $arg
$arg <=> $date
$date <=> "2001-01-01 01:01:01"
$date <=> 123456789; # epoch
"01.02.2019" <=> $date
$date1 <=> $date2
=head4 '+', sum($arg)
Converts C<$arg> to relative date, adds it to the date and returns new date as a result.
$date + $arg
$arg + $date
$date + "1Y 2M";
86400 + $date;
$date + DAY;
=head4 '+=', add($arg)
Converts C<$arg> to relative date and adds it to existing date object.
$date += $arg
$date += 10;
$date += YEAR;
$date += "1h 2m 3s";
=head4 '-', difference($arg)
If second operand is a date object, then returns L<Date::Rel> object representing exact interval from right operand till left operand.
$date_till - $date_from; # same as Date::Rel->new($date_from, $date_till)
(date("2019-02-01") - date("2019-01-01"))->to_days == 31;
( run in 0.719 second using v1.01-cache-2.11-cpan-39bf76dae61 )