warekky 0.1.0 → 0.1.1

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.
@@ -8,6 +8,9 @@ warekkyは和暦サポートのためのライブラリです。
8
8
 
9
9
  == Simple Usage
10
10
  $ irb
11
+ require 'rubygems'
12
+ #=> false
13
+
11
14
  require 'warekky'
12
15
  #=> true
13
16
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -24,7 +24,7 @@ module Warekky
24
24
  def strftime(d, format)
25
25
  era_group ?
26
26
  era_group.strftime(d, format) :
27
- d.strftime(format)
27
+ try_without(d, :strftime, format)
28
28
  end
29
29
 
30
30
  def parse(str, options = {})
@@ -17,7 +17,7 @@ module Warekky
17
17
  # strftimeで使える記号
18
18
  format('%G'){|era, era_year| era[:long] if era} # 明治/大正/昭和/平成
19
19
  format('%g'){|era, era_year| era.sign if era} # M/T/S/H
20
- format('%n'){|era, era_year| '%02d' % era_year} # (元号での)年度
20
+ format('%N'){|era, era_year| '%02d' % era_year} # (元号での)年度
21
21
 
22
22
  # parseで使われる元号毎の正規表現
23
23
  parse_regexp do |era|
@@ -14,7 +14,7 @@ describe "Warekky" do
14
14
  end
15
15
 
16
16
  it "with alphabet era name (アルファベット表記の元号)" do
17
- fmt = '%g%n/%m/%d'
17
+ fmt = '%g%N/%m/%d'
18
18
  Date.new(1867,12,31).strftime(fmt).should == "1867/12/31"
19
19
  Date.new(1868, 1, 1).strftime(fmt).should == "M01/01/01"
20
20
  Date.new(1912, 7,29).strftime(fmt).should == "M45/07/29"
@@ -28,7 +28,7 @@ describe "Warekky" do
28
28
  end
29
29
 
30
30
  it "with chinese charactor era name (漢字表記の元号)" do
31
- fmt = '%G%n/%m/%d'
31
+ fmt = '%G%N/%m/%d'
32
32
  Date.new(1867,12,31).strftime(fmt).should == "1867/12/31"
33
33
  Date.new(1868, 1, 1).strftime(fmt).should == "明治01/01/01"
34
34
  Date.new(1912, 7,29).strftime(fmt).should == "明治45/07/29"
@@ -14,7 +14,7 @@ describe "Warekky" do
14
14
  end
15
15
 
16
16
  it "with alphabet era name (アルファベット表記の元号)" do
17
- fmt = '%g%n/%m/%d'
17
+ fmt = '%g%N/%m/%d'
18
18
  DateTime.new(1867,12,31).strftime(fmt).should == "1867/12/31"
19
19
  DateTime.new(1868, 1, 1).strftime(fmt).should == "M01/01/01"
20
20
  DateTime.new(1912, 7,29).strftime(fmt).should == "M45/07/29"
@@ -28,7 +28,7 @@ describe "Warekky" do
28
28
  end
29
29
 
30
30
  it "with chinese charactor era name (漢字表記の元号)" do
31
- fmt = '%G%n/%m/%d'
31
+ fmt = '%G%N/%m/%d'
32
32
  DateTime.new(1867,12,31).strftime(fmt).should == "1867/12/31"
33
33
  DateTime.new(1868, 1, 1).strftime(fmt).should == "明治01/01/01"
34
34
  DateTime.new(1912, 7,29).strftime(fmt).should == "明治45/07/29"
@@ -14,7 +14,7 @@ describe "Warekky" do
14
14
  end
15
15
 
16
16
  it "with alphabet era name (アルファベット表記の元号)" do
17
- fmt = '%g%n/%m/%d'
17
+ fmt = '%g%N/%m/%d'
18
18
  Time.local(1867,12,31).strftime(fmt).should == "1867/12/31"
19
19
  Time.local(1868, 1, 1).strftime(fmt).should == "M01/01/01"
