Last active
December 13, 2015 20:28
-
-
Save tompng/4969967 to your computer and use it in GitHub Desktop.
Japanese Era Calendar Scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- encoding:utf-8 -*- | |
require 'date' | |
date=Date.parse ARGV[0] | |
eras = [ | |
[Date.parse('1989-01-08'), '平成'], | |
[Date.parse('1926-12-25'), '昭和'], | |
[Date.parse('1912-07-30'), '大正'], | |
[Date.parse('1868-09-08'), '明治'], | |
] | |
era_start, era = eras.find { |start, era| start <= date } | |
print "#{era}#{date.year-era_start.year+1}年#{date.month}月#{date.day}日\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- encoding:utf-8 -*- | |
require 'date' | |
date=Date.parse ARGV[0] | |
eras = [ | |
[[1989, 1, 8], '平成'], | |
[[1926,12,25], '昭和'], | |
[[1912, 7,30], '大正'], | |
[[1868, 9, 8], '明治'], | |
] | |
era_start, era = eras.find do |start, era| Date.new(*start) <= date end | |
era_start_year=era_start.first | |
print "#{era}#{date.year-era_start_year+1}年#{date.month}月#{date.day}日\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- encoding:utf-8 -*- | |
date=ARGV[0] | |
dateexp=/^(\d{4})-(\d\d)-(\d\d)$/ | |
match = date.match dateexp | |
raise "Unparsable date: #{date}" unless match | |
year, month, day = match[1].to_i, match[2], match[3] | |
# year,month,day=ARGV[0].match(dateexp)do |match| | |
# raise "Unparsable date: #{date}" unless match | |
# [match[1],match[2],match[3]].map &:to_i | |
# end | |
#year,month,day=date.split("-").map &:to_i | |
eras = [ | |
['1989-01-08', '平成'], | |
['1926-12-25', '昭和'], | |
['1912-07-30', '大正'], | |
['1868-09-08', '明治'], | |
] | |
era_start, era = eras.find { |start, era| start <= date } | |
era_start_year = era_start.match(/^\d{4}/)[0].to_i | |
# era_start_year = era_start.match(/^\d{4}/).to_s.to_i | |
# era_start_year = era_start[0,4].to_i | |
# era_start_year = era_start.split("-").first.to_i | |
printf("%s%s年%s月%s日\n", era, (year-era_start_year+1).to_s, month, day) | |
# print "#{era}#{year-era_start_year+1}年#{month}月#{day}日\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*-encoding:utf-8-*- | |
a,b,c=ARGV[0].split("-").map &:to_i | |
d=(a-=1911)*372+b*31+c | |
print "明治大正昭和平成"[i=d<619?0:d<5977?2:d<29055?4:6,2]+"#{a-[-44,0,14,77][i/2]}年#{b}月#{c}日" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment