warekky 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
 - data/.gitignore +21 -0
 - data/LICENSE +20 -0
 - data/README.rdoc +26 -0
 - data/Rakefile +49 -0
 - data/VERSION +1 -0
 - data/lib/warekky/core_ext.rb +49 -0
 - data/lib/warekky/era.rb +44 -0
 - data/lib/warekky/era_group.rb +138 -0
 - data/lib/warekky/ja.rb +36 -0
 - data/lib/warekky.rb +49 -0
 - data/spec/core_ext/with_date_spec.rb +152 -0
 - data/spec/core_ext/with_date_time_spec.rb +156 -0
 - data/spec/core_ext/with_time_spec.rb +156 -0
 - data/spec/ja/with_date_spec.rb +142 -0
 - data/spec/ja/with_date_time_spec.rb +133 -0
 - data/spec/ja/with_time_spec.rb +133 -0
 - data/spec/rcov.opts +1 -0
 - data/spec/spec.opts +1 -0
 - data/spec/spec_helper.rb +9 -0
 - data/spec/warekky/era_group_spec.rb +121 -0
 - data/spec/warekky/era_spec.rb +100 -0
 - data/spec/warekky_spec.rb +32 -0
 - data/warekky.gemspec +76 -0
 - metadata +115 -0
 
| 
         @@ -0,0 +1,156 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            require File.expand_path('../spec_helper', File.dirname(__FILE__))
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe "Warekky" do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              before :all do
         
     | 
| 
      
 7 
     | 
    
         
            +
                Warekky.era_group_class = Warekky::Ja
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              describe :strftime do
         
     | 
| 
      
 11 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  DateTime.new(1867,12,31).strftime('%Y.%m.%d').should == "1867.12.31"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  DateTime.new(1868, 1, 1).strftime('%Y.%m.%d').should == "1868.01.01"
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  fmt = '%g%n/%m/%d'
         
     | 
| 
      
 18 
     | 
    
         
            +
                  DateTime.new(1867,12,31).strftime(fmt).should == "1867/12/31"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  DateTime.new(1868, 1, 1).strftime(fmt).should == "M01/01/01"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  DateTime.new(1912, 7,29).strftime(fmt).should == "M45/07/29"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  DateTime.new(1912, 7,30).strftime(fmt).should == "T01/07/30"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  DateTime.new(1926,12,24).strftime(fmt).should == "T15/12/24"
         
     | 
| 
      
 23 
     | 
    
         
            +
                  DateTime.new(1926,12,25).strftime(fmt).should == "S01/12/25"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  DateTime.new(1989, 1, 7).strftime(fmt).should == "S64/01/07"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  DateTime.new(1989, 1, 8).strftime(fmt).should == "H01/01/08"
         
     | 
| 
      
 26 
     | 
    
         
            +
                  DateTime.new(2010, 6, 9).strftime(fmt).should == "H22/06/09"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  DateTime.new(2050,12,31).strftime(fmt).should == "H62/12/31"
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  fmt = '%G%n/%m/%d'
         
     | 
| 
      
 32 
     | 
    
         
            +
                  DateTime.new(1867,12,31).strftime(fmt).should == "1867/12/31"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  DateTime.new(1868, 1, 1).strftime(fmt).should == "明治01/01/01"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  DateTime.new(1912, 7,29).strftime(fmt).should == "明治45/07/29"
         
     | 
| 
      
 35 
     | 
    
         
            +
                  DateTime.new(1912, 7,30).strftime(fmt).should == "大正01/07/30"
         
     | 
| 
      
 36 
     | 
    
         
            +
                  DateTime.new(1926,12,24).strftime(fmt).should == "大正15/12/24"
         
     | 
| 
      
 37 
     | 
    
         
            +
                  DateTime.new(1926,12,25).strftime(fmt).should == "昭和01/12/25"
         
     | 
| 
      
 38 
     | 
    
         
            +
                  DateTime.new(1989, 1, 7).strftime(fmt).should == "昭和64/01/07"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  DateTime.new(1989, 1, 8).strftime(fmt).should == "平成01/01/08"
         
     | 
| 
      
 40 
     | 
    
         
            +
                  DateTime.new(2010, 6, 9).strftime(fmt).should == "平成22/06/09"
         
     | 
| 
      
 41 
     | 
    
         
            +
                  DateTime.new(2050,12,31).strftime(fmt).should == "平成62/12/31"
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              describe :era do
         
     | 
| 
      
 47 
     | 
    
         
            +
                it "should return an era for date" do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  DateTime.new(1867,12,31).era.should == nil
         
     | 
| 
      
 49 
     | 
    
         
            +
                  DateTime.new(1868, 1, 1).era.name.should == 'meiji'
         
     | 
| 
      
 50 
     | 
    
         
            +
                  DateTime.new(1912, 7,29).era.name.should == 'meiji'
         
     | 
| 
      
 51 
     | 
    
         
            +
                  DateTime.new(1912, 7,30).era.name.should == 'taisho'
         
     | 
| 
      
 52 
     | 
    
         
            +
                  DateTime.new(1926,12,24).era.name.should == 'taisho'
         
     | 
| 
      
 53 
     | 
    
         
            +
                  DateTime.new(1926,12,25).era.name.should == 'showa'
         
     | 
| 
      
 54 
     | 
    
         
            +
                  DateTime.new(1989, 1, 7).era.name.should == 'showa'
         
     | 
| 
      
 55 
     | 
    
         
            +
                  DateTime.new(1989, 1, 8).era.name.should == 'heisei'
         
     | 
| 
      
 56 
     | 
    
         
            +
                  DateTime.new(2010, 6, 9).era.name.should == 'heisei'
         
     | 
| 
      
 57 
     | 
    
         
            +
                  DateTime.new(2050,12,31).era.name.should == 'heisei'
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              describe :parse do
         
     | 
| 
      
 62 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                  DateTime.parse("1867/12/31").should == DateTime.new(1867,12,31)
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  DateTime.parse("M01/01/01").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  DateTime.parse("M45/07/29").should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  DateTime.parse("T01/07/30").should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  DateTime.parse("T15/12/24").should == DateTime.new(1926,12,24)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  DateTime.parse("S01/12/25").should == DateTime.new(1926,12,25)
         
     | 
| 
      
 72 
     | 
    
         
            +
                  DateTime.parse("S64/01/07").should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  DateTime.parse("H01/01/08").should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  DateTime.parse("H22/06/09").should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  DateTime.parse("H62/12/31").should == DateTime.new(2050,12,31)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  DateTime.parse("H22/06/09 01:23:45").should == DateTime.new(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                it "区切りなし" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                  DateTime.parse("M010101").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  DateTime.parse("M450729").should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  DateTime.parse("T010730").should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  DateTime.parse("T151224").should == DateTime.new(1926,12,24)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  DateTime.parse("S011225").should == DateTime.new(1926,12,25)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  DateTime.parse("S640107").should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 86 
     | 
    
         
            +
                  DateTime.parse("H010108").should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  DateTime.parse("H220609").should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  DateTime.parse("H621231").should == DateTime.new(2050,12,31)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  DateTime.parse("H220609 012345").should == DateTime.new(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  DateTime.parse("H220609012345").should == DateTime.new(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 94 
     | 
    
         
            +
                  DateTime.parse("明治元年1月1日").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  DateTime.parse("明治1年1月1日").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  DateTime.parse("明治01年01月01日").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  DateTime.parse("明治45年07月29日").should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  DateTime.parse("大正01年07月30日").should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  DateTime.parse("大正15年12月24日").should == DateTime.new(1926,12,24)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  DateTime.parse("昭和01年12月25日").should == DateTime.new(1926,12,25)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  DateTime.parse("昭和64年01月07日").should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  DateTime.parse("平成01年01月08日").should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  DateTime.parse("平成22年06月09日").should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  DateTime.parse("平成62年12月31日").should == DateTime.new(2050,12,31)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  DateTime.parse("平成22年06月09日 12時34分56秒").should == DateTime.new(2010, 6, 9, 12, 34, 56)
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                it "with chinese charactor short era name (漢字省略表記の元号)" do
         
     | 
| 
      
 109 
     | 
    
         
            +
                  DateTime.parse("明元年1月1日").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  DateTime.parse("明1年1月1日").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 111 
     | 
    
         
            +
                  DateTime.parse("明01年01月01日").should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 112 
     | 
    
         
            +
                  DateTime.parse("明45年07月29日").should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 113 
     | 
    
         
            +
                  DateTime.parse("大01年07月30日").should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 114 
     | 
    
         
            +
                  DateTime.parse("大15年12月24日").should == DateTime.new(1926,12,24)
         
     | 
| 
      
 115 
     | 
    
         
            +
                  DateTime.parse("昭01年12月25日").should == DateTime.new(1926,12,25)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  DateTime.parse("昭64年01月07日").should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 117 
     | 
    
         
            +
                  DateTime.parse("平01年01月08日").should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 118 
     | 
    
         
            +
                  DateTime.parse("平22年06月09日").should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  DateTime.parse("平62年12月31日").should == DateTime.new(2050,12,31)
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
              end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
              describe :[] do
         
     | 
| 
      
 125 
     | 
    
         
            +
                describe "should return an Era object" do
         
     | 
| 
      
 126 
     | 
    
         
            +
                  it "for era_name" do
         
     | 
| 
      
 127 
     | 
    
         
            +
                    [:meiji, :taisho, :showa, :heisei].each do |era|
         
     | 
| 
      
 128 
     | 
    
         
            +
                      DateTime.eras[era].class.should == Warekky::Era
         
     | 
| 
      
 129 
     | 
    
         
            +
                      DateTime.eras[era.to_s].class.should == Warekky::Era
         
     | 
| 
      
 130 
     | 
    
         
            +
                    end
         
     | 
| 
      
 131 
     | 
    
         
            +
                    DateTime.eras[nil].should == nil
         
     | 
| 
      
 132 
     | 
    
         
            +
                    DateTime.eras[''].should == nil
         
     | 
| 
      
 133 
     | 
    
         
            +
                    DateTime.eras[:unexist_era].should == nil
         
     | 
| 
      
 134 
     | 
    
         
            +
                  end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                  it "for era_name with kanji" do
         
     | 
| 
      
 137 
     | 
    
         
            +
                    %w[M T S H 明治 大正 昭和 平成 明 大 昭 平].each do |era|
         
     | 
| 
      
 138 
     | 
    
         
            +
                      DateTime.eras[era].class.should == Warekky::Era
         
     | 
| 
      
 139 
     | 
    
         
            +
                    end
         
     | 
| 
      
 140 
     | 
    
         
            +
                  end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                  it "for date" do
         
     | 
| 
      
 143 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1867,12,31)].should == nil
         
     | 
| 
      
 144 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1868, 1, 1)].name.should == 'meiji'
         
     | 
| 
      
 145 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1912, 7,29)].name.should == 'meiji'
         
     | 
| 
      
 146 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1912, 7,30)].name.should == 'taisho'
         
     | 
| 
      
 147 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1926,12,24)].name.should == 'taisho'
         
     | 
| 
      
 148 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1926,12,25)].name.should == 'showa'
         
     | 
| 
      
 149 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1989, 1, 7)].name.should == 'showa'
         
     | 
| 
      
 150 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(1989, 1, 8)].name.should == 'heisei'
         
     | 
| 
      
 151 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(2010, 6, 9)].name.should == 'heisei'
         
     | 
| 
      
 152 
     | 
    
         
            +
                    DateTime.eras[DateTime.new(2050,12,31)].name.should == 'heisei'
         
     | 
| 
      
 153 
     | 
    
         
            +
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                end
         
     | 
| 
      
 155 
     | 
    
         
            +
              end
         
     | 
| 
      
 156 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,156 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            require File.expand_path('../spec_helper', File.dirname(__FILE__))
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe "Warekky" do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              before :all do
         
     | 
| 
      
 7 
     | 
    
         
            +
                Warekky.era_group_class = Warekky::Ja
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              describe :strftime do
         
     | 
| 
      
 11 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  Time.local(1867,12,31).strftime('%Y.%m.%d').should == "1867.12.31"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  Time.local(1868, 1, 1).strftime('%Y.%m.%d').should == "1868.01.01"
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  fmt = '%g%n/%m/%d'
         
     | 
| 
      
 18 
     | 
    
         
            +
                  Time.local(1867,12,31).strftime(fmt).should == "1867/12/31"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  Time.local(1868, 1, 1).strftime(fmt).should == "M01/01/01"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  Time.local(1912, 7,29).strftime(fmt).should == "M45/07/29"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Time.local(1912, 7,30).strftime(fmt).should == "T01/07/30"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  Time.local(1926,12,24).strftime(fmt).should == "T15/12/24"
         
     | 
| 
      
 23 
     | 
    
         
            +
                  Time.local(1926,12,25).strftime(fmt).should == "S01/12/25"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Time.local(1989, 1, 7).strftime(fmt).should == "S64/01/07"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  Time.local(1989, 1, 8).strftime(fmt).should == "H01/01/08"
         
     | 
| 
      
 26 
     | 
    
         
            +
                  Time.local(2010, 6, 9).strftime(fmt).should == "H22/06/09"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  Time.local(2050,12,31).strftime(fmt).should == "H62/12/31"
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  fmt = '%G%n/%m/%d'
         
     | 
| 
      
 32 
     | 
    
         
            +
                  Time.local(1867,12,31).strftime(fmt).should == "1867/12/31"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Time.local(1868, 1, 1).strftime(fmt).should == "明治01/01/01"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  Time.local(1912, 7,29).strftime(fmt).should == "明治45/07/29"
         
     | 
| 
      
 35 
     | 
    
         
            +
                  Time.local(1912, 7,30).strftime(fmt).should == "大正01/07/30"
         
     | 
| 
      
 36 
     | 
    
         
            +
                  Time.local(1926,12,24).strftime(fmt).should == "大正15/12/24"
         
     | 
| 
      
 37 
     | 
    
         
            +
                  Time.local(1926,12,25).strftime(fmt).should == "昭和01/12/25"
         
     | 
| 
      
 38 
     | 
    
         
            +
                  Time.local(1989, 1, 7).strftime(fmt).should == "昭和64/01/07"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  Time.local(1989, 1, 8).strftime(fmt).should == "平成01/01/08"
         
     | 
| 
      
 40 
     | 
    
         
            +
                  Time.local(2010, 6, 9).strftime(fmt).should == "平成22/06/09"
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Time.local(2050,12,31).strftime(fmt).should == "平成62/12/31"
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              describe :era do
         
     | 
| 
      
 47 
     | 
    
         
            +
                it "should return an era for date" do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  Time.local(1867,12,31).era.should == nil
         
     | 
| 
      
 49 
     | 
    
         
            +
                  Time.local(1868, 1, 1).era.name.should == 'meiji'
         
     | 
| 
      
 50 
     | 
    
         
            +
                  Time.local(1912, 7,29).era.name.should == 'meiji'
         
     | 
| 
      
 51 
     | 
    
         
            +
                  Time.local(1912, 7,30).era.name.should == 'taisho'
         
     | 
| 
      
 52 
     | 
    
         
            +
                  Time.local(1926,12,24).era.name.should == 'taisho'
         
     | 
| 
      
 53 
     | 
    
         
            +
                  Time.local(1926,12,25).era.name.should == 'showa'
         
     | 
| 
      
 54 
     | 
    
         
            +
                  Time.local(1989, 1, 7).era.name.should == 'showa'
         
     | 
| 
      
 55 
     | 
    
         
            +
                  Time.local(1989, 1, 8).era.name.should == 'heisei'
         
     | 
| 
      
 56 
     | 
    
         
            +
                  Time.local(2010, 6, 9).era.name.should == 'heisei'
         
     | 
