AppleScript名:元号変換v31 |
set a to "2010/7/21" set a to parseDate(a) of me set {aGengoStr, aGengoNum} to retJapaneseGengo(a) of me –> {"平成", 22} on retJapaneseGengo(aDate) set aYear to year of aDate set aMonth to month of aDate as number set aDay to day of aDate set aStr to retZeroPaddingText(aYear, 4) of me & retZeroPaddingText(aMonth, 2) of me & retZeroPaddingText(aDay, 2) of me set aGengo to "" if aStr ≥ "19890108" then set aGengo to "平成" set aGengoNum to aYear – 1989 + 1 else if aStr ≥ "19261225" then set aGengo to "昭和" set aGengoNum to aYear – 1926 + 1 else if aStr ≥ "19120730" then set aGengo to "大正" set aGengoNum to aYear – 1912 + 1 else if aStr ≥ "18680125" then set aGengo to "明治" set aGengoNum to aYear – 1868 + 1 end if return {aGengo, aGengoNum} end retJapaneseGengo –数値にゼロパディングしたテキストを返す on retZeroPaddingText(aNum, aLen) set tText to ("0000000000" & aNum as text) set tCount to length of tText set resText to text (tCount – aLen + 1) thru tCount of tText return resText end retZeroPaddingText on parseDate(inStr) set aClass to class of inStr if aClass = string then try set aDate to date inStr on error return false end try else if aClass = date then set aDate to inStr end if return aDate end parseDate |
More from my site
(Visited 34 times, 1 visits today)