Archive for the ‘anniversary’ Tag
newLISP で祝祭日を計算する(改2)
ようやく、2020年以降にも対応しました(汗)
(define (vernal year) ; 春分の日
(if (and (<= 2000 year) (< year 2100))
(- (add 20.69115 (mul 0.242194 (- year 2000))) (/ (- year 2000) 4))))
(define (autumnal year) ; 秋分の日
(if (and (<= 2000 year) (< year 2100))
(- (add 23.09 (mul 0.242194 (- year 2000))) (/ (- year 2000) 4))))
(define (anniversary year month)
(let (i (find (0 3 (date (date-value year month 1))) *WeekDays*)
res '())
(case month
( 1 (push (list year 1 1 '元日) res -1) ; 元日
(if (= i 0) (push (list year 1 2 '振替休日) res -1))
(push (if ( year 2019) (push (list year 2 23 '天皇誕生日) res -1) ; 天皇誕生日
(if (= i 6) (push (list year 2 24 '振替休日) res -1))) )
( 3 (push (list year 3 (vernal year) '春分の日) res -1) ; 春分の日
(if (= i (- 22 ((res -1) 2))) (push (list year 3 (+ 1 ((res -1) 2)) '振替休日) res -1)) )
( 4 (push (list year 4 29 '昭和の日) res -1) ; 昭和の日
(if (= i 0) (push (list year 4 30 '振替休日) res -1))
(when (= year 2019)
(push (list year 4 30 '特別振替休日) res -1)
) )
( 5 (push (list year 5 3 '憲法記念日) res -1) ; 憲法記念日
(push (list year 5 4 'みどりの日) res -1) ; みどりの日
(push (list year 5 5 'こどもの日) res -1) ; こどもの日
(if (and (< 2 i) (< i 6)) (push (list year 5 6 '振替休日) res -1))
(when (= year 2019)
(push (list year 5 1 '天皇即位の日) res -1)
(push (list year 5 2 '特別振替休日) res -1)
) )
( 6 )
( 7 (if (= year 2020) (begin (push (list year 7 23 '海の日) res -1)
(push (list year 7 24 'スポーツの日) res -1))
(push (if ( year 2015) (push (list year 8 11 '山の日) res -1)) ; 山の日
(if (= i 4) (push (list year 8 12 '振替休日) res -1)))
( 9 (push (if (< i 2) ; 敬老の日 : 9月第3月曜日
(list year 9 (- 16 i) '敬老の日) ; 2 + 2 * 7
(list year 9 (- 23 i) '敬老の日)) ; 2 + 3 * 7
res -1)
(push (list year 9 (autumnal year) '秋分の日) res -1) ; 秋分の日
(if (= i (- 29 ((res -1) 2)) (push (list year 9 (+ 1 ((res -1) 2)) '振替休日) res -1)) )
(if (= 2 (- ((res 1) 2) ((res 0) 2)))
(push (list year 9 (- ((res -1) 2) 1) '国民の休日) res 1)) )
(10 (if (< year 2000) (push (list year 10 10 '体育の日) res -1)
(< year 2020)
(push (if ( year 2020)
(push (if (< i 2) ; スポーツの日 : 10月第2月曜日
(list year 10 (- 9 i) 'スポーツの日) ; 2 + 1 * 7
(list year 10 (- 16 i) 'スポーツの日)) ; 2 + 2 * 7
res -1))
(when (= year 2019)
(push (list year 10 22 '即位礼正殿の儀) res -1)) )
(11 (push (list year 11 3 '文化の日) res -1) ; 文化の日
(if (= i 5) (push (list year 11 4 '振替休日) res -1))
(push (list year 11 23 '勤労感謝の日) res -1) ; 勤労感謝の日
(if (= i 6) (push (list year 11 24 '振替休日) res -1)))
(12 (when (< year 2019) (push (list year 12 23 '天皇誕生日) res -1) ; 天皇誕生日
(if (= i 6) (push (list year 12 24 '振替休日) res -1)) ))
(true ))
res))
さて、これを使って VCSファイルを作るにはこちらのスクリプトをお使いください。
2020年のVCSファイルはこちらに掲載しています。
以上、如何でしょうか?
Palm(Clie)用の祝祭日データ設定ファイルを作ってみる。
年の瀬となり、そろそろ来年の予定を考え始めたころでしょうか?
予定表管理に使っている Clie の祝祭日データは、以前は、sony サイトで入手できましたが、現在は clie 自体がサポートされていません。したがって、自分で用意するしかありません。
とは言っても、祝祭日データ作成スクリプトは既に作ってありますので、後は、clie 用のデータに変換するだけです。
まずは、スクリプトを、(include は、init.lsp に定義してあります。)
(include "anniversary.lsp")
(define (make-DT y (M 1) (d 1) (h 0) (m 0) (s 0))
(format "%4d%02d%02dT%02d%02d%02d" y M d h m s))
(define preStr [text]BEGIN:VCALENDAR
VERSION:1.0
PRODID:PalmDesktop Generated
[/text])
(define calendarStr
[text]
BEGIN:VEVENT
SUMMARY:summayStr
DESCRIPTION:descStr
DTSTART:startStr
DTEND:endStr
END:VEVENT
[/text])
(define postStr [text]
END:VCALENDAR
[/text])
(define (make-event y m d desc)
(let (res calendarStr)
(replace "summayStr" res (string desc))
(replace "descStr" res "newLISP と vcal.lsp で作成")
(replace "startStr" res (make-DT y m d))
(replace "endStr" res (make-DT y m (++ d)))
res))
(define (make-vcal y)
(let (anni (mappend (curry anniversary y) (sequence 1 12))
res preStr)
(extend res (mappend (curry apply make-event) anni))
(extend res postStr)))
"anniversary.lsp"のソースは、“newLISP で祝祭日を計算する。”にありますが、ついでに掲載しておきましょう。
(define *WeekDays* '("Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"))
(define (vernal year)
(if (and (<= 2000 year) (< year 2100))
(- (add 20.69115 (mul 0.242194 (- year 2000))) (/ (- year 2000) 4))))
(define (autumnal year)
(if (and (<= 2000 year) (< year 2100))
(- (add 23.09 (mul 0.242194 (- year 2000))) (/ (- year 2000) 4))))
(define (anniversary year month)
(let (i (find (0 3 (date (date-value year month 1))) *WeekDays*)
res '())
(case month
( 1 (push (list year 1 1 '元日) res -1) ; 元日
(if (= i 0) (push (list year 1 2 '振替休日) res -1))
(push (if (< i 2) ; 成人の日 : 1月第2月曜日
(list year 1 (- 9 i) '成人の日) ; 2 + 1 * 7
(list year 1 (- 16 i) '成人の日)) ; 2 + 2 * 7
res -1) )
( 2 (push (list year 2 11 '建国記念の日) res -1) ; 建国記念の日
(if (= i 4) (push (list year 2 12 '振替休日) res -1)) )
( 3 (push (list year 3 (vernal year) '春分の日) res -1) ; 春分の日
(if (= i (- 22 ((res -1) 2))) (push (list year 3 (+ 1 ((res -1) 2)) '振替休日) res -1)) )
( 4 (push (list year 4 29 '昭和の日) res -1) ; 昭和の日
(if (= i 0) (push (list year 4 30 '振替休日) res -1)))
( 5 (push (list year 5 3 '憲法記念日) res -1) ; 憲法記念日
(push (list year 5 4 'みどりの日) res -1) ; みどりの日
(push (list year 5 5 'こどもの日) res -1) ; こどもの日
(if (and (< 2 i) (< i 6)) (push (list year 5 6 '振替休日) res -1)) )
( 6 )
( 7 (push (if (< i 2) ; 海の日 : 7月第3月曜日
(list year 7 (- 16 i) '海の日) ; 2 + 2 * 7
(list year 7 (- 23 i) '海の日)) ; 2 + 3 * 7
res -1) )
( 8 (when (> year 2015)
(push (list year 8 11 '山の日) res -1) ; 山の日
(if (= i 4) (push (list year 8 12 '振替休日) res -1))))
( 9 (push (if (< i 2) ; 敬老の日 : 9月第3月曜日
(list year 9 (- 16 i) '敬老の日) ; 2 + 2 * 7
(list year 9 (- 23 i) '敬老の日)) ; 2 + 3 * 7
res -1)
(push (list year 9 (autumnal year) '秋分の日) res -1) ; 秋分の日
(if (= i (- 29 ((res -1) 2)) (push (list year 9 (+ 1 ((res -1) 2)) '振替休日) res -1)) )
(if (= 2 (- ((res 1) 2) ((res 0) 2)))
(push (list year 9 (- ((res -1) 2) 1) '国民の休日) res 1)) )
(10 (push (if (< i 2) ; 体育の日 : 10月第2月曜日
(list year 10 (- 9 i) '体育の日) ; 2 + 1 * 7
(list year 10 (- 16 i) '体育の日)) ; 2 + 2 * 7
res -1) )
(11 (push (list year 11 3 '文化の日) res -1) ; 文化の日
(if (= i 5) (push (list year 11 4 '振替休日) res -1))
(push (list year 11 23 '勤労感謝の日) res -1) ; 勤労感謝の日
(if (= i 6) (push (list year 11 24 '振替休日) res -1)))
(12 (push (list year 12 23 '天皇誕生日) res -1) ; 天皇誕生日
(if (= i 6) (push (list year 12 24 '振替休日) res -1)) )
(true ))
res))
と言いつつ、さりげなく、修正してあったりします。以前の関数anniversary では、祝祭日がない時、nil を返しましたが、今回のスクリプトでは、空リスト () が返ります。
さて、使い方は、newLISP 上で、上記スクリプトを読み込み、
(write-file "holidays2011.vcs" (make-vcal 2011))
という風に実行すれば、2011年の祝祭日用vCalendarファイル "holidays2011.vcs" が作成されます。ちなみ、Clie の日本語コードは、Shift-JIS です。間違って、UTF-8 版 newLISP で動作させてはいけません。お間違えなく。
"holidays2011.vcs" の中身は、
BEGIN:VCALENDAR
VERSION:1.0
PRODID:PalmDesktop Generated
BEGIN:VEVENT
SUMMARY:元日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110101T000000
DTEND:20110102T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:成人の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110110T000000
DTEND:20110111T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:建国記念の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110211T000000
DTEND:20110212T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:春分の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110321T000000
DTEND:20110322T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:昭和の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110429T000000
DTEND:20110430T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:憲法記念日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110503T000000
DTEND:20110504T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:みどりの日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110504T000000
DTEND:20110505T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:こどもの日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110505T000000
DTEND:20110506T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:海の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110718T000000
DTEND:20110719T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:敬老の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110919T000000
DTEND:20110920T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:秋分の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20110923T000000
DTEND:20110924T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:体育の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20111010T000000
DTEND:20111011T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:文化の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20111103T000000
DTEND:20111104T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:勤労感謝の日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20111123T000000
DTEND:20111124T000000
END:VEVENT
BEGIN:VEVENT
SUMMARY:天皇誕生日
DESCRIPTION:newLISP と vcal.lsp で作成
DTSTART:20111223T000000
DTEND:20111224T000000
END:VEVENT
END:VCALENDAR
こんな感じ。Clie(Palm)では、予定表の設定用にvCalendarファイルが読み込めますので、上記スクリプトは、それに合わせてあります。データ構造は、見れば、大体想像がつくと思いますので、解説しません。祝祭日は、時間指定のないデータとして、登録されるようにしてあります。まっ、開始時間を当日の 0時に、終了時間を次の日の 0時にしてあるだけですけどね。他に必要なデータ(例えば、誕生日とか)は、適当に追加して下さい(笑)。
後は、Palm Desktop でインポートを開き、拡張子を vcs にして、作成したファイルを読み込めば、来年の祝祭日データが設定されます。これで、来年の準備は万全(笑)。
以上、如何でしょうか?
(2011/12/09 昭和の日に振替休日が抜けていたので、"anniversary.lsp" を変更)
(2016/01/09 "anniversary.lsp" に山の日を追加)
(2016/10/08 元日の振替休日追加)