| 
      
 57 
     | 
    
         
            +
                  Time.local(2050,12,31).era.name.should == 'heisei'
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              describe :parse do
         
     | 
| 
      
 62 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                  Time.parse("1867/12/31").should == Time.local(1867,12,31)
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  Time.parse("M01/01/01").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  Time.parse("M45/07/29").should == Time.local(1912, 7,29)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  Time.parse("T01/07/30").should == Time.local(1912, 7,30)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  Time.parse("T15/12/24").should == Time.local(1926,12,24)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  Time.parse("S01/12/25").should == Time.local(1926,12,25)
         
     | 
| 
      
 72 
     | 
    
         
            +
                  Time.parse("S64/01/07").should == Time.local(1989, 1, 7)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  Time.parse("H01/01/08").should == Time.local(1989, 1, 8)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  Time.parse("H22/06/09").should == Time.local(2010, 6, 9)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  Time.parse("H62/12/31").should == Time.local(2050,12,31)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  Time.parse("H22/06/09 01:23:45").should == Time.local(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                it "区切りなし" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                  Time.parse("M010101").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  Time.parse("M450729").should == Time.local(1912, 7,29)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  Time.parse("T010730").should == Time.local(1912, 7,30)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  Time.parse("T151224").should == Time.local(1926,12,24)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  Time.parse("S011225").should == Time.local(1926,12,25)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  Time.parse("S640107").should == Time.local(1989, 1, 7)
         
     | 
| 
      
 86 
     | 
    
         
            +
                  Time.parse("H010108").should == Time.local(1989, 1, 8)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  Time.parse("H220609").should == Time.local(2010, 6, 9)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  Time.parse("H621231").should == Time.local(2050,12,31)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  Time.parse("H220609 012345").should == Time.local(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  Time.parse("H220609012345").should == Time.local(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 94 
     | 
    
         
            +
                  Time.parse("明治元年1月1日").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  Time.parse("明治1年1月1日").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  Time.parse("明治01年01月01日").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  Time.parse("明治45年07月29日").should == Time.local(1912, 7,29)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  Time.parse("大正01年07月30日").should == Time.local(1912, 7,30)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  Time.parse("大正15年12月24日").should == Time.local(1926,12,24)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  Time.parse("昭和01年12月25日").should == Time.local(1926,12,25)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  Time.parse("昭和64年01月07日").should == Time.local(1989, 1, 7)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  Time.parse("平成01年01月08日").should == Time.local(1989, 1, 8)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  Time.parse("平成22年06月09日").should == Time.local(2010, 6, 9)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  Time.parse("平成62年12月31日").should == Time.local(2050,12,31)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  Time.parse("平成22年06月09日 12時34分56秒").should == Time.local(2010, 6, 9, 12, 34, 56)
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                it "with chinese charactor short era name (漢字省略表記の元号)" do
         
     | 
| 
      
 109 
     | 
    
         
            +
                  Time.parse("明元年1月1日").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  Time.parse("明1年1月1日").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 111 
     | 
    
         
            +
                  Time.parse("明01年01月01日").should == Time.local(1868, 1, 1)
         
     | 
| 
      
 112 
     | 
    
         
            +
                  Time.parse("明45年07月29日").should == Time.local(1912, 7,29)
         
     | 
| 
      
 113 
     | 
    
         
            +
                  Time.parse("大01年07月30日").should == Time.local(1912, 7,30)
         
     | 
| 
      
 114 
     | 
    
         
            +
                  Time.parse("大15年12月24日").should == Time.local(1926,12,24)
         
     | 
| 
      
 115 
     | 
    
         
            +
                  Time.parse("昭01年12月25日").should == Time.local(1926,12,25)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  Time.parse("昭64年01月07日").should == Time.local(1989, 1, 7)
         
     | 
| 
      
 117 
     | 
    
         
            +
                  Time.parse("平01年01月08日").should == Time.local(1989, 1, 8)
         
     | 
| 
      
 118 
     | 
    
         
            +
                  Time.parse("平22年06月09日").should == Time.local(2010, 6, 9)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  Time.parse("平62年12月31日").should == Time.local(2050,12,31)
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
              end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
              describe :[] do
         
     | 
| 
      
 125 
     | 
    
         
            +
                describe "should return an Era object" do
         
     | 
| 
      
 126 
     | 
    
         
            +
                  it "for era_name" do
         
     | 
| 
      
 127 
     | 
    
         
            +
                    [:meiji, :taisho, :showa, :heisei].each do |era|
         
     | 
| 
      
 128 
     | 
    
         
            +
                      Time.eras[era].class.should == Warekky::Era
         
     | 
| 
      
 129 
     | 
    
         
            +
                      Time.eras[era.to_s].class.should == Warekky::Era
         
     | 
| 
      
 130 
     | 
    
         
            +
                    end
         
     | 
| 
      
 131 
     | 
    
         
            +
                    Time.eras[nil].should == nil
         
     | 
| 
      
 132 
     | 
    
         
            +
                    Time.eras[''].should == nil
         
     | 
| 
      
 133 
     | 
    
         
            +
                    Time.eras[:unexist_era].should == nil
         
     | 
| 
      
 134 
     | 
    
         
            +
                  end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                  it "for era_name with kanji" do
         
     | 
| 
      
 137 
     | 
    
         
            +
                    %w[M T S H 明治 大正 昭和 平成 明 大 昭 平].each do |era|
         
     | 
| 
      
 138 
     | 
    
         
            +
                      Time.eras[era].class.should == Warekky::Era
         
     | 
| 
      
 139 
     | 
    
         
            +
                    end
         
     | 
| 
      
 140 
     | 
    
         
            +
                  end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                  it "for date" do
         
     | 
| 
      
 143 
     | 
    
         
            +
                    Time.eras[Time.local(1867,12,31)].should == nil
         
     | 
| 
      
 144 
     | 
    
         
            +
                    Time.eras[Time.local(1868, 1, 1)].name.should == 'meiji'
         
     | 
| 
      
 145 
     | 
    
         
            +
                    Time.eras[Time.local(1912, 7,29)].name.should == 'meiji'
         
     | 
| 
      
 146 
     | 
    
         
            +
                    Time.eras[Time.local(1912, 7,30)].name.should == 'taisho'
         
     | 
| 
      
 147 
     | 
    
         
            +
                    Time.eras[Time.local(1926,12,24)].name.should == 'taisho'
         
     | 
| 
      
 148 
     | 
    
         
            +
                    Time.eras[Time.local(1926,12,25)].name.should == 'showa'
         
     | 
| 
      
 149 
     | 
    
         
            +
                    Time.eras[Time.local(1989, 1, 7)].name.should == 'showa'
         
     | 
| 
      
 150 
     | 
    
         
            +
                    Time.eras[Time.local(1989, 1, 8)].name.should == 'heisei'
         
     | 
| 
      
 151 
     | 
    
         
            +
                    Time.eras[Time.local(2010, 6, 9)].name.should == 'heisei'
         
     | 
| 
      
 152 
     | 
    
         
            +
                    Time.eras[Time.local(2050,12,31)].name.should == 'heisei'
         
     | 
| 
      
 153 
     | 
    
         
            +
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                end
         
     | 
| 
      
 155 
     | 
    
         
            +
              end
         
     | 
| 
      
 156 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,142 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            require File.expand_path('../spec_helper', File.dirname(__FILE__))
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe "Warekky" do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              before :all do
         
     | 
| 
      
 7 
     | 
    
         
            +
                Warekky.era_group_class = Warekky::Ja
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              describe :strftime do
         
     | 
| 
      
 11 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1867,12,31), '%Y.%m.%d').should == "1867.12.31"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1868, 1, 1), '%Y.%m.%d').should == "1868.01.01"
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  fmt = '%g%n/%m/%d'
         
     | 
| 
      
 18 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1867,12,31), fmt).should == "1867/12/31"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1868, 1, 1), fmt).should == "M01/01/01"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1912, 7,29), fmt).should == "M45/07/29"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1912, 7,30), fmt).should == "T01/07/30"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1926,12,24), fmt).should == "T15/12/24"
         
     | 
| 
      
 23 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1926,12,25), fmt).should == "S01/12/25"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1989, 1, 7), fmt).should == "S64/01/07"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1989, 1, 8), fmt).should == "H01/01/08"
         
     | 
| 
      
 26 
     | 
    
         
            +
                  Warekky.strftime(Date.new(2010, 6, 9), fmt).should == "H22/06/09"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  Warekky.strftime(Date.new(2050,12,31), fmt).should == "H62/12/31"
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  fmt = '%G%n/%m/%d'
         
     | 
| 
      
 32 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1867,12,31), fmt).should == "1867/12/31"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1868, 1, 1), fmt).should == "明治01/01/01"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1912, 7,29), fmt).should == "明治45/07/29"
         
     | 
| 
      
 35 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1912, 7,30), fmt).should == "大正01/07/30"
         
     | 
| 
      
 36 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1926,12,24), fmt).should == "大正15/12/24"
         
     | 
| 
      
 37 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1926,12,25), fmt).should == "昭和01/12/25"
         
     | 
| 
      
 38 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1989, 1, 7), fmt).should == "昭和64/01/07"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  Warekky.strftime(Date.new(1989, 1, 8), fmt).should == "平成01/01/08"
         
     | 
| 
      
 40 
     | 
    
         
            +
                  Warekky.strftime(Date.new(2010, 6, 9), fmt).should == "平成22/06/09"
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Warekky.strftime(Date.new(2050,12,31), fmt).should == "平成62/12/31"
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              describe :parse do
         
     | 
| 
      
 46 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  Warekky.parse("1867/12/31").should == Date.new(1867,12,31)
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  Warekky.parse("M01/01/01").should == Date.new(1868, 1, 1)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  Warekky.parse("M45/07/29").should == Date.new(1912, 7,29)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  Warekky.parse("T01/07/30").should == Date.new(1912, 7,30)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  Warekky.parse("T15/12/24").should == Date.new(1926,12,24)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  Warekky.parse("S01/12/25").should == Date.new(1926,12,25)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  Warekky.parse("S64/01/07").should == Date.new(1989, 1, 7)
         
     | 
| 
      
 57 
     | 
    
         
            +
                  Warekky.parse("H01/01/08").should == Date.new(1989, 1, 8)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  Warekky.parse("H22/06/09").should == Date.new(2010, 6, 9)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  Warekky.parse("H62/12/31").should == Date.new(2050,12,31)
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                context "区切りなし" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                  it "by Time.parse" do
         
     | 
| 
      
 64 
     | 
    
         
            +
                    Date.parse("18671231").should == Date.new(1867, 12, 31)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  it "by Warekky.parse" do
         
     | 
| 
      
 68 
     | 
    
         
            +
                    Warekky.parse("M010101", :class => Date).should == Date.new(1868, 1, 1)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    Warekky.parse("M450729", :class => Date).should == Date.new(1912, 7,29)
         
     | 
| 
      
 70 
     | 
    
         
            +
                    Warekky.parse("T010730", :class => Date).should == Date.new(1912, 7,30)
         
     | 
| 
      
 71 
     | 
    
         
            +
                    Warekky.parse("T151224", :class => Date).should == Date.new(1926,12,24)
         
     | 
| 
      
 72 
     | 
    
         
            +
                    Warekky.parse("S011225", :class => Date).should == Date.new(1926,12,25)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    Warekky.parse("S640107", :class => Date).should == Date.new(1989, 1, 7)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    Warekky.parse("H010108", :class => Date).should == Date.new(1989, 1, 8)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    Warekky.parse("H220609", :class => Date).should == Date.new(2010, 6, 9)
         
     | 
| 
      
 76 
     | 
    
         
            +
                    Warekky.parse("H621231", :class => Date).should == Date.new(2050,12,31)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  end
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  Warekky.parse("明治元年1月1日").should == Date.new(1868, 1, 1)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  Warekky.parse("明治1年1月1日").should == Date.new(1868, 1, 1)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  Warekky.parse("明治01年01月01日").should == Date.new(1868, 1, 1)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  Warekky.parse("明治45年07月29日").should == Date.new(1912, 7,29)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  Warekky.parse("大正01年07月30日").should == Date.new(1912, 7,30)
         
     | 
| 
      
 86 
     | 
    
         
            +
                  Warekky.parse("大正15年12月24日").should == Date.new(1926,12,24)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  Warekky.parse("昭和01年12月25日").should == Date.new(1926,12,25)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  Warekky.parse("昭和64年01月07日").should == Date.new(1989, 1, 7)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  Warekky.parse("平成01年01月08日").should == Date.new(1989, 1, 8)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  Warekky.parse("平成22年06月09日").should == Date.new(2010, 6, 9)
         
     | 
| 
      
 91 
     | 
    
         
            +
                  Warekky.parse("平成62年12月31日").should == Date.new(2050,12,31)
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                it "with chinese charactor short era name (漢字省略表記の元号)" do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  Warekky.parse("明元年1月1日").should == Date.new(1868, 1, 1)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  Warekky.parse("明1年1月1日").should == Date.new(1868, 1, 1)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  Warekky.parse("明01年01月01日").should == Date.new(1868, 1, 1)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  Warekky.parse("明45年07月29日").should == Date.new(1912, 7,29)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  Warekky.parse("大01年07月30日").should == Date.new(1912, 7,30)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  Warekky.parse("大15年12月24日").should == Date.new(1926,12,24)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  Warekky.parse("昭01年12月25日").should == Date.new(1926,12,25)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  Warekky.parse("昭64年01月07日").should == Date.new(1989, 1, 7)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  Warekky.parse("平01年01月08日").should == Date.new(1989, 1, 8)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  Warekky.parse("平22年06月09日").should == Date.new(2010, 6, 9)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  Warekky.parse("平62年12月31日").should == Date.new(2050,12,31)
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
              end
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
              describe :[] do
         
     | 
| 
      
 111 
     | 
    
         
            +
                describe "should return an Era object" do
         
     | 
| 
      
 112 
     | 
    
         
            +
                  it "for era_name" do
         
     | 
| 
      
 113 
     | 
    
         
            +
                    [:meiji, :taisho, :showa, :heisei].each do |era|
         
     | 
| 
      
 114 
     | 
    
         
            +
                      Warekky[era].class.should == Warekky::Era
         
     | 
| 
      
 115 
     | 
    
         
            +
                      Warekky[era.to_s].class.should == Warekky::Era
         
     | 
| 
      
 116 
     | 
    
         
            +
                    end
         
     | 
| 
      
 117 
     | 
    
         
            +
                    Warekky[nil].should == nil
         
     | 
| 
      
 118 
     | 
    
         
            +
                    Warekky[''].should == nil
         
     | 
| 
      
 119 
     | 
    
         
            +
                    Warekky[:unexist_era].should == nil
         
     | 
| 
      
 120 
     | 
    
         
            +
                  end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                  it "for era_name with kanji" do
         
     | 
| 
      
 123 
     | 
    
         
            +
                    %w[M T S H 明治 大正 昭和 平成 明 大 昭 平].each do |era|
         
     | 
| 
      
 124 
     | 
    
         
            +
                      Warekky[era].class.should == Warekky::Era
         
     | 
| 
      
 125 
     | 
    
         
            +
                    end
         
     | 
| 
      
 126 
     | 
    
         
            +
                  end
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                  it "for date" do
         
     | 
| 
      
 129 
     | 
    
         
            +
                    Warekky[Date.new(1867,12,31)].should == nil
         
     | 
| 
      
 130 
     | 
    
         
            +
                    Warekky[Date.new(1868, 1, 1)].name.should == 'meiji'
         
     | 
| 
      
 131 
     | 
    
         
            +
                    Warekky[Date.new(1912, 7,29)].name.should == 'meiji'
         
     | 
