Kevin Ryde > chart > App::Chart::Timebase

Download:
chart-250.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  16
Open  3
View/Report Bugs
Source  

NAME ^

App::Chart::Timebase -- timebases

SYNOPSIS ^

 use App::Chart::Timebase;

DESCRIPTION ^

A App::Chart::Timebase object represents a date/time period and a starting point.

Dates in a timebase are integers starting from 0 for the starting point. For example a timebase might be weeks starting from 19 Nov 2007, in which case that week is 0, the following week is 1, etc. Methods on the timebase objects allow conversion of year/month/day dates to or from such an index number.

FUNCTIONS ^

App::Chart::Timebase::Days->new_from_iso ($start)
App::Chart::Timebase::Weeks->new_from_iso ($start)
App::Chart::Timebase::Months->new_from_iso ($start)
App::Chart::Timebase::Quarters->new_from_iso ($start)
App::Chart::Timebase::Years->new_from_iso ($start)
App::Chart::Timebase::Decades->new_from_iso ($start)

Create and return a new timebase object representing the given days/weeks/etc type of period, and with a 0 at the given $start date. $start is an ISO format string like "2007-12-31".

Days means weekdays, ie. trading days. Weeks is calendar weeks starting from each Monday, through to the following Sunday. Months is calendar months. Quarters are calendar quarters like Jan/Feb/Mar then Apr/May/Jun, etc.

$timebase->to_iso ($t)

Return an ISO date string like "2007-12-31" for the given $t timebase index (an integer). For example,

    my $timebase = App::Chart::Timebase::Days->new_from_iso ('2008-05-01');
    my $iso = $timebase->to_iso (5);
    # $iso is '2008-05-08'  (weekday 5 counting from 0 at 1 May)
$timebase->from_ymd_floor ($year, $month, $day)
$timebase->from_iso_floor ($str)
$timebase->from_iso_ceil ($str)

Return a time value (an integer) in $timebase which corresponds to the given date, either as values $year, $month and $day, or an ISO date string $str like "2007-12-31".

If the date is not representable in $timebase, then for floor the return is the next earlier timebase value or for ceil the next later. This only arises on a Days timebase when the date requested is a Saturday or Sunday. In that case floor gives the preceding Friday or ceil the following Monday.

$timebase->convert_from_floor ($from_timebase, $from_t)
$timebase->convert_from_ceil ($from_timebase, $from_t)

Convert an time value in $from_timebase to a value in $timebase. The two timebases can have different starting points and different units, such as converting a day number into a week number.

When the destination $timebase is a higher resolution than $from_timebase the convert_from_floor version gives the start of the $from_t period and the convert_from_ceil version gives the end. For example if $from_timebase is years but the destination $timebase is months then floor gives the first month (ie. January) in the $from_t year and ceil gives the last month (ie. December).

$timebase->strftime ($format, $t)

Return an strftime formatted string which is timebase value $t (an integer) under $format. For example,

    $timebase->strftime ('%d %b %Y', $t)
    # gives say "31 December 2007"
$timebase->today ()
$timebase->today ($timezone)

Return today's date as an integer in $timebase. The optional $timezone is a App::Chart::TZ object to use, or the default is local time.

$timebase->adjective()

Return a string which is an adjective for the $timebase. For example on a years timebase the return would be "Yearly". The string is translated through the usual Chart internationalizations if possible.

syntax highlighting: