Advanced-Config
view release on metacpan or search on metacpan
lib/Advanced/Config/Options.pm view on Meta::CPAN
$dates->{last_month}, $dates->{this_month}, $dates->{next_month});
# -------------------------------------------------------------------------
# Get the desired periods Year-Month ... ($mon == 0..11)
my $lyr = ( $mon == 0 ) ? ($yr - 1) : $yr;
my $nyr = ( $mon == 11 ) ? ($yr + 1) : $yr;
$dates->{this_period} = _fmt_period ($sep, $order, $yr, $dates->{this_month});
$dates->{last_period} = _fmt_period ($sep, $order, $lyr, $dates->{last_month});
$dates->{next_period} = _fmt_period ($sep, $order, $nyr, $dates->{next_month});
DBUG_PRINT ("PERIODS ($mon)", "LAST: %s, NOW: %s, NEXT: %s",
$dates->{last_period}, $dates->{this_period}, $dates->{next_period});
# -------------------------------------------------------------------------
if ( $prev->{this_month} && $prev->{this_month} ne $dates->{this_month} ) {
$what_changed = 2; # The month & periods changed ...
}
# -------------------------------------------------------------------------
# Get the desired years ...
$dates->{this_year} = sprintf ("%04d", $yr);
$dates->{last_year} = sprintf ("%04d", $yr - 1);
$dates->{next_year} = sprintf ("%04d", $yr + 1);
DBUG_PRINT (" YEARS", "LAST: %s, NOW: %s, NEXT: %s",
$dates->{last_year}, $dates->{this_year}, $dates->{next_year});
if ( $prev->{this_year} && $prev->{this_year} ne $dates->{this_year} ) {
$what_changed = 3; # The year changed ...
}
# -------------------------------------------------------------------------
# Get the miscellanious vars ...
$dates->{dow} = $week_day_ref->[$dow]; # 1..7 or spelled out.
$dates->{doy} = $doy + 1; # 1..365 normal, 1..366 in leap years.
$dates->{dom} = $day; # 1..31, range based on month.
DBUG_PRINT (" MISC", " DOW: %s, DOY: %d, DOM: %d",
$dates->{dow}, $dates->{doy}, $dates->{dom});
DBUG_RETURN ($what_changed);
}
# ==============================================================
=item change_special_date_vars ( $timestamp, $date_opts_ref, $date_hash_ref )
Same as L<set_special_date_vars> except it uses the specified date/time to
convert.
=cut
sub change_special_date_vars
{
DBUG_ENTER_FUNC (@_);
my $timestamp = shift;
my $date_opts = shift;
my $dates = shift;
# Special flag for special handling ... (undocumented)
local $date_opts->{timestamp} = $timestamp;
# Forces all dates to use the specified date/time
set_special_date_vars ($date_opts, $dates);
DBUG_VOID_RETURN ();
}
# ==============================================================
# For formatting the full dates ...
sub _fmt_date
{
my $sep = shift;
my $order = shift;
my $year = shift;
my $month = shift; # 1..12 or the name.
my $day = shift; # 1..31
my $dt;
if ( $order == 1 ) {
# MM-DD-YYYY format
$dt = sprintf ("%s%s%02d%s%04d", $month, $sep, $day, $sep, $year);
} elsif ( $order == 2 ) {
# DD-MM-YYYY format
$dt = sprintf ("%02d%s%s%s%04d", $day, $sep, $month, $sep, $year);
} else {
# YYYY-MM-DD order ...
$dt = sprintf ("%04d%s%s%s%02d", $year, $sep, $month, $sep, $day);
}
return ($dt);
}
# ==============================================================
# Formatting to be "year-month" or "month-year".
sub _fmt_period
{
my $sep = shift;
my $order = shift;
my $year = shift;
my $month = shift; # 1..12 or the name.
my $dt;
if ( $order == 1 || $order == 2 ) {
# MM-YYYY format
$dt = sprintf ("%s%s%04d", $month, $sep, $year);
} else {
# YYYY-MM format
$dt = sprintf ("%04d%s%s", $year, $sep, $month);
}
return ($dt);
}
# ==============================================================
=back
( run in 0.800 second using v1.01-cache-2.11-cpan-39bf76dae61 )