date-time.lisp

date-time.lisp

This is Common Lisp. date-time.lisp is small file with functions relating to RCD Business software.

(defparameter *day-names*
  '("Monday" "Tuesday" "Wednesday"
    "Thursday" "Friday" "Saturday"
    "Sunday"))

(defparameter *month-names*
  '("January" "February" "March" "April" "May" "June" "July"
    "August" "September" "October" "November" "December"))

(defun datestamp (&optional (universal-time (get-universal-time)))
  "Returns date stamp in formay YEAR-MM-DD"
  (format nil "~{~5*~4,'0D-~2:*~2,'0D-~2:*~2,'0D~8*~}"
          (multiple-value-list (decode-universal-time universal-time))))

(defun number-counted (nr)
  (let* ((str (format nil "~A" nr))
     (l (length str))
     (last (substring str (1- l) l))
     (last (read-from-string last))
     (suffix (if (= last 1) "st"
             (if (= last 2) "nd"
             (if (= last 3) "rd"
                 (if (or (zerop last)
                     (> last 3)) "th"))))))
    (format nil "~A~A" nr suffix)))

(defun date-written-datestamp (datestamp)
  (let* ((year (substring datestamp 0 4))
     (month (parse-integer (substring datestamp 5 7)))
     (month (nth (1- month) *month-names*))
     (day (parse-integer (substring datestamp 8 10))))
    (format nil "~A ~A ~A" (number-counted day) month year)))

(defun timestamp ()
  (multiple-value-bind
        (second minute hour date month year day-of-week dst-p tz)
      (get-decoded-time)
    (declare (ignore dst-p))
    (format nil "~a ~d-~2,'0d-~2,'0d (GMT~@d) ~2,'0d:~2,'0d:~2,'0d"
            (nth day-of-week *day-names*)
            year
            month
            date
            (- tz)
            hour
            minute
            second
            )))

(defun timestamp-filename nil
  (multiple-value-bind
        (second minute hour date month year day-of-week dst-p tz)
      (get-decoded-time)
    (declare (ignore dst-p day-of-week tz))
    (format nil "~d-~2,'0d-~2,'0d-~2,'0d:~2,'0d:~2,'0d"
            year
            month
            date
            hour
            minute
            second
            )))

(defun timestamp-date ()
  (multiple-value-bind
        (second minute hour date month year day-of-week dst-p tz)
      (get-decoded-time)
    (declare (ignore dst-p day-of-week tz hour minute second))
    (format nil "~d-~2,'0d-~2,'0d"
            year
            month
            date)))

;; (defun date-is-end-of-week-p (date &
;; (ql:quickload "simple-date-time")
;; (simple-date:day-of-week (simple-date:universal-time-to-timestamp (get-universal-time)))
;; (setf d (simple-date-time:make-date 2018 01 01))

Leave Your Comment or Contact GNU.Support

Contact GNU.Support now. There is a simple rule at GNU.Support: if we can help you, we do, whenever and wherever necessary, and it's the way we've been doing business since 2002, and the only way we know


Full name:


E-mail:


Message: