LoginSignup
2
1

More than 5 years have passed since last update.

AppleScript で年齢計算、干支、星座を計算

Posted at

誕生日と基準日をもとに、満年齢、数え年、干支、星座を表示するスクリプトです。
AppleScriptのメニューバーに入れておけば、重宝します。(たまにしか使いませんが)
西暦、和暦(明治、大正、昭和、平成)の両方に対応していますので、どちらの形式で入力してもOKです。

年齢計算.scpt
-- 誕生日から基準日の満年齢を計算します。
-- 干支と星座も表示します。
-- 入力は西暦でも和暦でも自動判定します。(明治〜平成まで)
--
set CR to ASCII character 13
display dialog "誕生日を入力(yyyy/mm/dd でも可)" default answer "昭和12年3月4日"
set BD to date gengo_check(text returned of result)

set TODAY to (current date) as text
set TD to (items 1 thru (offset of "日" in TODAY) of TODAY) as text
display dialog "基準日を入力" default answer TD
set KD to date gengo_check(text returned of result)

set NENREI to (round ((KD - BD) / (365.25 * 24 * 60 * 60)) rounding down) as text
set KAZOE to ((year of KD) - (year of BD) + 1) as text

set ETO to item (((year of BD) mod 12) + 1) of "申酉戌亥子丑寅卯辰巳午未"
set SEIZA to constellation(BD)

display dialog "満 " & NENREI & " 歳、" & ETO & "年、" & SEIZA & "です。(数え年で " & KAZOE & " 歳)"

on gengo_check(inData)
    set ans to inData
    set GENGO to (items 1 thru 2 of ans) as text
    set DIF to 0
    if GENGO = "明治" then set DIF to 1867
    if GENGO = "大正" then set DIF to 1911
    if GENGO = "昭和" then set DIF to 1925
    if GENGO = "平成" then set DIF to 1988
    if DIF > 0 then
        set POS to offset of "年" in ans
        set NEN to ((items 3 thru (POS - 1) of ans) as text) + DIF
        set ans to ((NEN as text) & items POS thru (offset of "日" in ans) of ans) as text
    end if
    return ans
end gengo_check

on constellation(B_Day)
    set ans to "Error"
    set MM to month of B_Day as integer
    set DD to day of B_Day as integer
    if (MM = 3 and DD  21) then set ans to "牡羊"
    if (MM = 4 and DD  19) then set ans to "牡羊"
    if (MM = 4 and DD  20) then set ans to "牡牛"
    if (MM = 5 and DD  20) then set ans to "牡牛"
    if (MM = 5 and DD  21) then set ans to "双子"
    if (MM = 6 and DD  21) then set ans to "双子"
    if (MM = 6 and DD  22) then set ans to "蟹"
    if (MM = 7 and DD  22) then set ans to "蟹"
    if (MM = 7 and DD  23) then set ans to "獅子"
    if (MM = 8 and DD  22) then set ans to "獅子"
    if (MM = 8 and DD  23) then set ans to "乙女"
    if (MM = 9 and DD  22) then set ans to "乙女"
    if (MM = 9 and DD  23) then set ans to "天秤"
    if (MM = 10 and DD  23) then set ans to "天秤"
    if (MM = 10 and DD  24) then set ans to "蠍"
    if (MM = 11 and DD  21) then set ans to "蠍"
    if (MM = 11 and DD  22) then set ans to "射手"
    if (MM = 12 and DD  21) then set ans to "射手"
    if (MM = 12 and DD  22) then set ans to "山羊"
    if (MM = 1 and DD  19) then set ans to "山羊"
    if (MM = 1 and DD  20) then set ans to "水瓶"
    if (MM = 2 and DD  18) then set ans to "水瓶"
    if (MM = 2 and DD  19) then set ans to "魚"
    if (MM = 3 and DD  20) then set ans to "魚"
    return ans & "座"
end constellation
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1