#macro LatinYear(year_) #if (int(year_) != year_) #error "oops, bad 'year'." #elseif (year_ < 1 | 3999 < year_) #error "oops, out-of-range 'year'." #end #macro __cvt(dgt_, s1_, s5_, s10_) #local units_ = concat(s1_,s1_,s1_); #local n_ = val(dgt_); #switch (n_) #case(0) #local t_ = ""; #break #range(1,3) #local t_ = substr(units_,1,n_); #break #case(4) #local t_ = concat(s1_,s5_); #break #case(5) #local t_ = s5_; #break #range(6,8) #local t_ = concat(s5_,substr(units_,1,n_-5)); #break #case(9) #local t_ = concat(s1_,s10_); #break #else #error "oops, \"cannot happen\" error in '__cvt()'." #end t_ #end #local ystr_ = str(year_,0,0); #local s_ = ""; #switch (strlen(ystr_)) #case(4) #local s_ = concat(substr("MMM",1,val(substr(ystr_,1,1))), __cvt(substr(ystr_,2,1),"C","D","M"), __cvt(substr(ystr_,3,1),"X","L","C"), __cvt(substr(ystr_,4,1),"I","V","X")); #break #case(3) #local s_ = concat(__cvt(substr(ystr_,1,1),"C","D","M"), __cvt(substr(ystr_,2,1),"X","L","C"), __cvt(substr(ystr_,3,1),"I","V","X")); #break #case(2) #local s_ = concat(__cvt(substr(ystr_,1,1),"X","L","C"), __cvt(substr(ystr_,2,1),"I","V","X")); #break #case(1) #local s_ = __cvt(ystr_,"I","V","X"); #break #else #error "oops, \"cannot happen\" error in 'LatinYear()'." #end s_ #end