parse-dateDate and Timeparse-durationparse-date-and-timeGoTo Top

parse-date-and-time   string &key start end junk-allowed date-separators time-separators month-precedes-date year-first default-to-current-year time-first => second, minute, hour, date, month, year, time-zone, daylight-savings-p, pos[Function]

Purpose
Parse a date-and-time specification string.

Package   :gbbopen-tools

Module   :gbbopen-tools

Arguments and values

string     A simple string
start     Starting index into string (default is 0)
end     Ending index into string (default is nil, meaning end of string)
junk-allowed     A generalized boolean (default is nil)
date-separators     A sequence of characters that are skipped and separate the date, month, and year fields in string, if needed (default is "-/ ,")
time-separators     A sequence of characters that are skipped and separate the hour, minute, and second fields in string, if needed (default is " :")
month-precedes-date     A generalized boolean (default is *month-precedes-date*)
year-first     A generalized boolean (default is *year-first*)
default-to-current-year     A generalized boolean (default is nil)
time-first     A generalized boolean (default is *time-first*)
second     An integer between 0 and up to 59, inclusive
minute     An integer between 0 and up to 59, inclusive
hour     An integer between 0 and up to 23, inclusive
date     An integer between 1 and up to 31, inclusive, depending on the month and year
month     An integer between 1 and 12, inclusive
year     An integer
time-zone     A time zone: a rational multiple of 1/3600 between -24 and 24 that represents the number of hours offset from GMT
daylight-savings-p     A generalized boolean
position     A index in string

Returns
Nine values: second, minute, hour, date, month, year, time-zone, daylight-savings-p, and position

Errors
If junk-allowed is false, an error is signaled if a numeric field in string does not consist entirely of the representation of a integer, possibly surrounded on either side by characters in separators.

Description
Both the month and date must be specified in string, optionally followed by the year and the time of day. The month can be a numeric value (1–12), a three-letter abbreviation, or the full month name. If the month is specified numerically, then the value of month-precedes-date is used to determine the month and date ordering. If no year is specified in string and default-to-current-year is nil, the current calendar year is assumed, unless the specified month and date have passed, in which case the next year is assumed. If no year is specified in string and default-to-current-year is true, the current calendar year is always assumed. If no hour, minute, or second values are specified, they default to zero. The values returned for time-zone and daylight-savings-p will be nil unless a time-zone is specified in string.

If month-precedes-date is true, the month is expected before the date; otherwise the date is expected to follow the month.

If year-first is supplied and is non-nil, the year must be provided and it is expected before the month and date; otherwise the year (if provided) is expected to follow the month and date.

If a time-zone is specified in string, it is used when encoding the universal-time value. Otherwise, if a non-nil time-zone argument was supplied, it used for the encoding. Otherwise, the current time zone adjusted for daylight saving time is used.

If time-first is true, the time-of-day is expected before the date; otherwise the time-of-day is expected to follow the date.

The returned position is the index within string where the parse ended.

See also
    *month-precedes-date*
    encode-date-and-time
    encode-time-of-day
    full-date-and-time
    parse-date
    parse-duration
    parse-time

Examples

  > (parse-date-and-time "1 Apr 2010")
  0
  0
  0
  1
  4
  2010
  nil
  nil
  10
  > (parse-date-and-time "April 1, 2010 10:30")
  0
  30
  10
  1
  4
  2010
  nil
  nil
  19
  > (parse-date-and-time "4/1/10 10:30pm")
  0
  30
  22
  1
  4
  2010
  nil
  nil
  14
  > (parse-date-and-time "10:30pm 4/1/10" :time-first 't)
  0
  30
  22
  1
  4
  2010
  nil
  nil
  14
  > (parse-date-and-time "Apr 1 2010 10:30 EDT")
  0
  30
  10
  1
  4
  2010
  4
  t
  20
  > (parse-date-and-time "1 Apr 2010 10:30 IST")
  0
  30
  10
  1
  4
  2010
  -11/2
  nil
  20
  > (parse-date-and-time "April 1, 2010 10:30 UTC-7")
  0
  30
  10
  1
  4
  2010
  7
  nil
  25
  >


The GBBopen Project


parse-dateDate and Timeparse-durationparse-date-and-timeGoTo Top