DateTimeX-Fiscal-Fiscal5253

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

2014-06-29 15:30  jim
    Version 2.01
    * Changed to Moo
    * Changed to Test::Exception in some tests

2014-06-29 15:30  jim
    Version 1.06
    * Set minimum Perl version to 5.8.8 in Makefile.PL
    * Removed unwanted accessor for "date" from automatic generation code.
    * "contains" now returns "undef" instead of "0" if the date isn't in
      the specified calendar.
    * Changed from using "lc()" to "tr/A-Z/a-z/" for case conversion.
    * Cleaned up code to generate week attributes.
    * Corrected spelling mistakes, updated POD for "containers".
    * Updated Makefile.PL to use more modern conventions.

2014-06-10 23:30  jim
    Version 1.05
    * Added code to deal with what seems to be a bug in gmtime() in
      Perl 5.10.0 built on a Win32 v5.x platform.

META.json  view on Meta::CPAN

{
   "abstract" : "Create fiscal 52/53 week calendars",
   "author" : [
      "Jim Bacon <jim@nortx.com>"
   ],
   "dynamic_config" : 1,
   "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.141520",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Create fiscal 52/53 week calendars'
author:
  - 'Jim Bacon <jim@nortx.com>'
build_requires:
  Test::Exception: '0'
  Test::More: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.141520'
license: perl

README  view on Meta::CPAN

DateTimeX-Fiscal-Fiscal5253 version 0.01
===================================

Compute dates used to create a 52/53 week calendar from a DateTime object.

The 52/53 week calendar is a fiscal calendar standard widely used by
companies that need easy comparison between sales periods from year
to year. It is recognized as a Generally Accepted Accounting Practice and
by the IRS as an alternative to a traditional calendar year or a fiscal
year based on twelve calendar months.

Its primary distinguishing characteristic is that it always begins and ends
on the same weekday. In addition, a 52/53 week year will always have exactly
52 or 53 perfect seven day weeks, yielding calendars that always have
either 364 or 371 days. This is what makes it useful for year-over-year
comparisons where seasonal factors such as holidays are important.

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

    }
    else {
        croak "Unable to parse date string: $date";
    }
    eval { $date = DateTime->new( year => $y, month => $m, day => $d ); }
      or croak "Invalid date: $date";

    return $date;
};

# Utility function to validate values supplied as a calendar style.
my $_valid_cal_style = sub {
    my $style = shift || 'fiscal';

    $style =~ tr/A-Z/a-z/;
    croak "Invalid calendar style specified: $style"
      unless $style =~ /^(fiscal|restated|truncated)$/;

    return $style;
};

# Define attributes and psuedo-attributes
has end_month => (
    is  => 'ro',
    isa => sub {
        croak "Invalid value for param end_month: $_[0]"

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

            $wstart += $weeksecs;
            $wend   += $weeksecs;
        }
    }

    $self->{_weeks_raw} = $weeks;

    return;
}

# Build the basic calendar structures as needed.
sub _build_periods {
    my $self = shift;
    my $style = shift || $self->{style};

    # not strictly needed, but makes for easier to read code
    my $restate  = $style eq 'restated'  ? 1 : 0;
    my $truncate = $style eq 'truncated' ? 1 : 0;

    # Avoid re-builds when possible.
    return if $restate  && defined( $self->{_restated} );

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

            $wkcntr++;
        }

        $pdata->{ $_ + 1 } = $pinfo;
    }
    $pdata->{summary}->{end} = $pdata->{12}->{end};

    if ( $self->{_weeks} == 52 ) {

        # Set style to 'fiscal' and assign the structure to all
        # three calendar types in a normal year to save time and space.
        $pdata->{summary}->{style} = 'fiscal';
        $self->{_fiscal} = $self->{_restated} = $self->{_truncated} = $pdata;
        $self->{_fiscal_weeks}    = $wdata;
        $self->{_restated_weeks}  = $wdata;
        $self->{_truncated_weeks} = $wdata;
    }
    else {
        $self->{"_$style"}         = $pdata;
        $self->{"_${style}_weeks"} = $wdata;
    }

    return;
}

# The end day for a specified year is trivial to determine. In normal
# accounting use, a fiscal year is named for the calendar year it ends in,
# not the year it begins.
sub _end5253 {
    my $self = shift;

    my $dt = DateTime->last_day_of_month(
        year      => $self->{year},
        month     => $self->{end_month},
        time_zone => 'floating'
    );

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

        $dt->subtract( days => ( $dt_dow + 7 ) - $self->{end_dow} );
    }
    $dt->add( weeks => 1 )
      if $self->{end_type} eq 'closest' && $eom_day - $dt->day > 3;

    return $dt;
}

# Finding the starting day for a specified year is easy. Simply find
# the last day of the preceding year since the year is defined by
# the ending day and add 1 day to that. This avoids calendar year and month
# boundary issues.
sub _start5253 {
    my $self = shift;

    # do not assume it is safe to change the year attribute
    local $self->{year} = $self->year - 1;
    my $dt = $self->_end5253->add( days => 1 );

    return $dt;
}

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN


    return $y1;
}

sub has_leap_week {
    my $self = shift;

    return ( $self->{_weeks} == 53 ? 1 : 0 );
}

# return summary data about a calendar.
sub summary {
    my $self = shift;
    my %args = @_ == 1 ? ( style => shift ) : @_;

    $args{style} ||= $self->{style};
    croak 'Unknown parameter present' if scalar( keys(%args) ) > 1;

    my $cal = &{$_valid_cal_style}( $args{style} );

    my %cdata;

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

    # NOTE! This will break in 2038 on 32-bit builds!
    $args{date} = strftime( "%Y-%m-%d", localtime() )
      if ( lc( $args{date} ) eq 'today' );

    # _str2dt will croak on error
    my $date = &{$_str2dt}( $args{date} )->ymd;

    my $whash = $self->{"_${cal}_weeks"};
    my $cdata = $self->{"_$cal"}->{summary};

    # it is NOT an error if the date isn't in the calendar,
    # so return undef to differentiate this from an error condition
    return if $date lt $cdata->{start} || $date gt $cdata->{end};

    # since the date is in the calendar, let's return it's week,
    # and optionally, a structure with period and week number.

    my $w;
    for ( $w = 1 ; $date gt $whash->{$w}->{end} ; $w++ ) {

        # this should NEVER fire!
        croak 'FATAL ERROR! RAN OUT OF WEEKS' if $w > $cdata->{weeks};
    }
    my $p = $whash->{$w}->{period};

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

}

1;

__END__

=pod

=head1 NAME

DateTimeX::Fiscal::Fiscal5253 - Create fiscal 52/53 week calendars

=head1 SYNOPSIS

 use DateTimeX::Fiscal::Fiscal5253;
  
 my $fc = DateTimeX::Fiscal::Fiscal5253->new( year => 2012 );

=head1 DESCRIPTION

This module generates calendars for a "52/53 week" fiscal year. They are
also known as "4-4-5" or "4-5-4" calendars due to the repeating week
patterns of the periods in each quarter. A 52/53 week year will B<always>
have either 52 or 53 weeks (364 or 371 days.) One of the best known of
this type is the standard Retail 4-5-4 calendar as defined by the National
Retail Federation.

You are B<strongly> advised to speak with your accounting people
(after all, the reason you are reading this is because they want reports,
right?) and show them the summary data for any given year and see if it
matches what they expect.

Keep in mind that when an accountant says they want data for fiscal year 2012
they are probably talking about an accounting year that B<ends> in 2012. An
accountant will usually think in terms of "the fiscal year ending in October,

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

     leap_period => 'last',
 );

The constructor B<must> be called as a class method and will throw an
exception if not. It accepts the following parameters:

=over 4

=item C<end_month>

set the last calendar month of the fiscal year. This should be
an integer in the range 1 .. 12 where "1" is January.
Default: 12

=item C<end_dow>

sets the last day of the week of the fiscal year. This is an
integer in the range 1 .. 7 with Monday being 1. Remember, a 52/53 week
fiscal calendar always ends on the same weekday. Default: 6 (Saturday)

=item C<end_type>

determines how to calculate the last day of the fiscal year
based on the C<end_month> and C<end_dow>. There are two legal vaules:
"last" and "closest". Default: "last"