| 
      
 132 
     | 
    
         
            +
                    Warekky[Date.new(1912, 7,30)].name.should == 'taisho'
         
     | 
| 
      
 133 
     | 
    
         
            +
                    Warekky[Date.new(1926,12,24)].name.should == 'taisho'
         
     | 
| 
      
 134 
     | 
    
         
            +
                    Warekky[Date.new(1926,12,25)].name.should == 'showa'
         
     | 
| 
      
 135 
     | 
    
         
            +
                    Warekky[Date.new(1989, 1, 7)].name.should == 'showa'
         
     | 
| 
      
 136 
     | 
    
         
            +
                    Warekky[Date.new(1989, 1, 8)].name.should == 'heisei'
         
     | 
| 
      
 137 
     | 
    
         
            +
                    Warekky[Date.new(2010, 6, 9)].name.should == 'heisei'
         
     | 
| 
      
 138 
     | 
    
         
            +
                    Warekky[Date.new(2050,12,31)].name.should == 'heisei'
         
     | 
| 
      
 139 
     | 
    
         
            +
                  end
         
     | 
| 
      
 140 
     | 
    
         
            +
                end
         
     | 
| 
      
 141 
     | 
    
         
            +
              end
         
     | 
| 
      
 142 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,133 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            require File.expand_path('../spec_helper', File.dirname(__FILE__))
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe "Warekky" do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              before :all do
         
     | 
| 
      
 7 
     | 
    
         
            +
                Warekky.era_group_class = Warekky::Ja
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              describe :strftime do
         
     | 
| 
      
 11 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1867,12,31), '%Y.%m.%d').should == "1867.12.31"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1868, 1, 1), '%Y.%m.%d').should == "1868.01.01"
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  fmt = '%g%n/%m/%d'
         
     | 
| 
      
 18 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1867,12,31), fmt).should == "1867/12/31"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1868, 1, 1), fmt).should == "M01/01/01"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1912, 7,29), fmt).should == "M45/07/29"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1912, 7,30), fmt).should == "T01/07/30"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1926,12,24), fmt).should == "T15/12/24"
         
     | 
| 
      
 23 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1926,12,25), fmt).should == "S01/12/25"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1989, 1, 7), fmt).should == "S64/01/07"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1989, 1, 8), fmt).should == "H01/01/08"
         
     | 
| 
      
 26 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(2010, 6, 9), fmt).should == "H22/06/09"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(2050,12,31), fmt).should == "H62/12/31"
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  fmt = '%G%n/%m/%d'
         
     | 
| 
      
 32 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1867,12,31), fmt).should == "1867/12/31"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1868, 1, 1), fmt).should == "明治01/01/01"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1912, 7,29), fmt).should == "明治45/07/29"
         
     | 
| 
      
 35 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1912, 7,30), fmt).should == "大正01/07/30"
         
     | 
| 
      
 36 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1926,12,24), fmt).should == "大正15/12/24"
         
     | 
| 
      
 37 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1926,12,25), fmt).should == "昭和01/12/25"
         
     | 
| 
      
 38 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1989, 1, 7), fmt).should == "昭和64/01/07"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(1989, 1, 8), fmt).should == "平成01/01/08"
         
     | 
| 
      
 40 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(2010, 6, 9), fmt).should == "平成22/06/09"
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Warekky.strftime(DateTime.new(2050,12,31), fmt).should == "平成62/12/31"
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              describe :parse do
         
     | 
