japanese_calendar 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 911eaaf3d1894319e9d2f7349c303fa236f7c7eb
4
- data.tar.gz: 3a240bb75f650ab1559123df1272e66deff033a9
2
+ SHA256:
3
+ metadata.gz: d6bd70c70fd16b249bd21b5d7859ead4d393887170bbd28734cc58df5b6397dd
4
+ data.tar.gz: d1c54d42d05800862841d3f22c1b4be0ddb2f1282dfd7222abcfe36cbdbcf5ff
5
5
  SHA512:
6
- metadata.gz: 1135f2ec0097a8c9763bc4ef9e048241d24449f9e195de64ade0e54e045c479065588d2ebdeb8ad82dc5803a0df2cf0b1ab6c93abc1e401b3515864295f0dbb7
7
- data.tar.gz: 7ed0a7ec12be84cb46a8a0f58dff1b444272b5c0c9466a18c01d073215a5476c229cd0dee185db0bfc0db3b95371e5effb999d158ec1662c8944c3ff2c8893e0
6
+ metadata.gz: 736514a1cbce60600b39dc1a96aeb816b2c7f31d8297f720ca903d851eca7454f2c4785e5a514d189a7ada6f515c9f5648ed72c305b09e07771f4efbcde7f0c7
7
+ data.tar.gz: d3b12a19c5a160d85483410f79fc9a7974ebacf64e2225c0aa28f7c56b0293769fe4c6b7f63f69a9629bb1863dba04c3178fda888d88a6c4b0f17988cd7307d7
data/.travis.yml CHANGED
@@ -1,11 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.10
5
- - 2.2.6
6
- - 2.3.3
7
- - 2.4.0
8
- before_install: gem install bundler -v 1.13.6
4
+ - 2.3.8
5
+ - 2.4.6
6
+ - 2.5.5
7
+ - 2.6.2
8
+ before_install: gem install bundler -v 2.0.1
9
9
  addons:
10
10
  code_climate:
11
11
  repo_token: c542293583b86ca95015675c334c9fea63c14825709f7c9eb4c72a0c8cfc71b4
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Ryo Yamamoto
3
+ Copyright (c) 2016-2019 Ryo Yamamoto
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -23,6 +23,7 @@ Or install it yourself as:
23
23
  To get the Japanese era name, use the `era_name` method:
24
24
 
25
25
  ```
26
+ Time.new(2019, 5, 1).era_name # => "令和"
26
27
  Time.new(1989, 1, 8).era_name # => "平成"
27
28
  Time.new(1926, 12, 25).era_name # => "昭和"
28
29
  Time.new(1912, 7, 30).era_name # => "大正"
@@ -32,6 +33,7 @@ Time.new(1873, 1, 1).era_name # => "明治"
32
33
  If you want to get the Japanese era name in romaji, pass `:romaji`:
33
34
 
34
35
  ```
36
+ Time.new(2019, 5, 1).era_name(:romaji) # => "Reiwa"
35
37
  Time.new(1989, 1, 8).era_name(:romaji) # => "Heisei"
36
38
  Time.new(1926, 12, 25).era_name(:romaji) # => "Showa"
37
39
  Time.new(1912, 7, 30).era_name(:romaji) # => "Taisho"
@@ -41,7 +43,8 @@ Time.new(1873, 1, 1).era_name(:romaji) # => "Meiji"
41
43
  You can convert to a Japanese year with the `era_year` method:
42
44
 
43
45
  ```
44
- Time.new(2016, 12, 11).era_year # => 28
46
+ Time.new(2019, 5, 1).era_year # => 1
47
+ Time.new(2019, 4, 30).era_year # => 31
45
48
  Time.new(1989, 1, 7).era_year # => 64
46
49
  Time.new(1926, 12, 24).era_year # => 15
47
50
  Time.new(1912, 7, 29).era_year # => 45
@@ -50,25 +53,25 @@ Time.new(1912, 7, 29).era_year # => 45
50
53
  To get a string representation of the Japanese calendar, use the `strftime` method:
51
54
 
52
55
  ```
53
- time = Time.new(1989, 1, 1)
56
+ time = Time.new(2019, 5, 1)
54
57
 
55
58
  # Japanese era
56
- time.strftime("%K") # => "平成"
57
- time.strftime("%O") # => "Heisei"
58
- time.strftime("%^O") # => "HEISEI"
59
- time.strftime("%o") # => "H"
60
- time.strftime("%J") # => "01"
61
- time.strftime("%-J") # => "1"
62
- time.strftime("%_J") # => " 1"
59
+ time.strftime("%JN") # => "令和"
60
+ time.strftime("%JR") # => "Reiwa"
61
+ time.strftime("%^JR") # => "REIWA"
62
+ time.strftime("%Jr") # => "R"
63
+ time.strftime("%Jy") # => "01"
64
+ time.strftime("%-Jy") # => "1"
65
+ time.strftime("%_Jy") # => " 1"
63
66
 
64
67
  # Japanese weekday name
65
- time.strftime("%Q") # => "日曜日"
66
- time.strftime("%q") # => ""
68
+ time.strftime("%JA") # => "水曜日"
69
+ time.strftime("%Ja") # => ""
67
70
 