20
20
  Time.local(1912, 7,29).strftime(fmt).should == "M45/07/29"
@@ -28,7 +28,7 @@ describe "Warekky" do
28
28
  end
29
29
 
30
30
  it "with chinese charactor era name (漢字表記の元号)" do
31
- fmt = '%G%n/%m/%d'
31
+ fmt = '%G%N/%m/%d'
32
32
  Time.local(1867,12,31).strftime(fmt).should == "1867/12/31"
33
33
  Time.local(1868, 1, 1).strftime(fmt).should == "明治01/01/01"
34
34
  Time.local(1912, 7,29).strftime(fmt).should == "明治45/07/29"
@@ -14,7 +14,7 @@ describe "Warekky" do
14
14
  end
15
15
 
16
16
  it "with alphabet era name (アルファベット表記の元号)" do
17
- fmt = '%g%n/%m/%d'
17
+ fmt = '%g%N/%m/%d'
18
18
  Warekky.strftime(Date.new(1867,12,31), fmt).should == "1867/12/31"
19
19
  Warekky.strftime(Date.new(1868, 1, 1), fmt).should == "M01/01/01"
20
20
  Warekky.strftime(Date.new(1912, 7,29), fmt).should == "M45/07/29"
@@ -28,7 +28,7 @@ describe "Warekky" do
28
28
  end
29
29
 
30
30
  it "with chinese charactor era name (漢字表記の元号)" do
31
- fmt = '%G%n/%m/%d'
31
+ fmt = '%G%N/%m/%d'
32
32
  Warekky.strftime(Date.new(1867,12,31), fmt).should == "1867/12/31"
33
33
  Warekky.strftime(Date.new(1868, 1, 1), fmt).should == "明治01/01/01"
34
34
  Warekky.strftime(Date.new(1912, 7,29), fmt).should == "明治45/07/29"
@@ -40,6 +40,20 @@ describe "Warekky" do
40
40
  Warekky.strftime(Date.new(2010, 6, 9), fmt).should == "平成22/06/09"
41
41
  Warekky.strftime(Date.new(2050,12,31), fmt).should == "平成62/12/31"
42
42
  end
43
+
44
+ it "with chinese charactor era name (漢字表記の元号) %nの改行入り" do
45
+ fmt = '%G%N年%n%m月%n%d日'
46
+ Warekky.strftime(Date.new(1867,12,31), fmt).should == "1867年\n12月\n31日"
47
+ Warekky.strftime(Date.new(1868, 1, 1), fmt).should == "明治01年\n01月\n01日"
48
+ Warekky.strftime(Date.new(1912, 7,29), fmt).should == "明治45年\n07月\n29日"
49
+ Warekky.strftime(Date.new(1912, 7,30), fmt).should == "大正01年\n07月\n30日"
50
+ Warekky.strftime(Date.new(1926,12,24), fmt).should == "大正15年\n12月\n24日"
51
+ Warekky.strftime(Date.new(1926,12,25), fmt).should == "昭和01年\n12月\n25日"
52
+ Warekky.strftime(Date.new(1989, 1, 7), fmt).should == "昭和64年\n01月\n07日"
53
+ Warekky.strftime(Date.new(1989, 1, 8), fmt).should == "平成01年\n01月\n08日"
54
+ Warekky.strftime(Date.new(2010, 6, 9), fmt).should == "平成22年\n06月\n09日"
55
+ Warekky.strftime(Date.new(2050,12,31), fmt).should == "平成62年\n12月\n31日"
56
+ end
43
57
  end
44
58
 
45
59
  describe :parse do
@@ -14,7 +14,7 @@ describe "Warekky" do
14
14
  end
15
15
 
16
16
  it "with alphabet era name (アルファベット表記の元号)" do
17
- fmt = '%g%n/%m/%d'
17
+ fmt = '%g%N/%m/%d'
18
18
  Warekky.strftime(DateTime.new(1867,12,31), fmt).should == "1867/12/31"
