Changeset 352

Show
Ignore:
Timestamp:
11/21/01 02:29:52
Author:
miyagawa
Message:

0.02

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Date-Japanese-Era/trunk/README

    r230 r352  
    2323 
    2424METHODS 
     25    codeset 
     26          $codeset = Date::Japanese::Era->codeset; 
     27          Date::Japanese::Era->codeset($encoding); 
     28 
     29        sets / gets external encoding of Japanese era names. For example 
     30        with the following code, input and output of era names are encoded 
     31        in UTF-8. 
     32 
     33          Date::Japanese::Era->codeset('utf8'); 
     34          $era = Date::Japanese::Era->new($name, $year); # $name is UTF-8 
     35          print $era->name;                              # also UTF-8 
     36 
     37        You need Jcode module installed to make use of this feature. 
     38        Otherwise, calls to codeset() are simply ignored (with warning). 
     39 
    2540    new 
    2641          $era = Date::Japanese::Era->new($year, $month, $day); 
     
    3550        Default is EUC-JP. 
    3651 
    37         Exceptions are thrown when inputs are invalid (e.g: non-existent 
    38         era-name and year combination, unknwon era-name, etc.). 
    39  
    40     codeset 
    41           $codeset = Date::Japanese::Era->codeset; 
    42           Date::Japanese::Era->codeset($encoding); 
    43  
    44         sets / gets external encoding of Japanese era names. For example 
    45         with the follwing code, input and output of era names are encoded in 
    46         UTF-8. 
    47  
    48           Date::Japanese::Era->codeset('utf8'); 
    49           $era = Date::Japanese::Era->new($name, $year); # $name is UTF-8 
    50           print $era->name;                              # also UTF-8 
    51  
    52         You need Jcode module installed to make use of this feature. 
     52        Exceptions are thrown when inputs are invalid (e.g: non-existent era 
     53        name and year combination, unknwon era-name, etc.). 
    5354 
    5455    name 
     
    7778 
    7879EXAMPLES 
     80      use Date::Japanese::Era; 
     81 
    7982      # 2001 is H-13 
    8083      my $era = Date::Japanese::Era->new(2001, 8, 31); 
     
    8386      # to Gregorian 
    8487      my $era = Date::Japanese::Era->new('Ê¿À®', 13); 
    85       print $era->gregorian_year; 
     88      print $era->gregorian_year;   # 2001 
    8689 
    8790CAVEATS 
    88     *   The day era just changed is handled as newer one. 
     91    *   Days when era just changed are handled as newer (later) one. 
    8992 
    9093    *   Currently supported era is up to 'meiji'. 
    9194 
    92     *   If someday current era (heisei) is changed, Date::Japanese::Era 
    93         should be upgraded. (Table is declared as global variable, so you 
    94         can overwrite it if necessary). 
     95    *   If someday current era (heisei) is changed, 
     96        Date::Japanese::Era::Table should be upgraded. (Table is declared as 
     97        global variable, so you can overwrite it if necessary). 
    9598 
    9699TODO 
  • Date-Japanese-Era/trunk/lib/Date/Japanese/Era.pm

    r230 r352  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.01'; 
     5$VERSION = '0.02'; 
    66 
    77use Carp; 
    8 use Date::Japanese::Era::Table; 
     8use constant END_OF_LUNAR => 1872; 
     9 
     10use vars qw(@ISA @EXPORT %ERA_TABLE %ERA_JA2ASCII %ERA_ASCII2JA); 
    911 
    1012use vars qw($Have_Jcode); 
     
    2729} 
    2830 
     31sub import { 
     32    my $self = shift; 
     33    if (@_) { 
     34        my $table = shift; 
     35        eval qq{use Date::Japanese::Era::Table::$table}; 
     36        die $@ if $@; 
     37    } 
     38    else { 
     39        require Date::Japanese::Era::Table; 
     40        import Date::Japanese::Era::Table; 
     41    } 
     42} 
     43 
    2944sub new { 
    3045    my($class, @args) = @_; 
     
    4964sub _from_ymd { 
    5065    my($self, @ymd) = @_; 
     66 
     67    if ($ymd[0] <= END_OF_LUNAR) { 
     68        Carp::carp("In $ymd[0] they didn't use gregorious date."); 
     69    } 
    5170 
    5271    require Date::Calc;         # not 'use' 
     
    150169  $gregorian = $era->gregorian_year;       # 1977 
    151170 
     171  # use JIS X0301 table for conversion 
     172  use Date::Japanese::Era 'JIS_X0301'; 
     173 
     174 
    152175=head1 DESCRIPTION 
    153176 
     
    224247=head1 EXAMPLES 
    225248 
     249  use Date::Japanese::Era; 
     250 
    226251  # 2001 is H-13 
    227252  my $era = Date::Japanese::Era->new(2001, 8, 31); 
     
    238263=item * 
    239264 
    240 Days when era just changed are handled as newer (later) one. 
    241  
    242 =item * 
    243  
    244 Currently supported era is up to 'meiji'. 
     265Currently supported era is up to 'meiji'. And before Meiji 05.12.02, 
     266gregorius calendar was not used there, but lunar calendar was. This 
     267module does not support lunar calendar, but gives warnings in such 
     268cases ("In %d they didn't use gregorius calendar"). 
     269 
     270=item * 
     271 
     272There should be discussion how we handle the exact day the era has 
     273changed (former one or latter one?). This module default handles the 
     274day as newer one, but you can change so that it sticks to JIS table 
     275(older one) by saying: 
     276 
     277  use Date::Japanese::Era 'JIS_X0301'; 
     278 
     279For example, 1912-07-30 is handled as: 
     280 
     281  default       Taishou 1 07-30 
     282  JIS_X0301     Meiji 45 07-30 
    245283 
    246284=item * 
    247285 
    248286If someday current era (heisei) is changed, Date::Japanese::Era::Table 
    249 should be upgraded. (Table is declared as global variable, so you can 
    250 overwrite it if necessary). 
     287should be upgraded. 
    251288 
    252289=back 
     
    263300=item * 
    264301 
    265 Support earlier eras
     302Support earlier eras and lunar calendar
    266303 
    267304=back 
  • Date-Japanese-Era/trunk/t/00_Era.t

    r230 r352  
    11use strict; 
    2 use Test::More tests => 34
     2use Test::More tests => 35
    33 
    4 use Date::Japanese::Era; 
     4BEGIN { use_ok('Date::Japanese::Era'); } 
    55 
    66my @tests = ( 
     
    1313    [ 1912, 7, 30, 'taishou', 1 ], 
    1414    [ 1912, 7, 29, 'meiji', 45 ], 
    15     [ 1868, 9, 8, 'meiji', 1
     15    [ 1873, 1, 1, 'meiji', 6
    1616); 
    1717 
     
    2020    my $e1 = Date::Japanese::Era->new($year, $month, $day); 
    2121    if ($name =~ /^\w+$/) { 
    22         ok($e1->name_ascii eq $name, 'Gregorian to Japanese era (ASCII)'); 
     22        is($e1->name_ascii, $name, 'Gregorian to Japanese era (ASCII)'); 
    2323    } 
    2424    else { 
    25         ok($e1->name('euc') eq $name, 'Gregorian to Japanese era'); 
     25        is($e1->name('euc'), $name, 'Gregorian to Japanese era'); 
    2626    } 
    27     ok($e1->year == $era_year); 
     27    is($e1->year, $era_year); 
    2828 
    2929    my $e2 = Date::Japanese::Era->new($name, $era_year); 
    30     ok($e2->gregorian_year == $year, 'Japanese era to Gregorian'); 
     30    is($e2->gregorian_year, $year, 'Japanese era to Gregorian'); 
    3131} 
    3232 
     
    4343 
    4444for my $fail (@fail) { 
     45    local $SIG{__WARN__} = sub {}; 
    4546    eval { 
    4647        my $u = Date::Japanese::Era->new(@{$fail->[0]}); 
    4748    }; 
    48     ok($@ =~ /$fail->[1]/, 'various ways to fail'); 
     49    like($@, qr/$fail->[1]/, 'various ways to fail'); 
    4950} 
    5051 
     
    5455    Date::Japanese::Era->codeset('utf8'); 
    5556    my $era = Date::Japanese::Era->new($utf8, 52); 
    56     ok($era->name eq $utf8, 'input / output UTF-8'); 
     57    is($era->name, $utf8, 'input / output UTF-8'); 
    5758}; 
    5859