68
71
  # More examples
69
- time.strftime("%K%-J年%-m月%-d日(%q)") # => "平成1年1月1日()"
70
- time.strftime("%o%J.%m.%d") # => "H01.01.01"
71
- time.strftime("%B %-d, %-Y (%O %-J)") # => "January 1, 1989 (Heisei 1)"
72
+ time.strftime("%JN%-Jy年%-m月%-d日(%Ja)") # => "令和1年5月1日()"
73
+ time.strftime("%Jr%Jy.%m.%d") # => "R01.05.01"
74
+ time.strftime("%B %-d, %-Y (%JR %-Jy)") # => "May 1, 2019 (Reiwa 1)"
72
75
  ```
73
76
 
74
77
  ## Development
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.required_ruby_version = ">= 2.1"
24
+ spec.required_ruby_version = ">= 2.3"
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.13"
27
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 12.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency "rubocop"
30
30
  spec.add_development_dependency "simplecov"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ require "date"
3
+ require "japanese_calendar/era"
4
+ require "japanese_calendar/weekday"
5
+
6
+ class Date
7
+ prepend JapaneseCalendar::Era
8
+ prepend JapaneseCalendar::Weekday
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ require "date"
3
+ require "japanese_calendar/era"
4
+ require "japanese_calendar/weekday"
5
+
6
+ class DateTime
7
+ prepend JapaneseCalendar::Era
8
+ prepend JapaneseCalendar::Weekday
9
+ end
@@ -48,26 +48,28 @@ module JapaneseCalendar
48
48
  #
49
49
  # date_of_birth = Time.new(1978, 7, 19)
50
50
  #
51
- # date_of_birth.strftime("%K") # => "昭和"
52
- # date_of_birth.strftime("%O") # => "Showa"
53
- # date_of_birth.strftime("%^O") # => "SHOWA"
54
- # date_of_birth.strftime("%o") # => "S"
55
- # date_of_birth.strftime("%J") # => "53"
51
+ # date_of_birth.strftime("%JN") # => "昭和"
52
+ # date_of_birth.strftime("%JR") # => "Showa"
53
+ # date_of_birth.strftime("%^JR") # => "SHOWA"
54
+ # date_of_birth.strftime("%Jr") # => "S"
55
+ # date_of_birth.strftime("%Jy") # => "53"
56
56
  #
57
- # date_of_birth.strftime("%K%-J年") # => "昭和53年"
57
+ # date_of_birth.strftime("%JN%-Jy年") # => "昭和53年"
58
58
  #
59
59
  # Raises an error when the Japanese year cannot be found.
60
60
  #
61
- # Time.new(1872, 12, 31).strftime("%K%-J年") # => RuntimeError
61
+ # Time.new(1872, 12, 31).strftime("%JN%-Jy年") # => RuntimeError
62
62
  def strftime(format)
63
63
  string = format.dup
64
- string.gsub!(/%K/, era_name)
65
- string.gsub!(/%O/, era_name(:romaji))
66
- string.gsub!(/%\^O/, era_name(:romaji).upcase)
67
- string.gsub!(/%o/, era_name(:romaji)[0])
68
- string.gsub!(/%J/, "%02d" % era_year)
69
- string.gsub!(/%-J/, "%d" % era_year)
70
- string.gsub!(/%_J/, "%2d" % era_year)
64
+ string.gsub!(/%JN/, era_name)
65
+ string.gsub!(/%JR/, era_name(:romaji))
66
+ string.gsub!(/%\^JR/, era_name(:romaji).upcase)
67
+ string.gsub!(/%Jr/, era_name(:romaji)[0])
68
+ string.gsub!(/%Jy/, "%02d" % era_year)
69
+ string.gsub!(/%-Jy/, "%d" % era_year)
70
+ string.gsub!(/%_Jy/, "%2d" % era_year)
71
+ deprecated_japanese_calendar_era_name_strftime(string)
72
+ deprecated_japanese_calendar_era_year_strftime(string)
71
73
  super(string)
72
74
  end
73
75
 
@@ -76,18 +78,55 @@ module JapaneseCalendar
76
78
  Period = Struct.new(:beginning_of_period, :kanji_name, :romaji_name)
77
79
 
78
80
  PERIODS = [
79
- Period.new(Time.new(1989, 1, 8), "平成", "Heisei").freeze,
80
- Period.new(Time.new(1926, 12, 25), "昭和", "Showa" ).freeze,
81
- Period.new(Time.new(1912, 7, 30), "大正", "Taisho").freeze,
82
- Period.new(Time.new(1868, 1, 25), "明治", "Meiji" ).freeze
81
+ Period.new(Date.new(2019, 5, 1), "令和", "Reiwa").freeze,
82
+ Period.new(Date.new(1989, 1, 8), "平成", "Heisei").freeze,
83
+ Period.new(Date.new(1926, 12, 25), "昭和", "Showa" ).freeze,
84
+ Period.new(Date.new(1912, 7, 30), "大正", "Taisho").freeze,
85
+ Period.new(Date.new(1868, 1, 25), "明治", "Meiji" ).freeze
83
86
  ].freeze
84
87
 
85
- MEIJI_6 = Time.new(1873, 1, 1)
88
+ MEIJI_6 = Date.new(1873, 1, 1)
86
89
 
87
90
  def current_era
88
91
  error_proc = proc { raise "#{self.class.name.downcase} out of range" }
89
- error_proc.call if self < MEIJI_6
90
- PERIODS.find(error_proc) { |period| period.beginning_of_period <= self }
92
+ error_proc.call if self.to_date < MEIJI_6
93
+ PERIODS.find(error_proc) do |period|
94
+ period.beginning_of_period <= self.to_date
95
+ end
96
+ end
97
+
98
+ def deprecated_japanese_calendar_era_name_strftime(string)
99
+ if string =~ /%K/
100
+ warn "%K is deprecated. Please use %JN instead."
101
+ string.gsub!(/%K/, era_name)
102
+ end
103
+ if string =~ /%O/
104
+ warn "%O is deprecated. Please use %JR instead."
105
+ string.gsub!(/%O/, era_name(:romaji))
106
+ end
107
+ if string =~ /%\^O/
108
+ warn "%^O is deprecated. Please use %^JR instead."
109
+ string.gsub!(/%\^O/, era_name(:romaji).upcase)
110
+ end
111
+ if string =~ /%o/
112
+ warn "%o is deprecated. Please use %Jr instead."
113
+ string.gsub!(/%o/, era_name(:romaji)[0])
114
+ end
115
+ end
116
+
117
+ def deprecated_japanese_calendar_era_year_strftime(string)
118
+ if string =~ /%J/
119
+ warn "%J is deprecated. Please use %Jy instead."
120
+ string.gsub!(/%J/, "%02d" % era_year)
121
+ end
122
+ if string =~ /%-J/
123
+ warn "%-J is deprecated. Please use %-Jy instead."
124
+ string.gsub!(/%-J/, "%d" % era_year)
125
+ end
126
+ if string =~ /%_J/
127
+ warn "%_J is deprecated. Please use %_Jy instead."
128
+ string.gsub!(/%_J/, "%2d" % era_year)
129
+ end
91
130
  end
92
131
  end
93
132
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module JapaneseCalendar
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.0"
4
4
  end
@@ -7,15 +7,29 @@ module JapaneseCalendar
7
7
  #
8
8
  # date_of_birth = Time.new(1978, 7, 19)
9
9
  #
10
- # date_of_birth.strftime("%Q") # => "水曜日"
11
- # date_of_birth.strftime("%q") # => "水"
10
+ # date_of_birth.strftime("%JA") # => "水曜日"
11
+ # date_of_birth.strftime("%Ja") # => "水"
12
12
  #
13
13
  # date_of_birth.strftime("%-Y年%-m月%-d日(%q)") # => "1978年7月19日(水)"
14
14
  def strftime(format)
15
15
  string = format.dup
16
- string.gsub!(/%Q/, NAMES[wday])
17
- string.gsub!(/%q/, NAMES[wday][0])
16
+ string.gsub!(/%JA/, NAMES[wday])
17
+ string.gsub!(/%Ja/, NAMES[wday][0])
18
+ deprecated_japanese_calendar_weekday_strftime(string)
18
19
  super(string)
19
20
  end
21
+
22
+ private
23
+
24
+ def deprecated_japanese_calendar_weekday_strftime(string)
25
+ if string =~ /%Q/
26
+ warn "%Q is deprecated. Please use %JA instead."
27
+ string.gsub!(/%Q/, NAMES[wday])
28
+ end
29
+ if string =~ /%q/
30
+ warn "%q is deprecated. Please use %Ja instead."
31
+ string.gsub!(/%q/, NAMES[wday][0])
32
+ end
33
+ end
20
34
  end
21
35
  end
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require "japanese_calendar/version"
3
+ require "japanese_calendar/core_ext/date_time"
4
+ require "japanese_calendar/core_ext/date"
3
5
  require "japanese_calendar/core_ext/time"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: japanese_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Yamamoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-25 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +117,8 @@ files:
117
117
  - exe/japanese_calendar
118
118
  - japanese_calendar.gemspec
119
119
  - lib/japanese_calendar.rb
120
+ - lib/japanese_calendar/core_ext/date.rb
121
+ - lib/japanese_calendar/core_ext/date_time.rb
120
122
  - lib/japanese_calendar/core_ext/time.rb
121
123
  - lib/japanese_calendar/era.rb
122
124
  - lib/japanese_calendar/version.rb
@@ -133,15 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
135
  requirements:
134
136
  - - ">="
135
137
  - !ruby/object:Gem::Version
136
- version: '2.1'
138
+ version: '2.3'
137
139
  required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  requirements:
139
141
  - - ">="
140
142
  - !ruby/object:Gem::Version
141
143
  version: '0'
142
144
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.6.8
145
+ rubygems_version: 3.0.3
145
146
  signing_key:
146
147
  specification_version: 4
147
148
  summary: Japanese calendar utility for Ruby