| 
      
 46 
     | 
    
         
            +
                it "without era name (元号の指定なし)" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  Warekky.parse("1867/12/31", :class => DateTime).should == DateTime.new(1867,12,31)
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                it "with alphabet era name (アルファベット表記の元号)" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  Warekky.parse("M01/01/01", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  Warekky.parse("M45/07/29", :class => DateTime).should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  Warekky.parse("T01/07/30", :class => DateTime).should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  Warekky.parse("T15/12/24", :class => DateTime).should == DateTime.new(1926,12,24)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  Warekky.parse("S01/12/25", :class => DateTime).should == DateTime.new(1926,12,25)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  Warekky.parse("S64/01/07", :class => DateTime).should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 57 
     | 
    
         
            +
                  Warekky.parse("H01/01/08", :class => DateTime).should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  Warekky.parse("H22/06/09", :class => DateTime).should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  Warekky.parse("H62/12/31", :class => DateTime).should == DateTime.new(2050,12,31)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  Warekky.parse("H22/06/09 01:23:45", :class => DateTime).should == DateTime.new(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                context "区切りなし" do
         
     | 
| 
      
 64 
     | 
    
         
            +
                  it "by Time.parse" do
         
     | 
| 
      
 65 
     | 
    
         
            +
                    DateTime.parse("18671231").should == DateTime.new(1867, 12, 31)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    DateTime.parse("18671231 012345") == DateTime.new(1867, 12, 31, 1, 23, 45)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    DateTime.parse("18671231012345") == DateTime.new(1867, 12, 31, 1, 23, 45)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                  it "by Warekky.parse" do
         
     | 
| 
      
 71 
     | 
    
         
            +
                    Warekky.parse("M010101", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 72 
     | 
    
         
            +
                    Warekky.parse("M450729", :class => DateTime).should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    Warekky.parse("T010730", :class => DateTime).should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    Warekky.parse("T151224", :class => DateTime).should == DateTime.new(1926,12,24)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    Warekky.parse("S011225", :class => DateTime).should == DateTime.new(1926,12,25)
         
     | 
| 
      
 76 
     | 
    
         
            +
                    Warekky.parse("S640107", :class => DateTime).should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    Warekky.parse("H010108", :class => DateTime).should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 78 
     | 
    
         
            +
                    Warekky.parse("H220609", :class => DateTime).should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 79 
     | 
    
         
            +
                    Warekky.parse("H621231", :class => DateTime).should == DateTime.new(2050,12,31)
         
     | 
| 
      
 80 
     | 
    
         
            +
                    Warekky.parse("H220609 012345", :class => DateTime).should == DateTime.new(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    Warekky.parse("H220609012345", :class => DateTime).should == DateTime.new(2010, 6, 9, 1, 23, 45)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  end
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                it "with chinese charactor era name (漢字表記の元号)" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  Warekky.parse("明治元年1月1日", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  Warekky.parse("明治1年1月1日", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  Warekky.parse("明治01年01月01日", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  Warekky.parse("明治45年07月29日", :class => DateTime).should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  Warekky.parse("大正01年07月30日", :class => DateTime).should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 91 
     | 
    
         
            +
                  Warekky.parse("大正15年12月24日", :class => DateTime).should == DateTime.new(1926,12,24)
         
     | 
| 
      
 92 
     | 
    
         
            +
                  Warekky.parse("昭和01年12月25日", :class => DateTime).should == DateTime.new(1926,12,25)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  Warekky.parse("昭和64年01月07日", :class => DateTime).should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 94 
     | 
    
         
            +
                  Warekky.parse("平成01年01月08日", :class => DateTime).should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  Warekky.parse("平成22年06月09日", :class => DateTime).should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  Warekky.parse("平成62年12月31日", :class => DateTime).should == DateTime.new(2050,12,31)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  Warekky.parse("平成22年06月09日 12時34分56秒", :class => DateTime).should == DateTime.new(2010, 6, 9, 12, 34, 56)
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                it "with chinese charactor short era name (漢字省略表記の元号)" do
         
     | 
| 
      
 101 
     | 
    
         
            +
                  Warekky.parse("明元年1月1日", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  Warekky.parse("明1年1月1日", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  Warekky.parse("明01年01月01日", :class => DateTime).should == DateTime.new(1868, 1, 1)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  Warekky.parse("明45年07月29日", :class => DateTime).should == DateTime.new(1912, 7,29)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  Warekky.parse("大01年07月30日", :class => DateTime).should == DateTime.new(1912, 7,30)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  Warekky.parse("大15年12月24日", :class => DateTime).should == DateTime.new(1926,12,24)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  Warekky.parse("昭01年12月25日", :class => DateTime).should == DateTime.new(1926,12,25)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  Warekky.parse("昭64年01月07日", :class => DateTime).should == DateTime.new(1989, 1, 7)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  Warekky.parse("平01年01月08日", :class => DateTime).should == DateTime.new(1989, 1, 8)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  Warekky.parse("平22年06月09日", :class => DateTime).should == DateTime.new(2010, 6, 9)
         
     | 
| 
      
 111 
     | 
    
         
            +
                  Warekky.parse("平62年12月31日", :class => DateTime).should == DateTime.new(2050,12,31)
         
     | 
| 
      
 112 
     | 
    
         
            +
                end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
              end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
              describe :[] do
         
     | 
| 
      
 118 
     | 
    
         
            +
                describe "should return an Era object" do
         
     | 
| 
      
 119 
     | 
    
         
            +
                  it "for date" do
         
     | 
| 
      
 120 
     | 
    
         
            +
                    Warekky[DateTime.new(1867,12,31)].should == nil
         
     | 
| 
      
 121 
     | 
    
         
            +
                    Warekky[DateTime.new(1868, 1, 1)].name.should == 'meiji'
         
     | 
| 
      
 122 
     | 
    
         
            +
                    Warekky[DateTime.new(1912, 7,29)].name.should == 'meiji'
         
     | 
| 
      
 123 
     | 
    
         
            +
                    Warekky[DateTime.new(1912, 7,30)].name.should == 'taisho'
         
     | 
| 
      
 124 
     | 
    
         
            +
                    Warekky[DateTime.new(1926,12,24)].name.should == 'taisho'
         
     | 
| 
      
 125 
     | 
    
         
            +
                    Warekky[DateTime.new(1926,12,25)].name.should == 'showa'
         
     | 
| 
      
 126 
     | 
    
         
            +
                    Warekky[DateTime.new(1989, 1, 7)].name.should == 'showa'
         
     | 
| 
      
 127 
     | 
    
         
            +
                    Warekky[DateTime.new(1989, 1, 8)].name.should == 'heisei'
         
     | 
| 
      
 128 
     | 
    
         
            +
                    Warekky[DateTime.new(2010, 6, 9)].name.should == 'heisei'
         
     | 
| 
      
 129 
     | 
    
         
            +
                    Warekky[DateTime.new(2050,12,31)].name.should == 'heisei'
         
     | 
| 
      
 130 
     | 
    
         
            +
                  end
         
     | 
| 
      
 131 
     | 
    
         
            +
                end
         
     | 
| 
      
 132 
     | 
    
         
            +
              end
         
     | 
| 
      
 133 
     | 
    
         
            +
            end
         
     |