guiletime.scm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ; gives time in seconds
  2. ; (car (mktime (car (strptime "%Y-%m-%d %H:%M" "2017-12-12"))))
  3. ; 1513058400
  4. ; converts numeber to string
  5. ; (strftime "%c" (localtime 1513058400))
  6. ; "mar 12 dic 2017 00:00:00 CST"
  7. ; gives current time as time
  8. ; (localtime (current-time))
  9. ; ;#(30 47 11 8 10 117 3 311 0 21600 "CST")
  10. ; ; convers string to time
  11. ; (strptime "%c" (strftime "%c" (localtime 1513058400)))
  12. ; ;(#(0 0 0 12 11 117 2 345 -1 0 #f) . 28)
  13. ; (strptime "%c" "mar 12 dic 2017 12:30:00 CST")
  14. ;(#(0 30 12 12 11 117 2 345 -1 0 #f) . 28)
  15. ;convuert current time to UTC
  16. ; (strftime "%c" (localtime (current-time) "UTC"))
  17. ;(countdown "2017-12-12 12:30")
  18. ; STRING-> STRING
  19. (define (countdown end)
  20. (let ((end-secs (car (mktime (car (strptime "%Y-%m-%d %H:%M" end)))))
  21. (current-secs (car (mktime (car (strptime "%c" (strftime "%c" (localtime (current-time) "UTC"))))))))
  22. (format #f "~?" "~d Days ~d Hours ~d Minutes until next LGN" (seconds-to-time (- end-secs current-secs)))))
  23. ;(format #f "~a seconds left" (- end-secs (current-time)))
  24. ;(format #t "~?" "~d hola ~d" '(1 2))
  25. (define (seconds-to-time seconds)
  26. (define (days-left time)
  27. (floor (/ time 86400)))
  28. (define (hours-left time)
  29. (floor (/ (remainder time 86400)
  30. 3600)))
  31. (define (minutes-left time)
  32. (floor (/ (remainder (remainder time 86400) 3600)
  33. 60)))
  34. (list (days-left seconds)
  35. (hours-left seconds)
  36. (minutes-left seconds)))