年度 の数字はどれになるのか調べたが今一よくわからない。決算月という
概念があると考えると、決算月の翌月1日は起算日となる。その起算日の年が
そのまま年度の数字となる。西暦の場合、単純に数字が増えていくだけなので
そのまま数字を使えばよい。元号の場合、起算日の年の年号をそのまま使用す
ることになると思われる。ただし、どこかにそのルールがあるのかどうかよく
わからなかった。
決算月と年度が決定すると期首と期末は算出できる。
| 決算月 | 年度 | 期首 | 期末 |
|---|---|---|---|
| 3月 | 2020 | 2020-04-01 | 2021-03-31 |
| 6月 | 2020 | 2020-07-01 | 2021-06-30 |
| 9月 | 2020 | 2020-10-01 | 2021-09-30 |
| 12月 | 2020 | 2020-01-01 | 2020-12-31 |
| 決算月 | 年度 | 期首 | 期末 |
|---|---|---|---|
| 3月 | 2021 | 2021-04-01 | 2022-03-31 |
| 6月 | 2021 | 2021-07-01 | 2022-06-30 |
| 9月 | 2021 | 2021-10-01 | 2022-09-30 |
| 12月 | 2021 | 2021-01-01 | 2021-12-31 |
決算月と年度からその年度の期首を求める関数を実装した。
(defun finance-get-fiscal-starting-time (closing-month fiscal-year)
(encode-time 0 0 0
1 ;; day
(+ 1 (mod closing-month 12)) ;; month
fiscal-year
))finance-get-fiscal-starting-time 関数では期首を算出できるため、その値から期末を求める関数を実装した。
(defun finance-get-fiscal-closing-time (starting-time)
(let ((starting-data (decode-time starting-time)))
(encode-time
(nth 0 starting-data) ;; sec
(nth 1 starting-data) ;; minute
(nth 2 starting-data) ;; hour
(- (nth 3 starting-data) 1) ;; day
(nth 4 starting-data) ;; month
(+ (nth 5 starting-data) 1) ;; year
(nth 6 starting-data) ;; zone
)))さらに決算月と現在日時から、年度の値を求める関数を実装した1。
(defun finance-get-fiscal-year (closing-month target-time)
(let* ((target-date (decode-time target-time))
(target-year (nth 5 target-date))
(beginning_of_month (+ 1 (mod (+ 1 closing-month) 12))))
(if (<= beginning_of_month month)
year
(- year 1))))脚注
1
この関数は以前実装した関数に手を加えたものとなっている。以前の実装については次を参照のこと。期首月と年月から年度を取得するEmacs Lisp