[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new time and date procedures

This page is part of the web mail archives of SRFI 19 from before July 7th, 2015. The new archives for SRFI 19 contain all messages, not just those from before July 7th, 2015.



Taking the comments so far, I'd like to suggest changing the time and
date procedures in the following way. This isn't a complete write-up,
and I haven't done the implementation, but I'd be glad for your
opinions:

;; data types

time    : structured record second/minute/hour/day/month/year/day of
week/
          day of year/daylights savings time/time zone offset.
Equivalent
          to universal time. Implementations can vary as to whether leap
          are included. Range is implementation specific.

seconds : real, potentially inexact, corresponding to the number of
seconds
          from 0 to implementation specific upper range. What '0'
corresponds to
          in the real world is also implementation specific.

Julian day number : integer, corresponding to the number of days
          from 0 to implementation specific upper range. What '0'
corresponds to
          in the real world is also implementation specific.

Implementations should describe the ranges of these numbers and their
correspondence with the real world.

;; get the current values

(current-time)
(current-julian-day-number) ; '0' is implementation specific
(current-seconds)           ; '0' is implementation specific.
                            ; convertible to time.
(current-process-seconds)   ; '0' and value is implantation specific
(current-run-seconds)       ; '0' and value is implementation specific

Note: process-seconds and run-seconds don't have the same 0 as
(current-seconds) seconds.

;; readers

; TIME

(time-second time) => real (0 to 61.0) ; potentially includes leap
seconds
(time-minute time) => integer (0 to 59)
(time-hour time)   => integer (0 to 23)
(time-day time)    => integer (1 to 31)
(time-month time)  => integer (1 to 12) (January=1, etc.)
(time-year time)   => integer
(time-week-day)    => integer (0 to 6) (Sunday=0 to Saturday=6).
(time-year-day)    => integer (0 to 365)
(time-dst? time)   => boolean (#t if observing dst, #f otherwise)
(time-zone-offset time) => integer

; JULIAN-DAY-NUMBER

(julian-day-number-day jdn) => integer (1 to 31)
(julian-day-number-month jdn) => integer (1 to 12)
(julian-day-number-year jdn) => integer

;; encoders

(make-time second minute hour date month year)
(make-time second minute hour date month year zone-offset)
(make-julian-day-number day month year)

;; writers

(set-time-second! time real)
(set-time-minute! time integer)
(set-time-hour! time integer)
(set-time-day! time integer)
(set-time-month! time integer)
(set-time-year! time integer)
(set-time-dst?! time boolean)
(set-time-zone-offset! time integer)

;; converters. all strings are ISO formats.

(time->seconds time) => real
(seconds->time real) => time

(time->julian-day-number time) => integer
(julian-day-number->time integer) => time

(julian-day-number->seconds integer) => real
(seconds->julian-day-number real) => integer

(time->string time)  => string
(string->time string) => time

(julian-day-number->string integer) => string
(string->julian-day-number string) => integer

(seconds->string seconds) => string
(string->seconds string)  => real

;; comparing procedures

(time=? time1 time2) => boolean
(time>? time1 time2) => boolean
(time<? time1 time2) => boolean
(time>=? time1 time2) => boolean
(time<=? time1 time2) => boolean

;; data type probes

(time? time) => boolean