--I just wrote
def convert_year_to_wareki(year):
wareki_start_year = {
'Meiji': 1868, 'Taisho': 1912, 'Showa': 1926, 'Heisei': 1989, 'Reiwa': 2019
}
if year < wareki_start_year['Taisho']:
return f"(Meiji{year - wareki_start_year['Meiji'] + 1}Year)"
elif year == wareki_start_year['Taisho']:
return f"(Meiji{year - wareki_start_year['Meiji'] + 1}Year/Taisho{year - wareki_start_year['Taisho'] + 1}Year)"
elif year < wareki_start_year['Showa']:
return f"(Taisho{year - wareki_start_year['Taisho'] + 1}Year)"
elif year == wareki_start_year['Showa']:
return f"(Taisho{year - wareki_start_year['Taisho'] + 1}Year/Showa{year - wareki_start_year['Showa'] + 1}Year)"
elif year < wareki_start_year['Heisei']:
return f"(Showa{year - wareki_start_year['Showa'] + 1}Year)"
elif year == wareki_start_year['Heisei']:
return f"(Showa{year - wareki_start_year['Showa'] + 1}Year/Heisei{year - wareki_start_year['Heisei'] + 1}Year)"
elif year < wareki_start_year['Reiwa']:
return f"(Heisei{year - wareki_start_year['Heisei'] + 1}Year)"
elif year == wareki_start_year['Reiwa']:
return f"(Heisei{year - wareki_start_year['Heisei'] + 1}Year/Reiwa{year - wareki_start_year['Reiwa'] + 1}Year)"
else:
return f"(Reiwa{year - wareki_start_year['Reiwa'] + 1}Year)"
year2Wareki(year){
let wYear = ''
let gen = ''
if(year > 2018){
wYear = year-2018
gen = 'Reiwa'
}else if(year > 1988){
wYear= year-1988
gen = 'Heisei'
}else if(year > 1925){
wYear = year-1925
gen = 'Showa'
}else if(year > 1911){
wYear = year-1911
gen = 'Taisho'
}else if(year > 1867){
wYear = year-1867
gen = 'Meiji'
}
if(wYear === 1) wYear = 'Former'
return gen !== '' ? gen + wYear + 'Year' : false
},
def convert_to_wareki(d: datetime.date) -> str:
dt_native = datetime.datetime.combine(d, datetime.time())
return strjpftime(dt_native, f"{d.year}Year(%O%EYear) {d.month}Month{d.day}Day")
2020(2020)January 1
Recommended Posts