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) -> $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) -> $iSecs`
19 Convert string date/time to seconds since epoch.
21 - `$sDate` - date/time string
23 Handles the following formats:
30 - 2001-12-31T23:59:59Z
31 - 2001-12-31T23:59:59+01:00
33 - 2001-12-31T23:59+01:00
35 If the date format was not recognised, will return 0.
37 ## <a name="StaticMethod <strong>formatTime</strong> ($epoc"></a> [[StaticMethod]] **formatTime** `($epochSeconds,$formatString,$outputTimeZone) -> $value`
39 - `$epochSeconds` epochSecs GMT
40 - `$formatString` twiki time date format, default `$day $month $year - $hour:$min`
41 - `$outputTimeZone` timezone to display, `gmtime` or `servertime`, default is whatever is set in $TWiki::cfg\{DisplayTimeValues\}
43 `$formatString` supports:
45 <table border="1" cellpadding="0" cellspacing="0">
64 <td> weekday name </td>
68 <td> day number (0 = Sunday) </td>
72 <td> week number </td>
80 <td> month number </td>
84 <td> 4-digit year </td>
88 <td> 2-digit year </td>
92 <td> ful HTTP header format date/time </td>
96 <td> full email format date/time </td>
100 <td> full RCS format date/time </td>
104 <td> seconds since 1st January 1970 </td>
108 ## <a name="StaticMethod <strong>formatDelta</strong> ($s)"></a><a name="StaticMethod <strong>formatDelta</strong> ($s) "></a> [[StaticMethod]] **formatDelta** `($s) -> $string`
110 Format a time in seconds as a string. For example, "1 day, 3 hours, 2 minutes, 6 seconds"
112 ## <a name="StaticMethod <strong>parseInterval</strong> ($s"></a> [[StaticMethod]] **parseInterval** `($szInterval) -> [$iSecs,$iSecs]`
114 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.
116 - `$szInterval` - time interval string
118 in yacc syntax, grammar and actions:
120 interval ::= date { $$.start = fillStart($1); $$.end = fillEnd($1); }
121 | date '/' date { $$.start = fillStart($1); $$.end = fillEnd($3); }
122 | 'P' duration '/' date { $$.start = fillEnd($4)-$2; $$.end = fillEnd($4); }
123 | date '/' 'P' duration { $$.start = fillStart($1); $$.end = fillStart($1)+$4; }
126 an `interval` may be followed by a timezone specification string (this is not supported yet).
128 `duration` has the form (regular expression):
130 P(<number><nameOfDuration>)+
132 nameOfDuration may be one of:
134 - y(year), m(month), w(week), d(day), h(hour), M(minute), S(second)
136 `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):
138 - 2001-01-01T00:00:00
139 - 2001-12-31T23:59:59
141 timezone is optional and not supported yet.
143 If the format is not recognised, will return empty interval [0,0].
145 TODO: timezone testing, especially on non valid strings