Module: FeCoreExt::CoreExt::DateClassMethods
- Included in:
- Date
- Defined in:
- lib/fe_core_ext/core_ext/date.rb
Instance Method Summary collapse
- #parse_as_future(string) ⇒ Object
- #parse_gengo(string) ⇒ Object
- #parse_heisei(string) ⇒ Object
- #parse_reiwa(string) ⇒ Object
Instance Method Details
#parse_as_future(string) ⇒ Object
22 23 24 25 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 22 def parse_as_future(string) date = parse(string) date > current ? date : date + 1.year end |
#parse_gengo(string) ⇒ Object
41 42 43 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 41 def parse_gengo(string) parse_heisei(string) || parse_reiwa(string) end |
#parse_heisei(string) ⇒ Object
27 28 29 30 31 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 27 def parse_heisei(string) string.match('平成(\d+)年(\d+)月(\d+)日') { Date.new($1.to_i + 1988, $2.to_i, $3.to_i) } end |
#parse_reiwa(string) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 33 def parse_reiwa(string) string.match('令和(\S+)年(\d+)月(\d+)日') { year = 1 if $1 == '元' year ||= $1.to_i Date.new(year + 2018, $2.to_i, $3.to_i) } end |