NAME
Date::QuarterOfYear - calculate what quarter a given date is in
SYNOPSIS
$q
= quarter_of_year(
'2013-02-17'
);
# '2013-Q1'
$q
= quarter_of_year(
$epoch
);
# '2013-Q1'
$q
= quarter_of_year({
year
=> 2012,
month
=> 8,
day
=> 9 });
(
$year
,
$quarter
) = quarter_of_year(
$epoch
);
DESCRIPTION
Date::QuarterOfYear provides a single function, but even so you must explicitly ask for it, as per the SYNOPSIS.
quarter_of_year()
quarter_of_year
takes a date and returns what quarter that date is in. The input date can be specified in various ways, and the result will either be returned as a string of the form 'YYYY-QN' (eg '2014-Q2'), or as a list ($year, $quarter)
.
$time
=
time
();
$qstring
= quarter_of_year(
$time
);
(
$year
,
$quarter
) = quarter_of_year(
$time
);
This is a very simple module, and there are other modules that can calculate the quarter for you. But I have similar code in multiple places where I don't want to load DateTime just for this.
SEE ALSO
DateTime has several features related to quarters: given a DateTime
instance, the quarter
method returns a number between 1 and 4. The day_of_quarter
method returns a number between 1 and the number of days in the quarter. The quarter_name
method returns a locale-specific name for the quarter.
Date::Format provides a time2str
function that will generate the quarter number (1..4).
Time::Moment also provides a quarter
method that returns the quarter number for a given date.
REPOSITORY
https://github.com/neilb/Date-QuarterOfYear
AUTHOR
Neil Bowers <neilb@cpan.org>
LICENSE AND COPYRIGHT
This software is copyright (c) 2014 by Neil Bowers <neilb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.