japanese_calendar 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -1147
- data/README.md +11 -0
- data/lib/japanese_calendar/core_ext/date.rb +1 -1
- data/lib/japanese_calendar/core_ext/date_time.rb +1 -1
- data/lib/japanese_calendar/core_ext/time.rb +1 -1
- data/lib/japanese_calendar/deprecation/era_wrapper.rb +58 -0
- data/lib/japanese_calendar/deprecation/reporting.rb +17 -0
- data/lib/japanese_calendar/deprecation/weekday_wrapper.rb +48 -0
- data/lib/japanese_calendar/era.rb +31 -112
- data/lib/japanese_calendar/era/calculations.rb +129 -0
- data/lib/japanese_calendar/era/reflection.rb +19 -0
- data/lib/japanese_calendar/version.rb +1 -1
- data/lib/japanese_calendar/weekday.rb +18 -16
- data/lib/japanese_calendar/weekday/calculations.rb +26 -0
- metadata +8 -5
- data/lib/japanese_calendar/deprecator.rb +0 -11
- data/lib/japanese_calendar/era/deprecator.rb +0 -39
- data/lib/japanese_calendar/weekday/deprecator.rb +0 -34
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JapaneseCalendar
|
4
|
+
module Era
|
5
|
+
module Reflection #:nodoc:
|
6
|
+
include Era::Calculations
|
7
|
+
|
8
|
+
PERIODS.each do |period|
|
9
|
+
define_method "#{period.romaji_name.downcase}?" do
|
10
|
+
begin
|
11
|
+
period == current_era
|
12
|
+
rescue RuntimeError
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,13 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'japanese_calendar/
|
3
|
+
require 'japanese_calendar/deprecation/weekday_wrapper'
|
4
|
+
require 'japanese_calendar/weekday/calculations'
|
4
5
|
|
5
6
|
module JapaneseCalendar
|
7
|
+
# Weekday extensions to <tt>Date</tt>, <tt>DateTime</tt> and <tt>Time</tt>.
|
6
8
|
module Weekday
|
7
|
-
|
9
|
+
include Weekday::Calculations
|
10
|
+
prepend Deprecation::WeekdayWrapper
|
8
11
|
|
9
|
-
# Formats
|
12
|
+
# Formats the day of the week according to the directives in the given
|
13
|
+
# format string.
|
10
14
|
#
|
15
|
+
# Format directives:
|
16
|
+
# %JA - The full weekday name in Japanese ("日曜日")
|
17
|
+
# %Ja - The abbreviated weekday name in Japanese ("日")
|
18
|
+
#
|
19
|
+
# Examples:
|
11
20
|
# date_of_birth = Time.new(1978, 7, 19)
|
12
21
|
#
|
13
22
|
# date_of_birth.strftime("%JA") # => "水曜日"
|
@@ -15,29 +24,22 @@ module JapaneseCalendar
|
|
15
24
|
#
|
16
25
|
# date_of_birth.strftime("%-Y年%-m月%-d日(%Ja)") # => "1978年7月19日(水)"
|
17
26
|
def strftime(format)
|
18
|
-
string = format
|
19
|
-
|
27
|
+
string = super(format)
|
28
|
+
string.gsub(weekday_pattern, weekday_conversion)
|
20
29
|
end
|
21
30
|
|
22
31
|
private
|
23
32
|
|
24
|
-
|
25
|
-
%w[日曜日 月曜日 火曜日 水曜日 木曜日 金曜日 土曜日][wday]
|
26
|
-
end
|
27
|
-
|
28
|
-
def weekday_abbreviation
|
29
|
-
weekday_name[0]
|
30
|
-
end
|
31
|
-
|
33
|
+
# Returns a hash representing the format directives of the day of the week.
|
32
34
|
def weekday_conversion
|
33
35
|
{
|
34
36
|
'%JA' => weekday_name,
|
35
|
-
'%Ja' => weekday_abbreviation
|
36
|
-
'%Q' => weekday_name,
|
37
|
-
'%q' => weekday_abbreviation
|
37
|
+
'%Ja' => weekday_abbreviation
|
38
38
|
}
|
39
39
|
end
|
40
40
|
|
41
|
+
# Returns a Regexp object representing the format directives of
|
42
|
+
# the day of the week (/%JA|%Ja/).
|
41
43
|
def weekday_pattern
|
42
44
|
Regexp.union(weekday_conversion.keys)
|
43
45
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JapaneseCalendar
|
4
|
+
module Weekday #:nodoc:
|
5
|
+
NAMES = %w[日曜日 月曜日 火曜日 水曜日 木曜日 金曜日 土曜日].freeze
|
6
|
+
|
7
|
+
private_constant :NAMES
|
8
|
+
|
9
|
+
# Calculations module.
|
10
|
+
module Calculations
|
11
|
+
private
|
12
|
+
|
13
|
+
# Returns a string representing the full name of the day of the week in
|
14
|
+
# Japanese ("日曜日").
|
15
|
+
def weekday_name
|
16
|
+
NAMES[wday]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a string representing the abbreviated name of the day of the
|
20
|
+
# week in Japanese ("日").
|
21
|
+
def weekday_abbreviation
|
22
|
+
weekday_name[0]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,12 +106,15 @@ files:
|
|
106
106
|
- lib/japanese_calendar/core_ext/date.rb
|
107
107
|
- lib/japanese_calendar/core_ext/date_time.rb
|
108
108
|
- lib/japanese_calendar/core_ext/time.rb
|
109
|
-
- lib/japanese_calendar/
|
109
|
+
- lib/japanese_calendar/deprecation/era_wrapper.rb
|
110
|
+
- lib/japanese_calendar/deprecation/reporting.rb
|
111
|
+
- lib/japanese_calendar/deprecation/weekday_wrapper.rb
|
110
112
|
- lib/japanese_calendar/era.rb
|
111
|
-
- lib/japanese_calendar/era/
|
113
|
+
- lib/japanese_calendar/era/calculations.rb
|
114
|
+
- lib/japanese_calendar/era/reflection.rb
|
112
115
|
- lib/japanese_calendar/version.rb
|
113
116
|
- lib/japanese_calendar/weekday.rb
|
114
|
-
- lib/japanese_calendar/weekday/
|
117
|
+
- lib/japanese_calendar/weekday/calculations.rb
|
115
118
|
homepage: https://github.com/RyoYamamotoJP/japanese_calendar
|
116
119
|
licenses:
|
117
120
|
- MIT
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'japanese_calendar/deprecator'
|
4
|
-
|
5
|
-
module JapaneseCalendar
|
6
|
-
module Era
|
7
|
-
module Deprecator
|
8
|
-
include JapaneseCalendar::Deprecator
|
9
|
-
|
10
|
-
DEPRECATIONS = {
|
11
|
-
'%K' => 'Please use %JN instead.',
|
12
|
-
'%O' => 'Please use %JR instead.',
|
13
|
-
'%^O' => 'Please use %^JR instead.',
|
14
|
-
'%o' => 'Please use %Jr instead.',
|
15
|
-
'%J' => 'Please use %Jy instead.',
|
16
|
-
'%-J' => 'Please use %-Jy instead.',
|
17
|
-
'%_J' => 'Please use %_Jy instead.'
|
18
|
-
}.freeze
|
19
|
-
|
20
|
-
private_constant :DEPRECATIONS
|
21
|
-
|
22
|
-
def strftime(format)
|
23
|
-
deprecations = collect_era_deprecations(format)
|
24
|
-
deprecations.each { |deprecation| deprecate(*deprecation) }
|
25
|
-
super(format)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def collect_era_deprecations(format)
|
31
|
-
deprecation_pattern = Regexp.union(DEPRECATIONS.keys)
|
32
|
-
deprecated_directives = format.scan(deprecation_pattern).uniq
|
33
|
-
DEPRECATIONS.select do |directive, _|
|
34
|
-
deprecated_directives.include?(directive)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'japanese_calendar/deprecator'
|
4
|
-
|
5
|
-
module JapaneseCalendar
|
6
|
-
module Weekday
|
7
|
-
module Deprecator
|
8
|
-
include JapaneseCalendar::Deprecator
|
9
|
-
|
10
|
-
DEPRECATIONS = {
|
11
|
-
'%Q' => 'Please use %JA instead.',
|
12
|
-
'%q' => 'Please use %Ja instead.'
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
private_constant :DEPRECATIONS
|
16
|
-
|
17
|
-
def strftime(format)
|
18
|
-
deprecations = collect_weekday_deprecations(format)
|
19
|
-
deprecations.each { |deprecation| deprecate(*deprecation) }
|
20
|
-
super(format)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def collect_weekday_deprecations(format)
|
26
|
-
deprecation_pattern = Regexp.union(DEPRECATIONS.keys)
|
27
|
-
deprecated_directives = format.scan(deprecation_pattern).uniq
|
28
|
-
DEPRECATIONS.select do |directive, _|
|
29
|
-
deprecated_directives.include?(directive)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|