1 # <a name="Package <code>TWiki::Time="></a> Package =TWiki::Time
3 Time handling functions.
7 <li><a href="#Package =TWiki::Time="> Package TWiki::Time</a><ul>
8 <li><a href="#StaticMethod <strong>parseTime</strong> ($szDat"> StaticMethod parseTime <tt>($szDate,$defaultLocal) -> $iSecs</tt></a></li>
9 <li><a href="#StaticMethod <strong>formatTime</strong> ($epoc"> StaticMethod formatTime <tt>($epochSeconds,$formatString,$outputTimeZone) -> $value</tt></a></li>
10 <li><a href="#StaticMethod <strong>formatDelta</strong> ($s)"> StaticMethod formatDelta <tt>($s) -> $string</tt></a></li>
11 <li><a href="#StaticMethod <strong>parseInterval</strong> ($s"> StaticMethod parseInterval <tt>($szInterval) -> [$iSecs,$iSecs]</tt></a></li>
17 ## <a name="StaticMethod <strong>parseTime</strong> ($szDat"></a> [[StaticMethod]] **parseTime** `($szDate,$defaultLocal) -> $iSecs`
19 Convert string date/time string to seconds since epoch (1970-01-01T00:00:00Z).
21 - `$sDate` - date/time string
23 Handles the following formats:
29 TWiki format without time (defaults to 00:00)
33 Date seperated by '/', '.' or '-', time with '.' or ':' Date and time separated by ' ', '.' and/or '-'
46 ISO dates may have a timezone specifier, either Z or a signed difference in hh:mm format. For example:
48 - 2001-12-31T23:59:59+01:00
51 The default timezone is Z, unless $defaultLocal is true in which case the local timezone will be assumed.
53 If the date format was not recognised, will return 0.
55 ## <a name="StaticMethod <strong>formatTime</strong> ($epoc"></a> [[StaticMethod]] **formatTime** `($epochSeconds,$formatString,$outputTimeZone) -> $value`
57 - `$epochSeconds` epochSecs GMT
58 - `$formatString` twiki time date format, default `$day $month $year - $hour:$min`
59 - `$outputTimeZone` timezone to display, `gmtime` or `servertime`, default is whatever is set in $TWiki::cfg\{DisplayTimeValues\}
61 `$formatString` supports:
63 <table border="1" cellpadding="0" cellspacing="0">
82 <td> weekday name </td>
86 <td> day number (0 = Sunday) </td>
90 <td> week number </td>
98 <td> month number </td>
102 <td> 4-digit year </td>
106 <td> 2-digit year </td>
110 <td> ful HTTP header format date/time </td>
114 <td> full email format date/time </td>
118 <td> full RCS format date/time </td>
122 <td> seconds since 1st January 1970 </td>
126 ## <a name="StaticMethod <strong>formatDelta</strong> ($s)"></a><a name="StaticMethod <strong>formatDelta</strong> ($s) "></a> [[StaticMethod]] **formatDelta** `($s) -> $string`
128 Format a time in seconds as a string. For example, "1 day, 3 hours, 2 minutes, 6 seconds"
130 ## <a name="StaticMethod <strong>parseInterval</strong> ($s"></a> [[StaticMethod]] **parseInterval** `($szInterval) -> [$iSecs,$iSecs]`
132 Convert string representing a time interval to a pair of integers representing the amount of seconds since epoch for the start and end extremes of the time interval.
134 - `$szInterval` - time interval string
136 in yacc syntax, grammar and actions:
138 interval ::= date { $$.start = fillStart($1); $$.end = fillEnd($1); }
139 | date '/' date { $$.start = fillStart($1); $$.end = fillEnd($3); }
140 | 'P' duration '/' date { $$.start = fillEnd($4)-$2; $$.end = fillEnd($4); }
141 | date '/' 'P' duration { $$.start = fillStart($1); $$.end = fillStart($1)+$4; }
144 an `interval` may be followed by a timezone specification string (this is not supported yet).
146 `duration` has the form (regular expression):
148 P(<number><nameOfDuration>)+
150 nameOfDuration may be one of:
152 - y(year), m(month), w(week), d(day), h(hour), M(minute), S(second)
154 `date` follows ISO8601 and must include hypens. (any amount of trailing elements may be omitted and will be filled in differently on the differents ends of the interval as to include the longest possible interval):
156 - 2001-01-01T00:00:00
157 - 2001-12-31T23:59:59
159 timezone is optional. Default is local time.
161 If the format is not recognised, will return empty interval [0,0].
163 TODO: timezone testing, especially on non valid strings