19
19
  Warekky.strftime(DateTime.new(1868, 1, 1), fmt).should == "M01/01/01"
20
20
  Warekky.strftime(DateTime.new(1912, 7,29), fmt).should == "M45/07/29"
@@ -28,7 +28,7 @@ describe "Warekky" do
28
28
  end
29
29
 
30
30
  it "with chinese charactor era name (漢字表記の元号)" do
31
- fmt = '%G%n/%m/%d'
31
+ fmt = '%G%N/%m/%d'
32
32
  Warekky.strftime(DateTime.new(1867,12,31), fmt).should == "1867/12/31"
33
33
  Warekky.strftime(DateTime.new(1868, 1, 1), fmt).should == "明治01/01/01"
34
34
  Warekky.strftime(DateTime.new(1912, 7,29), fmt).should == "明治45/07/29"
@@ -40,6 +40,20 @@ describe "Warekky" do
40
40
  Warekky.strftime(DateTime.new(2010, 6, 9), fmt).should == "平成22/06/09"
41
41
  Warekky.strftime(DateTime.new(2050,12,31), fmt).should == "平成62/12/31"
42
42
  end
43
+
44
+ it "with chinese charactor era name (漢字表記の元号) %nの改行入り" do
45
+ fmt = '%G%N年%n%m月%n%d日'
46
+ Warekky.strftime(DateTime.new(1867,12,31), fmt).should == "1867年\n12月\n31日"
47
+ Warekky.strftime(DateTime.new(1868, 1, 1), fmt).should == "明治01年\n01月\n01日"
48
+ Warekky.strftime(DateTime.new(1912, 7,29), fmt).should == "明治45年\n07月\n29日"
49
+ Warekky.strftime(DateTime.new(1912, 7,30), fmt).should == "大正01年\n07月\n30日"
50
+ Warekky.strftime(DateTime.new(1926,12,24), fmt).should == "大正15年\n12月\n24日"
51
+ Warekky.strftime(DateTime.new(1926,12,25), fmt).should == "昭和01年\n12月\n25日"
52
+ Warekky.strftime(DateTime.new(1989, 1, 7), fmt).should == "昭和64年\n01月\n07日"
53
+ Warekky.strftime(DateTime.new(1989, 1, 8), fmt).should == "平成01年\n01月\n08日"
54
+ Warekky.strftime(DateTime.new(2010, 6, 9), fmt).should == "平成22年\n06月\n09日"
55
+ Warekky.strftime(DateTime.new(2050,12,31), fmt).should == "平成62年\n12月\n31日"
56
+ end
43
57
  end
44
58
 
45
59
  describe :parse do
@@ -14,7 +14,7 @@ describe "Warekky" do
14
14
  end
15
15
 
16
16
  it "with alphabet era name (アルファベット表記の元号)" do
17
- fmt = '%g%n/%m/%d'
17
+ fmt = '%g%N/%m/%d'
18
18
  Warekky.strftime(Time.local(1867,12,31), fmt).should == "1867/12/31"
19
19
  Warekky.strftime(Time.local(1868, 1, 1), fmt).should == "M01/01/01"
20
20
  Warekky.strftime(Time.local(1912, 7,29), fmt).should == "M45/07/29"
@@ -28,7 +28,7 @@ describe "Warekky" do
28
28
  end
29
29
 
30
30
  it "with chinese charactor era name (漢字表記の元号)" do
31
- fmt = '%G%n/%m/%d'
31
+ fmt = '%G%N/%m/%d'
32
32
  Warekky.strftime(Time.local(1867,12,31), fmt).should == "1867/12/31"
33
33
  Warekky.strftime(Time.local(1868, 1, 1), fmt).should == "明治01/01/01"
34
34
  Warekky.strftime(Time.local(1912, 7,29), fmt).should == "明治45/07/29"
@@ -40,6 +40,20 @@ describe "Warekky" do
40
40
  Warekky.strftime(Time.local(2010, 6, 9), fmt).should == "平成22/06/09"
