1/* 2 * Copyright 2007, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Documentation by: 6 * Axel D�rfler 7 * Corresponds to: 8 * /trunk/headers/os/support/parsedate.h rev 19972 9 */ 10 11/*! 12 \file parsedate.h 13 \ingroup support 14 \ingroup libroot 15 \brief Date parsing functions 16 17 This is a set a functions for parsing date strings in various formats. 18 It's mostly tailored for parsing user given data, although originally, 19 it was developed to parse the date strings found in usenet messages. 20 21 The given date will be parsed relative to the specified time, and using 22 a predefined set of time/date formats. 23 24 \par Valid Input Strings 25 26 The internal formats allow parsedate() to understand a wide range of 27 input strings. The format list is ought to be compiled from the Date: 28 line of 80.000 usenet messages. 29 30 But since this function is also used in end-user applications like the 31 Tracker's find panel, it's helpful to know what this function accepts 32 and what not. 33 34 Here are some examples of input strings that parsedate() will be able 35 to convert along with some notes: 36 - "last friday", "this wednesday", "next July" 37 "last", "next", and "this" refer to the week or year (depending 38 on the context). So "last friday" means last week's friday. 39 "This wednesday" is referring to this week's wednesday, no matter 40 if it has already passed or not. 41 "Next July" refers to next year's July. All of these dates are 42 parsed relative to the specified time (usually "now"), and will 43 be set to the first moment of that time span: "next monday" is 44 monday, 0:00:00, midnight. 45 - "now" just returns the time all calculations are relative to. 46 - "next 5 minutes", "5 minutes", "+5 mins" all mean the same thing, 47 that is, current time plus exactly 5 minutes. 48 - "5 weeks" means in 5 weeks from now on. 49 - "8/5/2003", "5.8.2003", "2003-08-05" are all referring to August 50 5th, 2003, again at 0:00 midnight. 51 - "Thursday 3:00" means this week's thursday, at 3 o'clock. 52 53 \anchor parsedateFormats 54 \par Format Specifier 55 56 While the get_dateformats() function allow you to retrieve the built-in 57 formats, you can also define your own and use set_dateformats() to let 58 parsedate() use them in all subsequent calls. 59 60 The following is a list valid format specifiers and their meanings. 61 62 - \b a/A weekday (Sunday, Monday, ...) 63 - \b d day of month (1-31) 64 - \b b/B month name (January, February, ...) 65 - \b month (1-12) 66 - \b y/Y year 67 - \b H/I hours (1-24) 68 - \b M minutes (0-60) 69 - \b S seconds (0-60) 70 - \b p meridian (am/pm) 71 - \b z/Z time zone (i.e. GMT) 72 - \b T time unit, like "last friday", "next 5 minutes", "-15 hours", etc. 73 - \b - dash or slash 74 75 Any of ",.:" is allowed and will be expected in the input string as is. 76 You can enclose a \b single field with "[]" to mark it as being optional. 77 A blank stands for white space. No other character is allowed. 78 An invalid format string won't do any harm, but of course, no input string 79 will ever match that format. 80 81 For example, "H:M [p]" will match against "21:33", "4:12 am", but not 82 "30:30 pm" (hours out of range), "15:16 GMT" (this time zone is certainly 83 not a valid meridian specifier), or "4:66" (minutes out of range). 84 85 \par Note: 86 At the time of this writing, the parsedate() functions are not localized and 87 will only recognize English time specifications following the examples above. 88*/ 89 90/*! 91 \def PARSEDATE_RELATIVE_TIME 92 \brief relative time 93 94 The time value was computed relative to the specified time. 95*/ 96 97/*! 98 \def PARSEDATE_DAY_RELATIVE_TIME 99 \brief day relative time 100 101 The time value was computed relative to the specified time, and it would vary 102 with every day passed in the specified time. 103*/ 104 105/*! 106 \def PARSEDATE_MINUTE_RELATIVE_TIME 107 \brief minute relative time 108 109 The time value was computed relative to the specified time, and it would 110 vary with every minute passed in the specified time. 111*/ 112 113/*! 114 \def PARSEDATE_INVALID_DATE 115 \brief invalid date string 116 117 This flag will be set if the specified date string could not be parsed 118 correctly. For example, this may happen if there are some unknown words in 119 that string. 120*/ 121 122/*! 123 \fn time_t parsedate(const char *dateString, time_t relativeTo) 124 \brief Parses \a dateString relative to \a relativeTo 125 126 Parses the given \a dateString relative to the time 127 specified by \a relativeTo using the internal formats 128 table. 129 130 \param dateString the date that should be parsed, i.e. "next thursday". 131 \param relativeTo all relative dates will be relative to this time, if -1 132 is passed, the current time will be used. 133 \return the parsed time value or -1 if the \a dateString 134 could not be parsed. 135*/ 136 137/*! 138 \fn time_t parsedate_etc(const char *dateString, time_t relativeTo, int *_storedFlags) 139 \brief Parses <span class="var">dateString</span> relative to <span class="var">relativeTo</span> 140 141 This does basically the same as parsedate(), but will set the following 142 flags in <span class="var">_storedFlags</span>: 143 \htmlonly 144 <table border=1> 145 <!-- ToDo: this certainly is a hack --> 146 <tr><th bgcolor="#eeeeee">Constant</th><th bgcolor="#eeeeee">Meaning</th></tr> 147 <tr><td class="mdname1">PARSEDATE_RELATIVE_TIME</td> 148 <td>\endhtmlonly \copydoc PARSEDATE_RELATIVE_TIME \htmlonly 149 </td></tr> 150 <tr><td class="mdname1">PARSEDATE_DAY_RELATIVE_TIME</td> 151 <td>\endhtmlonly \copydoc PARSEDATE_DAY_RELATIVE_TIME \htmlonly 152 </td></tr> 153 <tr><td class="mdname1">PARSEDATE_MINUTE_RELATIVE_TIME</td> 154 <td>\endhtmlonly \copydoc PARSEDATE_MINUTE_RELATIVE_TIME \htmlonly 155 </td></tr> 156 <tr><td class="mdname1">PARSEDATE_INVALID_DATE</td> 157 <td> 158 \endhtmlonly \copydoc PARSEDATE_INVALID_DATE \htmlonly 159 This flag will only be set if the function returns -1. 160 </td></tr> 161 </table> 162 \endhtmlonly 163*/ 164 165/*! 166 \fn void set_dateformats(const char *formatTable[]) 167 \brief sets the internal format table for parsedate() 168 169 This function let you set the format table which is used by parsedate(). 170 When <span class="var">formatTable</span> is NULL, the standard built-in format table will be set again. 171 \param formatTable the NULL terminated formats list. This list must stay 172 valid when using parsedate() - it is not copied, but directly used. 173 \see 174 \ref parsedateFormats Format! 175*/ 176 177/*! 178 \fn const char **get_dateformats(void) 179 \brief returns the internal format table currently used by parsedate() 180 181 Returns the internal format table currently used by parsedate() - this is 182 either a pointer to the built-in one, or one that you have previously 183 set using set_dateformats(). 184 185 \see 186 \ref set_dateformats() 187*/ 188 189