Skip to content

Commit

Permalink
import DateTime 0.35 from CPAN
Browse files Browse the repository at this point in the history
git-cpan-module:   DateTime
git-cpan-version:  0.35
git-cpan-authorid: DROLSKY
git-cpan-file:     authors/id/D/DR/DROLSKY/DateTime-0.35.tar.gz
  • Loading branch information
autarch authored and schwern committed Dec 10, 2009
1 parent c3aab39 commit 0d21e8f
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 50 deletions.
9 changes: 9 additions & 0 deletions Changes
@@ -1,3 +1,12 @@
0.35 2006-10-22

[ ENHANCEMENTS ]

- Added several new methods for getting locale-based data, era_abbr(),
era_name(), quarter_abbr(), and quarter_name(). The era() method
returns the same data as era_abbr(), but is deprecated.


0.34 2006-08-11

[ BUG FIXES ]
Expand Down
19 changes: 5 additions & 14 deletions DateTime.xs
Expand Up @@ -63,22 +63,13 @@ const int PREVIOUS_MONTH_DOLY[12] = { 0,
const IV neg_dow[] = { 1, 7, 6, 5, 4, 3, 2 };

IV
_real_is_leap_year(IV y)
{
IV r = 0;

/* We need to have this first so that year 0 is a leap year */
if (y % 400 == 0) {
r = 1;
} else if (y % 100 == 0) {
r = 0;
} else if (y % 4 == 0) {
r = 1;
}

return r;
_real_is_leap_year(IV y) {
/* See http://www.perlmonks.org/?node_id=274247 for where this
silliness comes from */
return (y % 4) ? 0 : (y % 100) ? 1 : (y % 400) ? 0 : 1;
}


MODULE = DateTime PACKAGE = DateTime

PROTOTYPES: ENABLE
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -55,6 +55,7 @@ t/36invalid_local.t
t/37local-add.t
t/38local-subtract.t
t/39no-so.t
t/40leap-years.t
t/99-pod.t
TODO
tools/leap_seconds_header.pl
Expand Down
6 changes: 3 additions & 3 deletions META.yml
@@ -1,11 +1,11 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: DateTime
version: 0.34
version: 0.35
version_from: lib/DateTime.pm
installdirs: site
requires:
DateTime::Locale: 0.21
DateTime::Locale: 0.31
DateTime::TimeZone: 0.38
Params::Validate: 0.76
Pod::Man: 1.14
Expand All @@ -14,4 +14,4 @@ requires:
Time::Local: 1.04

distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.30
generated_by: ExtUtils::MakeMaker version 6.30_01
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -69,7 +69,7 @@ sub write_makefile
clean => { FILES => "test.c test.o $zz" },
CONFIGURE => \&init,

PREREQ_PM => { 'DateTime::Locale' => 0.21,
PREREQ_PM => { 'DateTime::Locale' => 0.31,
'DateTime::TimeZone' => 0.38,
'Params::Validate' => 0.76,
'Pod::Man' => 1.14,
Expand Down
56 changes: 40 additions & 16 deletions lib/DateTime.pm
Expand Up @@ -10,7 +10,7 @@ use DateTime::Helpers;

BEGIN
{
$VERSION = '0.34';
$VERSION = '0.35';

my $loaded = 0;
unless ( $ENV{PERL_DATETIME_PP} )
Expand Down Expand Up @@ -601,11 +601,16 @@ sub ce_year { $_[0]->{local_c}{year} <= 0 ?
$_[0]->{local_c}{year} - 1 :
$_[0]->{local_c}{year} }

sub era { $_[0]->{locale}->era( $_[0] ) }
sub era_name { $_[0]->{locale}->era_name( $_[0] ) }

sub era_abbr { $_[0]->{locale}->era_abbreviation( $_[0] ) }
# deprecated
*era = \&era_abbr;

sub christian_era { $_[0]->ce_year > 0 ? 'AD' : 'BC' }
sub secular_era { $_[0]->ce_year > 0 ? 'CE' : 'BCE' }

sub year_with_era { (abs $_[0]->ce_year) . $_[0]->era }
sub year_with_era { (abs $_[0]->ce_year) . $_[0]->era_abbr }
sub year_with_christian_era { (abs $_[0]->ce_year) . $_[0]->christian_era }
sub year_with_secular_era { (abs $_[0]->ce_year) . $_[0]->secular_era }

Expand All @@ -627,6 +632,9 @@ sub weekday_of_month { use integer; ( ( $_[0]->day - 1 ) / 7 ) + 1 }

sub quarter {$_[0]->{local_c}{quarter} };

sub quarter_name { $_[0]->{locale}->quarter_name( $_[0] ) }
sub quarter_abbr { $_[0]->{locale}->quarter_abbreviation( $_[0] ) }

sub day_of_month_0 { $_[0]->{local_c}{day} - 1 }
*day_0 = \&day_of_month_0;
*mday_0 = \&day_of_month_0;
Expand Down Expand Up @@ -1837,11 +1845,11 @@ or C<epoch()>, will never die.
=head2 Locales
Some methods are localizable. This is done by setting the locale
when constructing a DateTime object. There is also a
C<DefaultLocale()> class method which may be used to set the default
locale for all DateTime objects created. If this is not set, then
"English" is used.
All the object methods which return names or abbreviations return data
based on a locale. This is done by setting the locale when
constructing a DateTime object. There is also a C<DefaultLocale()>
class method which may be used to set the default locale for all
DateTime objects created. If this is not set, then "en_US" is used.
Some locales may return data as Unicode. When using Perl 5.6.0 or
greater, this will be a native Perl Unicode string. When using older
Expand Down Expand Up @@ -2096,9 +2104,15 @@ Returns the year.
Returns the year according to the BCE/CE numbering system. The year
before year 1 in this system is year -1, aka "1 BCE".
=item * era
=item * era_name
Returns a string provided by the locale, based on the year.
Returns the long name of the current era, something like "Before
Christ". See the L<Locales|/Locales> section for more details.
=item * era_abbr
Returns the abbreviated name of the current era, something like "BC".
See the L<Locales|/Locales> section for more details.
=item * christian_era
Expand All @@ -2110,9 +2124,9 @@ Returns a string, either "BCE" or "CE", according to the year.
=item * year_with_era
Returns a string containing the year immediately followed by its era.
The year is the absolute value of C<ce_year()>, so that year 1 is
"1BC" and year 0 is "1AD".
Returns a string containing the year immediately followed by its era
abbreviation. The year is the absolute value of C<ce_year()>, so that
year 1 is "1BC" and year 0 is "1AD".
=item * year_with_christian_era
Expand Down Expand Up @@ -2165,6 +2179,16 @@ Returns the day of the year.
Returns the quarter of the year, from 1..4.
=item * quarter_name
Returns the name of the current quarter. See the
L<Locales|/Locales> section for more details.
=item * quarter_abbr
Returns the abbreviated name of the current quarter. See the
L<Locales|/Locales> section for more details.
=item * day_of_quarter, doq
Returns the day of the quarter.
Expand Down Expand Up @@ -2529,8 +2553,7 @@ Each of these methods returns a new C<DateTime::Duration> object
representing some portion of the difference between two datetimes.
The C<delta_md()> method returns a duration which contains only the
month and day portions of the duration is represented. The
C<delta_days()> method returns a duration which contains only days,
and the C<delta_ms()> method
C<delta_days()> method returns a duration which contains only days.
The C<delta_md> and C<delta_days> methods truncate the duration so
that any fractional portion of a day is ignored. Both of these
Expand Down Expand Up @@ -3028,7 +3051,8 @@ The day of the month as a decimal number (range 01 to 31).
=item * %D
Equivalent to %m/%d/%y. This is not a good standard format if you
want both United States and European people to understand the date!
want folks from both the United States and the rest of the world to
understand the date!
=item * %e
Expand Down
17 changes: 4 additions & 13 deletions lib/DateTimePP.pm
Expand Up @@ -201,20 +201,11 @@ sub _is_leap_year
shift;
my $year = shift;

if ($year % 400 == 0)
{
return 1;
}
elsif ($year % 100 == 0)
{
return 0;
}
elsif ($year % 4 == 0)
{
return 1;
}
return 0 if $year % 4;
return 1 if $year % 100;
return 0 if $year % 400;

return 0;
return 1;
}

sub _day_length { DateTime::LeapSecond::day_length($_[1]) }
Expand Down
13 changes: 10 additions & 3 deletions t/03components.t
Expand Up @@ -2,7 +2,7 @@

use strict;

use Test::More tests => 130;
use Test::More tests => 135;

use DateTime;

Expand Down Expand Up @@ -75,6 +75,13 @@ is( $d->iso8601, '2001-07-05T02:12:50', '->iso8601' );

is( $d->is_leap_year, 0, '->is_leap_year' );

is( $d->era_abbr, 'AD', '->era_abbr' );
is( $d->era, $d->era_abbr, '->era (deprecated)' );
is( $d->era_name, 'Anno Domini', '->era_abbr' );

is( $d->quarter_abbr, 'Q3', '->quarter_abbr' );
is( $d->quarter_name, '3rd quarter', '->quarter_name' );

my $leap_d = DateTime->new( year => 2004,
month => 7,
day => 5,
Expand Down Expand Up @@ -128,7 +135,7 @@ is( $monday->day_of_week, 1, "Monday is day 1" );

is( $dt0->year, 1, "year 1 is year 1" );
is( $dt0->ce_year, 1, "ce_year 1 is year 1" );
is( $dt0->era, 'AD', 'era is AD' );
is( $dt0->era_abbr, 'AD', 'era is AD' );
is( $dt0->year_with_era, '1AD', 'year_with_era is 1AD' );
is( $dt0->christian_era, 'AD', 'christian_era is AD' );
is( $dt0->year_with_christian_era, '1AD', 'year_with_christian_era is 1AD' );
Expand All @@ -139,7 +146,7 @@ is( $monday->day_of_week, 1, "Monday is day 1" );

is( $dt0->year, 0, "year 1 minus 1 is year 0" );
is( $dt0->ce_year, -1, "ce_year 1 minus 1 is year -1" );
is( $dt0->era, 'BC', 'era is BC' );
is( $dt0->era_abbr, 'BC', 'era is BC' );
is( $dt0->year_with_era, '1BC', 'year_with_era is 1BC' );
is( $dt0->christian_era, 'BC', 'christian_era is BC' );
is( $dt0->year_with_christian_era, '1BC', 'year_with_christian_era is 1BC' );
Expand Down
18 changes: 18 additions & 0 deletions t/40leap-years.t
@@ -0,0 +1,18 @@
#!/usr/bin/perl -w

use strict;

use Test::More tests => 8;

use DateTime;


for my $y ( 0, 400, 2000, 2004 )
{
ok( DateTime->_is_leap_year($y), "$y is a leap year" );
}

for my $y ( 1, 100, 1900, 2133 )
{
ok( ! DateTime->_is_leap_year($y), "$y is not a leap year" );
}

0 comments on commit 0d21e8f

Please sign in to comment.