forth/wareki.fs

104 lines
2.2 KiB
Forth
Executable File

\ wareki.fs - Display WAREKI and Anno Domini corresponding years
\ +JMJ 2013 David Meyer <papa@sdf.org>
\ help-wareki - Display module help
: help-wareki ( -- )
cr ." WAREKI" cr
." Display Japanese era years corresponding to A.D. years and" cr
." vice versa." cr
." HEISEI ( u -- ) Display A.D. year corresponding to Heisei era year." cr
." MEIJI ( u -- ) Display A.D. year corresponding to Meiji era year." cr
." NENGO ( u -- ) Display Japanese year in Meiji, Taishou, Shouwa," cr
." or Heisei eras corresponding to A.D. year." cr
." SHOWA ( u -- ) Display A.D. year corresponding to Shouwa era year." cr
." TAISHO ( u -- ) Display A.D. year corresponding to Taishou era year." cr
;
\ nengo - Display NENGO for A.D. (Meiji, Taishou, Shouwa,
\ Heisei eras only)
: nengo ( u -- )
dup 1868 < if
." ERROR: Year precedes MEIJI era " drop
else
dup 1868 = if
." MEIJI GANNEN (Sep 8 -) " drop
else
dup 1912 < if
." MEIJI " 1867 - .
else
dup 1912 = if
." MEIJI 45/TAISHO GANNEN (Jul 30-) " drop
else
dup 1926 < if
." TAISHO " 1911 - .
else
dup 1926 = if
." TAISHO 15/SHOWA GANNEN (Dec 25-) " drop
else
dup 1989 < if
." SHOWA " 1925 - .
else
dup 1989 = if
." SHOWA 64/HEISEI GANNEN (Jan 8-) " drop
else
." HEISEI " 1988 - .
then
then
then
then
then
then
then
then
;
\ meiji - Display A.D. for Meiji era NENGO.
: meiji ( u -- )
dup 0= if
." ERROR: NENGO < 1 " drop
else
dup 45 > if
." ERROR: NENGO > 45 " drop
else
." AD " 1867 + .
then
then
;
\ taisho - Display A.D. for Taishou era NENGO.
: taisho ( u -- )
dup 0= if
." ERROR: NENGO < 1 " drop
else
dup 15 > if
." ERROR: NENGO > 15 " drop
else
." AD " 1911 + .
then
then
;
\ showa - Display A.D. for Shouwa era NENGO.
: showa ( u -- )
dup 0= if
." ERROR: NENGO < 1 " drop
else
dup 64 > if
." ERROR: NENGO > 64 " drop
else
." AD " 1925 + .
then
then
;
\ heisei - Display A.D. for Heisei era NENGO.
: heisei ( u -- )
dup 0= if
." ERROR: NENGO < 1 " drop
else
." AD " 1988 + .
then
;
cr ." Type 'help-wareki' for help"