Date are stored using several formats depending of their accuracy. Each format is defined as a range over various components of a date: year , month , day , hour , minute , second .
Finally we have defined a standard way to numerically encode dates: The possibly fractional number of days (daynumber) since January 1st, 1970 at zero hour local.
|3.12.0. (date-to-day date)
? (date-to-day (string-to-date "1993-12-04" 'year 'day)) = 8738
? (date-to-day (now)) = 15015.9551
|3.12.1. (day-to-date daynumber)
? (day-to-date 8738) = ::DATE:year-second:(1993-12-04 00:00:00)
? (day-to-date 8738.23) = ::DATE:year-second:(1993-12-04 05:31:11)
? (today) = ::DATE:year-day:(2011-02-10)
? (now) = ::DATE:year-second:(2011-02-10 22:55:23)
|3.12.4. (split-date date)
<year>: The year (minus 1900). <month>: The month number (0..11). <day>: The day of the month (1..31). <hour>: The hour (0..23). <minute>: The number of minutes (0..59). <second>: The number of seconds. <wday>: The day of the week (0..6). <yday>: The day of the year (1..366).
These items are present if the resolution of the date object allows it. The last two items require at least a date `` year to day ''
? (split-date (now)) = ((year . 111) (month . 2) (day . 10) (hour . 22) (minute . 55) (second . 23) (wday . 4) (yday . 40) )
? (split-date (today)) = ((year . 111) (month . 2) (day . 10) (wday . 4) (yday . 40))
|3.12.5. (date-type date)
? (date-type (today)) = (year day)
? (date-type (now)) = (year second)
|3.12.6. (date-extend date from to)
Reducing the resolution of a date is achieved by truncating unneeded components. Extending the resolution of a date towards more accuracy is achieved by inserting zeroes. Extending the resolution of a date towards fields of larger magnitude is achieved by inserting the current year, month, day, etc...
? (date-extend (now) 'year 'minute) = ::DATE:year-minute:(2011-02-10 22:55)
? (date-extend (date-extend (now) 'year 'minute) 'hour 'second) = ::DATE:hour-second:(22:55:00)
|3.12.7. (date-to-string date [format])
Argument format is a format string reminiscent of printf . When argument format is omitted, a regular ANSI string is produced.
YYYY-MM-DD HH:MM:SS for <year> to <second> YYYY-MM-DD for <year> to <day> MM-DD HH:MM for <month> to <minute>
The format for date-to-string is a character string that consists of field descriptors and text characters, reminiscent of printf . Each field descriptor consists of a % character followd by another character that specifies the replacement for the field descriptor. All other characters are copied from fmt into the result. The following field descriptors are supported:
The difference between %U and %W lies in which day is counted as the first day of the week. Week number 01 is the first week with four or more January days in it.
? (date-to-string (today)) = "2011-02-10"
? (date-to-string (now)) = "2011-02-10 22:55:23"
? (date-to-string (now) "%C %X") = "20 10:55:23 PM"
|3.12.8. (string-to-date string [from to])
Argument from and to are symbols specifying the resolution of the target date. They may be any of the following symbols: year , month , day , hour , minute , second . When these arguments are ommited, a date `` year to second '' is assumed.
Abbreviated dates are handled by filling the leftmost fields with the current date and the rightmost fields with zeroes.
? (string-to-date "1993-12-12 8:30" 'year 'minute) = ::DATE:year-minute:(1993-12-12 08:30)
|3.12.9. (date-add-second date count)
? (date-add-second (now) 67) = ::DATE:year-second:(2011-02-10 22:56:30)
|3.12.10. (date-add-minute date count)
? (date-add-minute (now) 67) = ::DATE:year-second:(2011-02-11 00:02:23)
|3.12.11. (date-add-hour date count)
? (date-add-hour (now) 67) = ::DATE:year-second:(2011-02-13 17:55:23)
|3.12.12. (date-add-day date count)
? (date-add-day (now) 67) = ::DATE:year-second:(2011-04-18 22:55:23)
|3.12.13. (date-add-month date count [opt])
This is tricky because months have different lengths. Adding an integral number of month to certain dates may produce an illegal day number for the target month. (eg. (date-add-month "1996-05-31" 1) ). The behavior of this function is therefore further specified by the value of optional argument opt .
? (date-add-month (now) -2 t) = ::DATE:year-second:(2010-12-10 22:55:23)
|3.12.14. (date-add-year date count [opt])
This is tricky because adding an integral number of years to february 29th dates may produce an illegal date. The behavior of this function is therefore further specified by the value of optional argument opt .
? (date-add-year (now) 2 t) = ::DATE:year-second:(2013-02-10 22:55:23)
|3.12.15. (date-code date flags)
These components are generated only if they make sense with the resolution of the date date .
? (date-code (now) 24) = (0.9605 -0.2782 -0.2616 -0.9652)
? (date-code (today) 31) = (15015 Nan Nan -0.901 -0.4339 -0.4339 0.901 0.7722 0.6354)