41
41
  Warekky.strftime(Time.local(2050,12,31), fmt).should == "平成62/12/31"
42
42
  end
43
+
44
+ it "with chinese charactor era name (漢字表記の元号) %nの改行入り" do
45
+ fmt = '%G%N年%n%m月%n%d日'
46
+ Warekky.strftime(Time.local(1867,12,31), fmt).should == "1867年\n12月\n31日"
47
+ Warekky.strftime(Time.local(1868, 1, 1), fmt).should == "明治01年\n01月\n01日"
48
+ Warekky.strftime(Time.local(1912, 7,29), fmt).should == "明治45年\n07月\n29日"
49
+ Warekky.strftime(Time.local(1912, 7,30), fmt).should == "大正01年\n07月\n30日"
50
+ Warekky.strftime(Time.local(1926,12,24), fmt).should == "大正15年\n12月\n24日"
51
+ Warekky.strftime(Time.local(1926,12,25), fmt).should == "昭和01年\n12月\n25日"
52
+ Warekky.strftime(Time.local(1989, 1, 7), fmt).should == "昭和64年\n01月\n07日"
53
+ Warekky.strftime(Time.local(1989, 1, 8), fmt).should == "平成01年\n01月\n08日"
54
+ Warekky.strftime(Time.local(2010, 6, 9), fmt).should == "平成22年\n06月\n09日"
55
+ Warekky.strftime(Time.local(2050,12,31), fmt).should == "平成62年\n12月\n31日"
56
+ end
43
57
  end
44
58
 
45
59
  describe :parse do
@@ -12,7 +12,7 @@ class ChineseTest < Warekky::EraGroup
12
12
  end
13
13
 
14
14
  format('%G'){|era, era_year| era.sign if era}
15
- format('%n'){|era, era_year| era_year}
15
+ format('%N'){|era, era_year| era_year}
16
16
 
17
17
  era('1862/01/01', '1974/12/31', :tongzhi , '同治')
18
18
  era('1875/01/01', '1908/12/31', :guangxu , '光緒')
@@ -109,12 +109,12 @@ describe Warekky::EraGroup do
109
109
  regexp1 = ChineseTest.formats_regexp
110
110
  regexp1.match("%g").should be_false
111
111
  regexp1.match("%G").should be_true
112
- regexp1.match("%N").should be_false
113
- regexp1.match("%n").should be_true
112
+ regexp1.match("%n").should be_false
113
+ regexp1.match("%N").should be_true
114
114
  regexp1.match("%y").should be_false
115
115
  regexp1.match("%Y").should be_false
116
116
 
117
- regexp1.match("%g%n/%m/%d").should be_true
117
+ regexp1.match("%g%N/%m/%d").should be_true
118
118
  end
119
119
  end
120
120
 
@@ -10,8 +10,17 @@ describe Warekky::Era do
10
10
  describe :strftime do
11
11
  it "invoke original method" do
12
12
  d = Date.new(2010, 6, 10)
13
- d.should_receive(:strftime).with("%Y/%m/%d")
14
- Warekky.strftime(d, "%Y/%m/%d")
13
+ Warekky.strftime(d, "%Y/%m/%d").should == "2010/06/10"
14
+ end
15
+
16
+ it "%n means newline" do
17
+ d = Date.new(2010, 6, 10)
18
+ begin
19
+ Warekky.strftime(d, "%Y%n%m%n%d").should == "2010\n06\n10"
20
+ rescue Exception => e
21
+ puts e.backtrace.join("\n ")
22
+ raise
23
+ end
15
24
  end
16
25
  end
17
26
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{warekky}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takeshi AKIMA"]
12
- s.date = %q{2010-06-10}
12
+ s.date = %q{2010-06-17}
13
13
  s.description = %q{Japanese Era(年号) library and Time, Date, DateTime extensions.}
14
14
  s.email = %q{akm2000@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warekky
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Takeshi AKIMA
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-10 00:00:00 +09:00
18
+ date: 2010-06-17 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency