-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalendar.lisp
76 lines (54 loc) · 1.63 KB
/
calendar.lisp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;; https://github.com/Cuis-Smalltalk/Calendars/blob/master/Chalten/A%20Point%20Based%20Model%20of%20the%20Gregorian%20Calendar.pdf
(defpackage :calendar
(:use :cl)
(:export
:time-measure
:time-measure-value
:time-measure-unit
:year
:year-value
:make-time-measure))
(in-package :calendar)
(defstruct (time-measure
(:constructor %make-time-measure))
value unit)
(defun make-time-measure (value unit)
(%make-time-measure :value value :unit unit))
(defstruct (year
(:constructor %make-year))
number)
(defun year (number)
(%make-year :number number))
(year 2020)
(defstruct (month
(:constructor %make-month))
number)
(defun month (number-or-name)
(%make-month :number number-or-name))
(month 1)
(defstruct (day-of-month
(:constructor %make-day-of-month))
day month)
(defun day-of-month (day month)
(%make-day-of-month :day day :month month))
(defstruct (week
(:constructor %make-week))
number year)
(defstruct (semester
(:constructor %make-semester))
number year)
(defun yesterday ())
(defun tomorrow ())
(defgeneric distance-between (ce1 ce2)
(:documentation "Distance between two calendar entities."))
(defmethod distance-between ((y1 year) (y2 year))
(make-time-measure (abs (- (year-number y2) (year-number y1))) :year))
(distance-between (year 2005) (year 2006))
(defgeneric days-of (entity))
(defgeneric months-of (entity))
(defgeneric hours-of (entity))
(defgeneric minutes-of (entity))
(defgeneric weeks-of (entity))
(defstruct time-period
years months weeks days hours minutes seconds)
(make-time-period :years 2 :weeks 30)