Gauche:日時の加算

Gauche:日時の加算

タイムスタンプの生成

(use srfi-19)

(define N 10)

(define date1     (string->date "2020-02-28T00:00:00+0900" "~Y-~m-~dT~H:~M:~S~z"))
(define duration1 (make-time 'time-duration 0 (* 6 60 60))) ; 6hr
(define time1     #f)

(do ((i 1 (+ i 1)))
    ((> i N))
  (print (date->string date1 "~Y-~m-~dT~H:~M:~S~z"))
  (set! time1 (date->time-utc date1))
  (set! time1 (add-duration time1 duration1))
  (set! date1 (time-utc->date time1)))


時間の加算

(define work-time-list
  '(
    7:45
    6:00
    5:30
    7:15
    ))

(define total-hours 0)

(for-each
 (lambda (time1)
   (rxmatch-cond
     ((#/^(\d+):(\d+)$/ (x->string time1)) (#f hours minutes)
      (inc! total-hours (+ (x->number hours)
                           (/. (x->number minutes) 60))))
     (else
      (errorf "invalid time found : ~a" time1))))
 work-time-list)

(format #t "~%total-hours = ~a~%" total-hours)

hamayama(2022/02/28 12:36:39 UTC)(2022/03/06 02:00:28 UTC)
(2022/03/06 23:36:57 UTC)

More ...