Comment detail

西暦 to 和暦 (Nested Flatten)
とりあえず、太陰暦には、対応してないです…。
実行結果:
(to-japanese-date "1926/12/25") 〜

;1868/12/2 => 明治1年12月2日
;1926/12/24 => 大正15年12月24日
;2007/12/01 => 平成19年12月1日
;1926/12/25 => 大正15年12月25日 昭和1年12月25日
;1868/1/2 => 範囲外
;1868/100/2 => 範囲外
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(defpackage #:doukaku-122 (:use #:cl))
(in-package #:doukaku-122)

(defconstant +meiji-end+     396802800)
(defconstant +taisho-start+  +meiji-end+)
(defconstant +taisho-end+    851353200)
(defconstant +showa-start+   +taisho-end+)
(defconstant +showa-end+     2809090800)
(defconstant +heisei-start+  2809177200)
(defconstant +meiji-offset+  1867)
(defconstant +taisho-offset+ 1911)
(defconstant +showa-offset+  1925)
(defconstant +heisei-offset+ 1988)

(defun to-japanese-date (date-string)
  (or (ppcre:register-groups-bind (y m d)
          ("([0-9]{4})/([01]*[0-9])/([0-3]*[0-9])$" date-string)
        (destructuring-bind (y m d) (mapcar #'parse-integer `(,y ,m ,d))
          (when (and (<= y 1868) (<= m 1) (< d 25))
            (return-from to-japanese-date (princ "範囲外")))
          (let ((utime (if (>= y 1900)
                           (encode-universal-time 0 0 0 d m y -9)
                           0))
                gengo toshi)
            (when (<= +heisei-start+ utime)
              (push "平成" gengo)
              (push (- y +heisei-offset+) toshi))
            (when (<= +showa-start+ utime +showa-end+)
              (push "昭和" gengo)
              (push (- y +showa-offset+) toshi))
            (when (<= +taisho-start+ utime +taisho-end+)
              (push "大正" gengo)
              (push (- y +taisho-offset+) toshi))
            (when (<= 0 utime +meiji-end+)
              (push "明治" gengo)
              (push (- y +meiji-offset+) toshi))
            (format nil #'multiple-gengo-print gengo toshi m d))))
      (princ "範囲外")))   ;日付のパターンにマッチしない場合は範囲外

(defun multiple-gengo-print (stream gengo y &rest args)
  (do ((yy y (cdr yy)) (g gengo (cdr g)))
      ((endp g))
    (apply #'format stream "~A~D年~D月~D日" (car g) (car yy) args)
    (and (cdr g) (princ " " stream))))

すいません、余計なプリント文が混じってましたので修正します。

1
2
3
4
5
6
7
8
--- 5234.txt    2008-01-09 01:43:00.000000000 +0900
+++ 5234.txt.diff       2008-01-09 01:42:50.000000000 +0900
@@ -20 +20 @@
-            (return-from to-japanese-date (princ "範囲外")))
+            (return-from to-japanese-date "範囲外"))
@@ -38 +38 @@
-      (princ "範囲外")))   ;日付のパターンにマッチしない場合は範囲外
+      "範囲外"))   ;日付のパターンにマッチしない場合は範囲外

Index

Feed

Other

Link

Pathtraq

loading...