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:
32 ISO dates may have a timezone specifier, either Z or a signed difference in hh:mm format. For example:
34 - 2001-12-31T23:59:59+01:00
37 The default timezone is Z, unless $defaultLocal is true in which case the local timezone will be assumed.
39 If the date format was not recognised, will return 0.
41 ## <a name="StaticMethod <strong>formatTime</strong> ($epoc"></a> [[StaticMethod]] **formatTime** `($epochSeconds,$formatString,$outputTimeZone) -> $value`
43 - `$epochSeconds` epochSecs GMT
44 - `$formatString` twiki time date format, default `$day $month $year - $hour:$min`
45 - `$outputTimeZone` timezone to display, `gmtime` or `servertime`, default is whatever is set in $TWiki::cfg\{DisplayTimeValues\}
47 `$formatString` supports:
49 <table border="1" cellpadding="0" cellspacing="0">
68 <td> weekday name </td>
72 <td> day number (0 = Sunday) </td>
76 <td> week number </td>
84 <td> month number </td>
88 <td> 4-digit year </td>
92 <td> 2-digit year </td>
96 <td> ful HTTP header format date/time </td>
100 <td> full email format date/time </td>
104 <td> full RCS format date/time </td>
108 <td> seconds since 1st January 1970 </td>
112 ## <a name="StaticMethod <strong>formatDelta</strong> ($s)"></a><a name="StaticMethod <strong>formatDelta</strong> ($s) "></a> [[StaticMethod]] **formatDelta** `($s) -> $string`
114 Format a time in seconds as a string. For example, "1 day, 3 hours, 2 minutes, 6 seconds"
116 ## <a name="StaticMethod <strong>parseInterval</strong> ($s"></a> [[StaticMethod]] **parseInterval** `($szInterval) -> [$iSecs,$iSecs]`
118 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.
120 - `$szInterval` - time interval string
122 in yacc syntax, grammar and actions:
124 interval ::= date { $$.start = fillStart($1); $$.end = fillEnd($1); }
125 | date '/' date { $$.start = fillStart($1); $$.end = fillEnd($3); }
126 | 'P' duration '/' date { $$.start = fillEnd($4)-$2; $$.end = fillEnd($4); }
127 | date '/' 'P' duration { $$.start = fillStart($1); $$.end = fillStart($1)+$4; }
130 an `interval` may be followed by a timezone specification string (this is not supported yet).
132 `duration` has the form (regular expression):
134 P(<number><nameOfDuration>)+
136 nameOfDuration may be one of:
138 - y(year), m(month), w(week), d(day), h(hour), M(minute), S(second)
140 `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):
142 - 2001-01-01T00:00:00
143 - 2001-12-31T23:59:59
145 timezone is optional. Default is local time.
147 If the format is not recognised, will return empty interval [0,0].
149 TODO: timezone testing, especially on non valid strings