[FileMaker]「第1・X 曜日の前日」に処理を実行する

以前 Raspberry Pi の cron で「第 X・Y 曜日の “前日”」(例:第3土曜日の前日)に処理を実行する方法について書いた。

[Raspberry Pi] cron で「第 X 曜日の前日」に実行3 – with a Christian Wife
https://wacw.cf/2018/12/29/cron-the-day-before-x-th-week-3/

私の住んでいるところは、第1水曜日が不燃ごみの日だ。不燃ごみの前日も cron を使えば、Slack に通知したりできると思った。

そこで問題に気付きました。

「第 “1”・X 曜日の前日」は cron でやろうとすると、これまで以上にややこしくなる!

第1火曜日が1〜6日にあたる月は、冒頭リンクの第3土曜日の前日と同じようにやればいい。

しかし、第1火曜日が月末になってしまう月(すなわち第1水曜日が1日の場合)は、月末の日付が 28・29・30・31 の4パターンあるので、それらの場合分けを考えると計算式を考えるのが難しそうだ。

ということで、それなら「第1水曜日の前日」に関しては、FileMaker Server のスケジュールで処理を実行することにした。FileMaker Server を使えば指定日に Slack に投稿したりすることも簡単にできるからだ。

参考:
SlackにFileMakerから通知を送信する – Qiita
https://qiita.com/yasuhikoc/items/f0fdc4365c7e0da34915

環境:macOS Catalina Version 10.15.6(英語環境)、FileMaker Pro 18 Advanced

cron と違い、FileMaker の計算式で第1水曜日の前日を考えるには、「明日が第1水曜日である日」を計算式で求め、それに合致する日にだけ処理を実行すればいい。

具体的には、第1水曜日というのは1〜7日のいずれかが水曜日の日である。

なので、スクリプトで以下のように書き、FileMaker Server のスケジュールに登録しておけばいい。

If [ DayOfWeek ( Get ( CurrentDate ) + 1 ) = 4 and Day ( Get ( CurrentDate ) + 1 ) = 1
or DayOfWeek ( Get ( CurrentDate ) + 1 ) = 4 and Day ( Get ( CurrentDate ) + 1 ) = 2
or DayOfWeek ( Get ( CurrentDate ) + 1 ) = 4 and Day ( Get ( CurrentDate ) + 1 ) = 3
or DayOfWeek ( Get ( CurrentDate ) + 1 ) = 4 and Day ( Get ( CurrentDate ) + 1 ) = 4
or DayOfWeek ( Get ( CurrentDate ) + 1 ) = 4 and Day ( Get ( CurrentDate ) + 1 ) = 5
or DayOfWeek ( Get ( CurrentDate ) + 1 ) = 4 and Day ( Get ( CurrentDate ) + 1 ) = 6
or DayOfWeek ( Get ( CurrentDate ) + 1 ) = 4 and Day ( Get ( CurrentDate ) + 1 ) = 7
 ]
	[実行する処理]
End If

参考:
DayOfWeek
https://fmhelp.filemaker.com/help/18/fmp/ja/index.html#page/FMP_Help/dayofweek.html

Day
https://fmhelp.filemaker.com/help/18/fmp/ja/index.html#page/FMP_Help/day.html