Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.CESARUM.DATE.UTILITY

Internal date utilities. Defines utilities to process dates. See also: COM.INFORMATIMAGO.COMMON-LISP.CESARUM.DATE COM.INFORMATIMAGO.COMMON-LISP.GREGORIAN-CALENDAR COM.INFORMATIMAGO.COMMON-LISP.JULIAN-CALENDAR License: AGPL3 Copyright Pascal J. Bourguignon 2007 - 2012 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Public

COMPARE-LISTS-OF-NUMBERS (A B)

PRE: (and (proper-list-p a) (proper-list-p b) (every (function realp) a) (every (function realp) b)) RETURN: The lexicographical order of the two lists of numbers.

CURRENT-TIMEZONE

RETURN: The current default timezone, expressed as a number of seconds from Greenwich; East positive. WARNING: COMMON-LISP convention is West positive.

DST-IN-YEAR (YEAR)

RETURN: A list of (year m d) where DST is shifted in or out in the YEAR/ BUG: This uses the undetermined local timezone, we don't know what country DST is returned...

DURATION (&REST EXPRESSION &KEY &ALLOW-OTHER-KEYS)

RETURN: A new DURATION instance, initialized with the EXPRESSION. NOTE: Only the keywords listed in *DURATION-KEYWORDS* are really allowed.

ENGLISH-NAME-OF-JULIAN-MONTH (MONTH)

RETURN: A string containing the name in English of the MONTH (Julian, Gregorian, etc, calendars).

ENGLISH-NAME-OF-JULIAN-WEEKDAY (WEEKDAY)

RETURN: A string containing the name in English of the WEEKDAY.

HMS60-FROM-SECONDES (SECONDES)

RETURN: seconde ; minute ; hour POST: (or (not (integerp secondes)) (= secondes (multiple-value-call (function hms-to-secondes) (hms60-from-secondes secondes))))

HMS60-TO-SECONDES (SECONDE MINUTE HOUR)

RETURN: The number of seconds corresponding to hour:minute:second in base sixty.

JULIAN-DATE (SECONDE MINUTE HOUR JULIAN-DAY-NUMBER)

RETURN: The Julian Date for the given time and Julian Day Number. URL: <http://en.wikipedia.org/wiki/Julian_day#Calculation>

JULIAN-DAY-NUMBER/GREGORIAN (DAY MONTH YEAR)

RETURN: The Julian Day Number for the given Gregorian Date. URL: <http://en.wikipedia.org/wiki/Julian_day#Calculation>

JULIAN-DAY-NUMBER/JULIAN (DAY MONTH YEAR)

RETURN: The Julian Day Number for the given Julian Date. URL: <http://en.wikipedia.org/wiki/Julian_day#Calculation>

WEEKDAY-OF-JULIAN-DATE (JULIAN-DATE)

RETURN: The Day of the week of the given Julian Day. 0 = Monday, 1 = Tuesday, ..., 6 = Sunday. URL: <http://en.wikipedia.org/wiki/Julian_day#Calculation>

Private

OP-PLIST (A B N)

a+nb

Undocumented

TEST/COMPARE-LISTS-OF-NUMBERS

TEST/HMS60

MACRO

Public

DEFINE-DATE-COMPARE-METHODS (CLASS)

DO: Define date comparison methods.

GENERIC-FUNCTION

Public

AS-LIST-OF-NUMBERS (DATE)

Return the values of the date from the most significant number to the last. It can be a list of a single number. This is meaningful only in the context of the given date class, and used to compare two dates of the same class.

COLLAPSE-JULIAN-DURATION (DURATION)

DO: Collapse weeks as 7 days. RETURN: secondes; minutes; hours; days; months; years NOTE: If you add keywords to *DURATION-KEYWORDS* you may have to override this method.

DATE-AFTER (DATE DURATION)

RETURN: The date DURATION after DATE.

DATE-BEFORE (DATE DURATION)

RETURN: The date DURATION before DATE.

DATE/= (DATE1 DATE2)

RETURN: Whether DATE1 is different from DATE2.

DATE< (DATE1 DATE2)

RETURN: Whether DATE1 is before DATE2.

DATE<= (DATE1 DATE2)

RETURN: Whether DATE1 is before or the same as DATE2.

DATE= (DATE1 DATE2)

RETURN: Whether DATE1 is the same as DATE2.

DATE> (DATE1 DATE2)

RETURN: Whether DATE1 is after DATE2.

DATE>= (DATE1 DATE2)

RETURN: Whether DATE1 is after or the same as DATE2.

DURATION* (A N)

RETURN: The product of a duration by a number.

