License:
BSD style: see license.txtVersion:
Aug 2007: Initial release Feb 2008: RetooledAuthor:
Matti Niemenmaa This module is based on the ISO 8601:2004 standard, and has functions for parsing (almost) every date/time format specified therein. (The ones not supported are intervals, durations, and recurring intervals.) Refer to the standard for a full description of the formats supported. The functions (parseTime, parseDate, and parseDateAndTime) are overloaded into two different versions of each: one updates a given Time, and the other updates a given ExtendedDate struct. The purpose of this struct is to support more detailed information which the Time data type does not (and, given its simple integer nature, cannot) support. Times with specified time zones are simply converted into UTC: this may lead to the date changing when only a time was parsed: e.g. "01:00+03" is the same as "22:00", except that when the former is parsed, one is subtracted from the day.Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Time t; ExtendedDate ed; parseDate("19", t); // January 1st, 1900 parseDate("1970", t); // January 1st, 1970 parseDate("1970-02", t); // February 1st, 1970 parseDate("19700203", t); // February 3rd, 1970 parseDate("+19700203", ed, 2); // March 1st, 197002 parseDate("-197002-04-01", ed, 2); // April 1st, -197003 (197003 BCE) parseDate("00000101", t); // January 1st, -1 (1 BCE) parseDate("1700-W14-2", t); // April 6th, 1700 parseDate("2008W01", t); // December 31st, 2007 parseDate("1987-221", t); // August 9th, 1987 parseDate("1234abcd", t); // January 1st, 1234; return value is 4 parseDate("12abcdef", t); // January 1st, 1200; return value is 2 parseDate("abcdefgh", t); // January 1st, 0001; return value is 0 |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Time t; ExtendedDate ed; // ",000" omitted for clarity parseTime("20", t); // 20:00:00 parseTime("2004", t); // 20:04:00 parseTime("20:04:06", t); // 20:04:06 parseTime("16:49:30,001", t); // 16:49:30,001 parseTime("16:49:30,1", t); // 16:49:30,100 parseTime("16:49,4", t); // 16:49:24 parseTime("23:59:60", ed); // 23:59:60 parseTime("24:00:01", t); // 00:00:00; return value is 5 parseTime("24:00:01", ed); // 00:00:00; return value is 5; endOfDay parseTime("30", t); // 00:00:00; return value is 0 parseTime("21:32:43-12:34", t); // 10:06:43; day increased by one |
parseTime:
there are no allowances for expanded years or reduced dates (two-digit years), and separator usage must be consistent. Although the standard allows for omitting the T between the date and the time, this function requires it.Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | Time t; // January 1st, 2008 00:01:00 parseDateAndTime("2007-12-31T23:01-01", t); // April 12th, 1985 23:50:30,042 parseDateAndTime("1985W155T235030,042", t); // Invalid time: returns zero parseDateAndTime("1902-03-04T10:1a", t); // Separating T omitted: returns zero parseDateAndTime("1985-04-1210:15:30+04:00", t); // Inconsistent separators: all return zero parseDateAndTime("200512-01T10:02", t); parseDateAndTime("1985-04-12T10:15:30+0400", t); parseDateAndTime("1902-03-04T050607", t); |