"last" says to use the last weekday in the month of the type specified
in C<end_dow> as the end of the fiscal year.

"closest" says to use the weekday of the type specified that is closest
to the end of the calendar month as the last day, B<even if it is in the
following month>.

=item C<leap_period>

determines what period the 53rd week (if needed) is placed in.
This could be of importance when creating year-over-year reports.
There are two legal values: "first" and "last". Default: "last"

"first" says to place the extra week in period 1.

"last" says to place the extra week in period 12.

=back

The last two parameters control what year the calendar is generated for.
These parameters are optional but B<mutually exclusive> and will
throw an exception if both are present.

=over 4

=item C<year>

sets the B<fiscal year> to build for. It defaults to the correct
fiscal year for the current date or to the fiscal year containing the date
specified by C<date>.

The fiscal year value will often be different than the calendar year for
dates that are near the beginning or end of the fiscal year. For example,
Jan 3, 2015 is the last day of FYE2014 when using an C<end_type> of "closest".

B<NOTE!> In normal accounting terms, a fiscal year is named for the calendar
year it ends in. That is, for a fiscal year that ends in October, fiscal year
2005 would begin in October or November of calendar year 2004
(depending upon the setting of C<end_type>.) However, Retail 4-5-4
calendars are named for the year they B<begin> in. This means that a Retail
4-5-4 calendar for 2005 would begin in 2005 and not 2004 as an accountant
would normally think. See the discussion at the end of this documentation
about Retail 4-5-4 calendars for more information.

=item C<date>

if present, is either a string representing a date or a
L<DateTime> object. This will be used to build a calendar that contains
the given value. Again, be aware that dates that are close to the end
of a given fiscal year might have different values for the calendar year
vs the fiscal year.

If the value for C<date> is a string, it must be specified as either
"YYYY-MM-DD" or "MM/DD/YYYY" or some reasonable variant of those such as
single digit days and months. Time components, if present, are discarded.
Any other format will throw an exception. A L<DateTime> object will be
cloned before being used to prevent unwanted changes to the original object.

=back

=head1 ACCESSORS

The accessors allow you to examine the parameters used to create the calendar
and the resulting base values. All accessors are read-only and will throw
an exception if a parameter is passed to them.

If you want to change any of the underlying properties that define an
object, B<create a new object!>

=head2 end_month

 my $end_month = $fc->end_month();

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

Returns the last date in the fiscal year as constructed from the parameters
given to the constructor.

=head2 weeks

 my $weeks = $fc->weeks();

Returns the number of weeks in the fiscal year as generated by the
parameters given to the construtor. The value will be either "52" or "53"
depending on whether a leap week was added. This value does B<not> look
at the calendar style but rather is based on only the fiscal year itself.

=head2 has_leap_week

 my $fc = DateTimeX::Fiscal::Fiscal5253->new( year => 2006 );
 print "This is a Fiscal Leap Year" if $fc->has_leap_week;

This method is basically syntactic sugar for the C<weeks> accessor and
returns a Boolean value indicating whether or not the fiscal Year for the
object has 53 weeks instead of the standard 52 weeks.

=head1 METHODS

