Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update date/time functions. #35

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions stdlib/stdlib.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,47 @@
;; as a list (DD MM YYYY). We also ahve a builtin function (time)
;; to return the time as a list (HH MM SS).
;;
;; create some helper functions for retrieving the various parts of
;; the date/time.
(set! year (fn* ()
;; Here we create some helper functions for retrieving the various
;; parts of the date/time, as well as some aliases for ease of typing.
(set! date:year (fn* ()
"Return the current year, as an integer."
(nth (date) 3)))
(set! year date:year)

(set! month (fn* ()
(set! date:month (fn* ()
"Return the number of the current month, as an integer."
(nth (date) 2)))
(set! month date:month)

(set! day (fn* ()
(set! date:day (fn* ()
"Return the day of the current month, as an integer."
(nth (date) 1)))
(set! day date:day)

(set! weekday (fn* ()
(set! date:weekday (fn* ()
"Return a string containing the current day of the week."
(nth (date) 0)))
(set! weekday date:weekday)

(set! hour (fn* ()
(set! time:hour (fn* ()
"Return the current hour, as an integer."
(nth (time) 0)))
(set! hour time:hour)

(set! minute (fn* ()
(set! time:minute (fn* ()
"Return the current minute, as an integer."
(nth (time) 1)))
(set! minute time:minute)

(set! second (fn* ()
(set! time:second (fn* ()
"Return the current seconds, as an integer."
(nth (time) 2)))
(set! second time:second)

(set! hms (fn* ()
(set! time:hms (fn* ()
"Return the current time, formatted as 'HH:MM:SS', as a string."
(sprintf "%s:%s:%s" (hour) (minute) (second))))
(set! hms time:hms)


;;
Expand Down
8 changes: 4 additions & 4 deletions time.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
;; made available by helper-functions defined in our standard-library.
;;

(print "The year is %s" (year))
(print "The date is %s/%s/%s" (day) (month) (year))
(print "The time is %s (%s seconds past the epoch)" (hms) (now))
(print "Today is a %s" (weekday))
(print "The year is %s" (date:year))
(print "The date is %s/%s/%s" (date:day) (date:month) (date:year))
(print "The time is %s (%s seconds past the epoch)" (time:hms) (now))
(print "Today is a %s" (date:weekday))

(print "Date as a list %s" (date))
(print "Time as a list %s" (time))