DURATION+ (A B)

RETURN: The sum of two durations.

DURATION- (A B)

RETURN: The difference of two durations.

DURATION-BETWEEN (END START)

Return the DURATION between END and START. Both END and START dates must be of the same class.

WEEK (DURATION)

RETURN: The week of the duration. NOTE: This is not the duration expressed in week, just the week component of the duration.

Undocumented

SETFWEEK (VALUE SELF)

Private

DURATION/ (A N)

RETURN: The division of a duration by a number.

UNITS-OF-LIST-OF-NUMBERS (DATE)

Return a list of duration keywords corresponding to the numbers returned by as-list-of-numbers. These keywords may not necessarily be already in *DURATION-KEYWORDS*, but could be merged there.

SLOT-ACCESSOR

Public

DAY (DURATION)

The RETURN: The day of the duration. NOTE: This is not the duration expressed in day, just the day component of the duration.

SETFDAY (VALUE SELF)

Set the RETURN: The day of the duration. NOTE: This is not the duration expressed in day, just the day component of the duration.

HOUR (DURATION)

The RETURN: The hour of the duration. NOTE: This is not the duration expressed in hour, just the hour component of the duration.

SETFHOUR (VALUE SELF)

Set the RETURN: The hour of the duration. NOTE: This is not the duration expressed in hour, just the hour component of the duration.

MINUTE (DURATION)

The RETURN: The minute of the duration. NOTE: This is not the duration expressed in minute, just the minute component of the duration.

SETFMINUTE (VALUE SELF)

Set the RETURN: The minute of the duration. NOTE: This is not the duration expressed in minute, just the minute component of the duration.

MONTH (DURATION)

The RETURN: The month of the duration. NOTE: This is not the duration expressed in month, just the month component of the duration.

SETFMONTH (VALUE SELF)

Set the RETURN: The month of the duration. NOTE: This is not the duration expressed in month, just the month component of the duration.

SECONDE (DURATION)

The RETURN: The seconde of the duration. NOTE: This is not the duration expressed in seconde, just the seconde component of the duration.

SETFSECONDE (VALUE SELF)

Set the RETURN: The seconde of the duration. NOTE: This is not the duration expressed in seconde, just the seconde component of the duration.

YEAR (DURATION)

The RETURN: The year of the duration. NOTE: This is not the duration expressed in year, just the year component of the duration.

SETFYEAR (VALUE SELF)

Set the RETURN: The year of the duration. NOTE: This is not the duration expressed in year, just the year component of the duration.

Private

EXPRESSION (OBJECT)

A p-list

VARIABLE

Public

*DAY*

Symbolic duration of one day.

*DURATION-KEYWORDS*

A list of keywords allowed in duration expressions, in the order they should be printed.

*HOUR*

Symbolic duration of one hour.

*MINUTE*

Symbolic duration of one minute.

*MONTH*

Symbolic duration of one month.

*QUARTER*

Symbolic duration of one quarter.

*SECONDE*

Symbolic duration of one second.

*WEEK*

Symbolic duration of one week.

*YEAR*

Symbolic duration of one year.

CLASS

Public

DURATION (&REST EXPRESSION &KEY &ALLOW-OTHER-KEYS)

We store durations 'symbolically'. The 'units' may be colinear in a given calendar, but we don't collapse them because either they may be not colinear in other calendars, or their ratio may not be always the same (eg. 1 year is 24 months in the Davian calendar vs 12 months in the Gregorian calendar, or 1 month may be 28, 29, 30 or 31 days). There is no order for durations. Moreover, the set of units is not hardwired, the client may add new units to the *DURATION-KEYWORDS* list. Only the units listed in *DURATION-KEYWORDS* are processed by the DURATION arithmetic operators. This allows us to use these DURATION objects with respect to any calendar.

CONSTANT

Public

+APRIL+

The number of the April month in the Gregorial calendar.

+AUGUST+

The number of the August month in the Gregorial calendar.

+DECEMBER+

The number of the December month in the Gregorial calendar.

+FEBRUARY+

The number of the February month in the Gregorial calendar.

+JANUARY+

The number of the January month in the Gregorial calendar.

+JULY+

The number of the July month in the Gregorial calendar.

+JUNE+

The number of the June month in the Gregorial calendar.

+MARCH+

The number of the Marchmonth in the Gregorial calendar.

+MAY+

The number of the May month in the Gregorial calendar.

+NOVEMBER+

The number of the November month in the Gregorial calendar.

+OCTOBER+

The number of the October month in the Gregorial calendar.

+SEPTEMBER+

The number of the September month in the Gregorial calendar.