=head2 style

 my $fc = DateTimeX::Fiscal::Fiscal5253->new( year => 2006 );
 my $cal_style = $fc->style; # returns the current style
 $fc->style( 'restated );    # set the style to 'restated'

This method reads and sets the calendar style to be used by all of the
following methods. It can be overridden on a case by case basis as needed
by those methods.

The legal values are "fiscal", "restated", and "truncated" when the style
is being set. A new object has the style set to 'fiscal' by default.

The value 'fiscal' will use a calendar with the full number of weeks
without regard to whether there are 52 or 53 weeks in the year.

The value 'restated' says to ignore the first week in a 53 week year and
create a calendar with only 52 weeks. This allows for more accurate
year-over-year comparisons involving a year that would otherwise have
53 weeks.

The value 'truncated' says to ignore the last week in a 53 week year and
create a calendar with only 52 weeks. This may allow for more accurate
year-over-year comparisons involving a year that would otherwise have
53 weeks.

"restated" and "truncated" have no effect in normal 52 week years.

=head2 summary

 my %summary = $fc->summary();
 my $summary = $fc->summary();
 
 my %summary = $fc->summary( style => 'restated');
 my $summary = $fc->summary( 'restated' );

This method will return either a hash or a reference to a hash (depending
upon context) containing a summary of the current calendar style or the one
specified by the style parameter.

 my $fc = DateTimeX::Fiscal::Fiscal5253->new( year => 2012 );
 my $fc_info = $fc->summary();
  
 print Dumper($fc_info);
 $VAR1 = {
          'style => 'fiscal',
          'year' => 2012,
          'start' => '2012-01-01',
          'end' => '2012-12-29',
          'weeks' => 52
        };

The value contained in C<$fc_info-E<gt>{year}> is the name of the fiscal
year as commonly used by accountants (as in "fye2012") and is usually the
same as the calendar year the fiscal year B<ends> in. However, it is
possible for the actual ending date to be in the B<following> calendar
year when the C<end_month> is '12' (the default) and an C<end_type> of
"closest" is specified, fiscal year 2014 built as shown below demonstrates
this:

 my $fc = DateTimeX::Fiscal::Fiscal5253->new(
              year => 2014,
              end_type => 'closest'
          );
 
 print Dumper($fc->summary());

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN


=head2 contains

 my $fc = DateTimeX::Fiscal::Fiscal5253->new( year => 2012 );
  
 if ( my $wnum = $fc->contains() ) {
     print "The current date is in week $wnum\n";
 }
  
 if ( $fc->contains( date => 'today', style => 'restated' ) ) {
     print 'The current day is in the fiscal calendar';
 }
  
 if ( $fc->contains( date => '2012-01-01', style => 'fiscal' ) ) {
     print '2012-01-01 is in the fiscal calendar';
 }
  
 my $dt = DateTime->today( time_zone => 'floating' );
 if ( my $wnum = $fc->contains( date => $dt ) ) {
     print "$dt is in week $wnum\n";
 }
  
 my %containers = $fc->contains( '2012-06-04' );
 print Dumper(\%containers);
 $VAR1 = {
          'period' => 6,
          'week' => 23
        };

Returns the week number in the designated style that contains the given
date or C<undef> if not. The method will C<croak> if an error occurs such
as an invalid date format or unknown style type.

This method takes two named parameters, 'date' and 'style'. Bear in mind
that some dates that are in the fiscal calendar might not be in a restated
or truncated calendar. A single un-named parameter can be used as a shorthand
for supplying only the date.

A hash containing both the period and week numbers is returned if the
method is called in list context and the date is present.

=over 4

=item C<date>

Accepts the same formats as the constructor as well as the special
keyword 'today'. Defaults to the current date if not supplied.

=item C<style>

Specifies which calendar style to check against and accepts
the same values as the 'style' method does. The default is the current value
returned as set by the C<style> method.

=back

=head2 period

 my %pdata = $fc->period( period => 5, style => 'restated' );
 my $pdata = $fc->period( period => 1, style => 'fiscal' );

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN


=over 4

=item C<period>

Must be a number in the range 1 - 12. An exception will be thrown if this
parameter is not given.

=item C<style>

Specifies what calendar style to retrieve the period information from. Legal
values are the same as those for the C<style> method. The current value of
the C<style> method will be used by default.

=back

The returned data is as follows:

 print Dumper($pdata);
 $VAR1 = { 
          'period' => 1,

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN


=over 4

=item C<week>

Must be a number in the range 1 - 52 (53 if a leap week is present in the
requested style.) An exception will be thrown if not given.

=item C<style>

Specifies what calendar style to retrieve the week information from. Legal
values are the same as those for the C<style> method. The current value for
the C<style> method will be used by default.

=back

The returned data is as follows:

 print Dumper($wdata);
 $VAR1 = { 
          'week' => 5,

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

 my $wend = $fc->week_end( style => 'fiscal' );

=back

There is no method to return the week number component because presumably
you already know that. Use C<contains> to get the week number for the current
date if applicable. (Besides, C<$fc-E<gt>week_week> is just plain ugly!)

=head1 RETAIL 4-5-4 CALENDARS

A Retail 4-5-4 calendar (as described by the National Retail Federation here:
L<http://www.nrf.com/modules.php?name=Pages&sp_id=392>) is an example of a
fiscal 52/53 week year that starts on the Sunday closest to Jan 31 of
the specified year.

In other words, to create a Retail 4-5-4 calendar for 2012, you will create
a Fiscal5253 object that ends in 2013 on the Saturday closest to Jan 31.

B<Note!> Fiscal years are named for the year they end in, Retail 4-5-4
years are named for the year they B<begin> in!

 # Create a Retail 4-5-4 calendar for 2012
 my $r2012 = DateTimeX::Fiscal::Fiscal5253->new(
     year => 2013,          # This will be the ending year for the calendar
     end_month => 1,        # End in January
     end_dow => 6,          # on the Saturday
     end_type => 'closest', # closest to the end of the month
     leap_period => 'last'  # and any leap week in the last period
 );
 
 print Dumper(\%{$r2012->summary()});
 $VAR1 = { 
          'style' => 'fiscal',
          'year' => '2013',

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN

 
 print Dumper(\%{$r2012->summary( style => 'truncated' )});
 $VAR1 = { 
          'style' => 'truncated',
          'year' => '2013',
          'weeks' => 52,
          'start' => '2012-01-29'
          'end' => '2013-01-26',
        };

You can verify that this is correct by viewing the calendars available at
the NRF website: L<http://www.nrf.com/4-5-4Calendar>

The reporting date can be determined by adding 5 days to the end of any
given period. Using L<DateTime> makes this trivial:

 # Get the reporting date for period 5 for the object created above
 my ($y,$m,$d) = split(/\-/,$r2012->period_end( period => 5 ));
 my $report_date = DateTime->new(
     year => $y,
     month => $m,

lib/DateTimeX/Fiscal/Fiscal5253.pm  view on Meta::CPAN


=head1 SEE ALSO

L<DateTime> to get ideas about how to work with an object suppiled to
the constructor as the C<date> parameter.

Do a Google (or comparable) search to learn more about fiscal Years and
the 52/53 week. This is a fairly arcane subject that usually is of interest
only to accountants and those of us who must provide reports to them.

Of particular interest will be how a Retail 4-5-4 calendar differs in
definition from an accounting 4-4-5 fiscal year.

=head1 CREDITS

This module, like any other in the L<DateTime> family, could not exist
without the work and dedication of Dave Rolsky.

=head1 SUPPORT

Support is provided by the author. Please report bugs or make feature

t/30_methods.t  view on Meta::CPAN


# Also make one that is guaranteed to contain the current date.
my $dt    = DateTime->now();
my $dt6   = DateTime->now()->clone->add( months => 6 );
my $e_mo  = $dt6->month;
my $fcnow = $class->new( end_month => $dt6->month, year => $dt6->year );

ok( !$fc->has_leap_week,  '2012 does not have a leap week' );
ok( $fc53->has_leap_week, '2014 does have a leap week' );

# Verify that calendars for 53 week years vary for each style
my $cmeta53 = $fc53->summary();
ok( $cmeta53->{style} eq 'fiscal', 'default style set to "fiscal"' );
ok( $cmeta53->{weeks} == 53,       'default has 53 weeks' );
$cmeta53 = $fc53->summary( style => 'Fiscal' );
ok( $cmeta53->{style} eq 'fiscal', 'style set to "fiscal"' );
ok( $cmeta53->{weeks} == 53,       'Fiscal has 53 weeks' );
$cmeta53 = $fc53->summary( style => 'Restated' );
ok( $cmeta53->{style} eq 'restated', 'style set to "restated"' );
ok( $cmeta53->{weeks} == 52,         'Restated has 52 weeks' );
$cmeta53 = $fc53->summary( style => 'Truncated' );
ok( $cmeta53->{style} eq 'truncated', 'style set to "truncated"' );
ok( $cmeta53->{weeks} == 52,          'Truncated has 52 weeks' );

# Test that "contains" function accepts valid calendar values
ok( $fc53->contains( date => $fc53->start ) == 1, 'default has start date' );
ok( $fc53->contains( date => $fc53->end ) == 53,  'default has end date' );
ok( $fc53->contains( date => $fc53->start, style => 'Fiscal' ) == 1,
    'default has start date' );
ok( $fc53->contains( date => $fc53->end, style => 'Fiscal' ) == 53,
    'default has end date' );
ok( $fc53->contains( date => $fc53->start, style => 'Truncated' ) == 1,
    'Truncated has start date' );
ok( $fc53->contains( date => $fc53->end, style => 'Restated' ) == 52,
    'Restated has end date' );

t/30_methods.t  view on Meta::CPAN

    TODO: {
        local $TODO = 'Moo doesn\'t check for this' if 1;

        ok( !eval { $fc->style( 'fiscal', 'foobar' ) },
            'style rejects extra paramenter'
        );
    }

    ok(
        !eval { $fc->summary( style => 'foobar' ) },
        'calendar rejects style "foobar"'
    );
    ok(
        !eval { $fc->summary( foo => 'bar' ) },
        'calendar rejects unknown parameter'
    );
    ok( !eval { $fc->contains( style => 'foobar' ) },
        'contains rejects style "foobar"' );
    ok(
        !eval { $fc->contains( foo => 'bar' ) },
        'contains rejects unknown parameter'
    );
    ok( !eval { $fc->period( period => 1, style => 'foobar' ) },
        'period rejects style "foobar"' );
    ok(
        !eval { $fc->period( foo => 'bar' ) },
        'period rejects unknown parameter'
    );

    for (qw( month start end weeks )) {
        my $pmethod = "period_$_";
        ok( !eval { $fc->$pmethod( period => 1, style => 'foobar' ) },
            "$pmethod rejects calendar style 'foobar'" );
        ok(
            !eval { $fc->$pmethod( foo => 'bar' ) },
            "$pmethod rejects unknown parameter"
        );
    }
    ok( !eval { $fc->week( week => 1, style => 'foobar' ) },
        'week rejects style "foobar"' );
    ok( !eval { $fc->week( foo => 'bar' ) }, 'week rejects unknown parameter' );
    for (qw( period start end )) {
        my $wmethod = "period_$_";
        ok( !eval { $fc->$wmethod( period => 1, style => 'foobar' ) },
            "$wmethod rejects calendar style 'foobar'" );
        ok(
            !eval { $fc->$wmethod( foo => 'bar' ) },
            "$wmethod rejects unknown parameter"
        );
    }
}

done_testing();

exit;

t/80_sanity.t  view on Meta::CPAN

        'contains end date in period 12' );
    ok( !$fc->contains( date => $fc->{_start}->clone->subtract( days => 1 ) ),
        'does not contain day before start date' );
    ok( !$fc->contains( date => $fc->{_end}->clone->add( days => 1 ) ),
        'does not contain day after end date' );

    if ( $fc->has_leap_week ) {
        my $dt = $fc->{_start}->clone->add( days => 6 );
        ok(
            !$fc->contains( date => $dt, style => 'Restated' ),
            'Restated calendar does not have first week'
        );
        $dt->add( days => 1 );
        ok(
            $dt->ymd eq $fc->{_restated}->{summary}->{start},
            'Restated start date is one week after base start'
        );
        ok(
            $fc->contains( date => $dt, style => 'Restated' ),
            'Restated calendar contains own start'
        );
        ok(
            $fc->{_restated}->{summary}->{style} eq 'restated',
            'Restated has correct name in calendar summary record'
        );
        $dt = $fc->{_end}->clone->subtract( days => 6 );
        ok(
            !$fc->contains( date => $dt, style => 'Truncated' ),
            'Truncated calendar does not have last week'
        );
        $dt->subtract( days => 1 );
        ok(
            $dt->ymd eq $fc->{_truncated}->{summary}->{end},
            'Truncated start date is one week before base end'
        );
        ok( $fc->contains( date => $dt, style => 'Truncated' ),
            'Truncated calendar contains own end' );
        ok(
            $fc->{_truncated}->{summary}->{style} eq 'truncated',
            'Truncated has correct name in calendar summary record'
        );

        if ( $fc->leap_period eq 'first' ) {
            cmp_ok(
                $fc->period_weeks( period => 1 ),
                '==',
                $fc->period_weeks( period => 4 ) + 1,
                'period 1 has an extra week'
            );
            cmp_ok(



( run in 0.544 second using v1.01-cache-2.11-cpan-5dc5da66d9d )