birthday.scm 870 B

123456789101112131415161718192021222324
  1. (use-modules (zenity)
  2. (srfi srfi-19))
  3. (define (seconds->years s)
  4. (floor (/ s 60 60 24 356)))
  5. (let* ((birthday (or (zenity-calendar "What is your date of birth?")
  6. (exit)))
  7. (now (current-date))
  8. (birthday* (make-date 0 0 0 0
  9. (cdr (assoc 'day birthday))
  10. (cdr (assoc 'month birthday))
  11. (cdr (assoc 'year birthday))
  12. (date-zone-offset now))))
  13. (when (= (date-year-day now)
  14. (date-year-day birthday*))
  15. (display "Happy birthday!")
  16. (newline))
  17. (let* ((age-sec (time-second (time-difference (date->time-utc now)
  18. (date->time-utc birthday*))))
  19. (age (seconds->years age-sec)))
  20. (display (list "You are" age "years old"))
  21. (newline)))