Skip to content

Instantly share code, notes, and snippets.

@phondanai
Last active April 5, 2017 05:20
Show Gist options
  • Save phondanai/81be41f011f05deba28208fa18f0e992 to your computer and use it in GitHub Desktop.
Save phondanai/81be41f011f05deba28208fa18f0e992 to your computer and use it in GitHub Desktop.
Calculating total days from first day to current day of current year and calculate total saving if save from first day to current day.
(ql:quickload '(ningle clack woo))
(defun current-year ()
(multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(get-decoded-time)
(declare (ignore minute hour date month day-of-week dst-p tz))
year))
(defun current-saving (today_num)
"Return the total saving money from first day to current day of the year"
(*
(+ today_num 1)
(/ today_num 2)))
(defun get-total-day ()
(multiple-value-bind
(quotient reminder)
(truncate
(-
(get-universal-time)
(encode-universal-time 0 0 0 1 1 (current-year)))
(* 60 60 24))
(incf quotient 1)))
;(current-saving (get-total-day))
(defvar *app* (make-instance 'ningle:<app>))
(setf (ningle:route *app* "/")
#'(lambda (params)
(declare (ignore params))
(format nil "~d days, ~d saving" (get-total-day) (current-saving (get-total-day)))))
(setf (ningle:route *app* "/total_days")
#'(lambda (params)
(declare (ignore params))
(format nil "~d" (get-total-day))))
(setf (ningle:route *app* "/saving")
#'(lambda (params)
(declare (ignore params))
(format nil "~d" (current-saving (get-total-day)))))
(clack:clackup *app*
:server :woo
:use-default-middlewares nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment