777 lines
18 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Penlight Documentation</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Penlight</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
</ul>
<h2>Modules</h2>
<ul>
<li><a href="../modules/pl.html">pl</a></li>
<li><strong>pl.Date</strong></li>
<li><a href="../modules/pl.List.html">pl.List</a></li>
<li><a href="../modules/pl.Map.html">pl.Map</a></li>
<li><a href="../modules/pl.MultiMap.html">pl.MultiMap</a></li>
<li><a href="../modules/pl.OrderedMap.html">pl.OrderedMap</a></li>
<li><a href="../modules/pl.Set.html">pl.Set</a></li>
<li><a href="../modules/pl.app.html">pl.app</a></li>
<li><a href="../modules/pl.array2d.html">pl.array2d</a></li>
<li><a href="../modules/pl.class.html">pl.class</a></li>
<li><a href="../modules/pl.comprehension.html">pl.comprehension</a></li>
<li><a href="../modules/pl.config.html">pl.config</a></li>
<li><a href="../modules/pl.data.html">pl.data</a></li>
<li><a href="../modules/pl.dir.html">pl.dir</a></li>
<li><a href="../modules/pl.file.html">pl.file</a></li>
<li><a href="../modules/pl.func.html">pl.func</a></li>
<li><a href="../modules/pl.input.html">pl.input</a></li>
<li><a href="../modules/pl.lapp.html">pl.lapp</a></li>
<li><a href="../modules/pl.lexer.html">pl.lexer</a></li>
<li><a href="../modules/pl.luabalanced.html">pl.luabalanced</a></li>
<li><a href="../modules/pl.operator.html">pl.operator</a></li>
<li><a href="../modules/pl.path.html">pl.path</a></li>
<li><a href="../modules/pl.permute.html">pl.permute</a></li>
<li><a href="../modules/pl.pretty.html">pl.pretty</a></li>
<li><a href="../modules/pl.seq.html">pl.seq</a></li>
<li><a href="../modules/pl.sip.html">pl.sip</a></li>
<li><a href="../modules/pl.strict.html">pl.strict</a></li>
<li><a href="../modules/pl.stringio.html">pl.stringio</a></li>
<li><a href="../modules/pl.stringx.html">pl.stringx</a></li>
<li><a href="../modules/pl.tablex.html">pl.tablex</a></li>
<li><a href="../modules/pl.template.html">pl.template</a></li>
<li><a href="../modules/pl.test.html">pl.test</a></li>
<li><a href="../modules/pl.text.html">pl.text</a></li>
<li><a href="../modules/pl.utils.html">pl.utils</a></li>
<li><a href="../modules/pl.xml.html">pl.xml</a></li>
</ul>
<h2>Topics</h2>
<ul>
<li><a href="../topics/01-introduction.md.html">01-introduction.md</a></li>
<li><a href="../topics/02-arrays.md.html">02-arrays.md</a></li>
<li><a href="../topics/03-strings.md.html">03-strings.md</a></li>
<li><a href="../topics/04-paths.md.html">04-paths.md</a></li>
<li><a href="../topics/05-dates.md.html">05-dates.md</a></li>
<li><a href="../topics/06-data.md.html">06-data.md</a></li>
<li><a href="../topics/07-functional.md.html">07-functional.md</a></li>
<li><a href="../topics/08-additional.md.html">08-additional.md</a></li>
<li><a href="../topics/09-discussion.md.html">09-discussion.md</a></li>
</ul>
<h2>Examples</h2>
<ul>
<li><a href="../examples/seesubst.lua.html">seesubst.lua</a></li>
<li><a href="../examples/sipscan.lua.html">sipscan.lua</a></li>
<li><a href="../examples/symbols.lua.html">symbols.lua</a></li>
<li><a href="../examples/test-cmp.lua.html">test-cmp.lua</a></li>
<li><a href="../examples/test-data.lua.html">test-data.lua</a></li>
<li><a href="../examples/test-listcallbacks.lua.html">test-listcallbacks.lua</a></li>
<li><a href="../examples/test-pretty.lua.html">test-pretty.lua</a></li>
<li><a href="../examples/test-symbols.lua.html">test-symbols.lua</a></li>
<li><a href="../examples/testapp.lua.html">testapp.lua</a></li>
<li><a href="../examples/testclone.lua.html">testclone.lua</a></li>
<li><a href="../examples/testconfig.lua.html">testconfig.lua</a></li>
<li><a href="../examples/testglobal.lua.html">testglobal.lua</a></li>
<li><a href="../examples/testinputfields.lua.html">testinputfields.lua</a></li>
<li><a href="../examples/testinputfields2.lua.html">testinputfields2.lua</a></li>
<li><a href="../examples/testxml.lua.html">testxml.lua</a></li>
<li><a href="../examples/which.lua.html">which.lua</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>pl.Date</code></h1>
<p>Date and Date Format classes.</p>
<p> See <a href="../topics/05-dates.md.html#">the Guide</a>.</p>
<p> Dependencies: <a href="../modules/pl.class.html#">pl.class</a> , <a href="../modules/pl.stringx.html#">pl.stringx</a> </p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#Date">Date&nbsp;(t)</a></td>
<td class="summary">Date constructor.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date.tzone">Date.tzone&nbsp;()</a></td>
<td class="summary">get the time zone offset from UTC.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:toUTC">Date:toUTC&nbsp;()</a></td>
<td class="summary">convert this date to UTC.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:toLocal">Date:toLocal&nbsp;()</a></td>
<td class="summary">convert this UTC date to local.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:set">Date:set&nbsp;(t)</a></td>
<td class="summary">set the current time of this Date object.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:year">Date:year&nbsp;(y)</a></td>
<td class="summary">set the year.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:month">Date:month&nbsp;(m)</a></td>
<td class="summary">set the month.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:day">Date:day&nbsp;(d)</a></td>
<td class="summary">set the day.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:hour">Date:hour&nbsp;(h)</a></td>
<td class="summary">set the hour.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:min">Date:min&nbsp;(min)</a></td>
<td class="summary">set the minutes.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:sec">Date:sec&nbsp;(sec)</a></td>
<td class="summary">set the seconds.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:yday">Date:yday&nbsp;(yday)</a></td>
<td class="summary">set the day of year.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:year">Date:year&nbsp;(y)</a></td>
<td class="summary">get the year.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:month">Date:month&nbsp;()</a></td>
<td class="summary">get the month.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:day">Date:day&nbsp;()</a></td>
<td class="summary">get the day.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:hour">Date:hour&nbsp;()</a></td>
<td class="summary">get the hour.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:min">Date:min&nbsp;()</a></td>
<td class="summary">get the minutes.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:sec">Date:sec&nbsp;()</a></td>
<td class="summary">get the seconds.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:yday">Date:yday&nbsp;()</a></td>
<td class="summary">get the day of year.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:weekday_name">Date:weekday_name&nbsp;(full)</a></td>
<td class="summary">name of day of week.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:month_name">Date:month_name&nbsp;(full)</a></td>
<td class="summary">name of month.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:is_weekend">Date:is_weekend&nbsp;()</a></td>
<td class="summary">is this day on a weekend?.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:add">Date:add&nbsp;(t)</a></td>
<td class="summary">add to a date object.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:last_day">Date:last_day&nbsp;()</a></td>
<td class="summary">last day of the month.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:diff">Date:diff&nbsp;(other)</a></td>
<td class="summary">difference between two Date objects.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:__tostring">Date:__tostring&nbsp;()</a></td>
<td class="summary">long numerical ISO data format version of this date.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:__eq">Date:__eq&nbsp;()</a></td>
<td class="summary">equality between Date objects.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date:__lt">Date:__lt&nbsp;()</a></td>
<td class="summary">equality between Date objects.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date.Format">Date.Format&nbsp;(fmt.)</a></td>
<td class="summary">Date.Format constructor.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date.Format:parse">Date.Format:parse&nbsp;(str)</a></td>
<td class="summary">parse a string into a Date object.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Date.Format:tostring">Date.Format:tostring&nbsp;(d)</a></td>
<td class="summary">convert a Date object into a string.</td>
</tr>
</table>
<br/>
<br/>
<h2><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "Date"></a>
<strong>Date&nbsp;(t)</strong>
</dt>
<dd>
Date constructor.
<h3>Parameters:</h3>
<ul>
<li><code><em>t</em></code>: this can be either <ul>
<li>nil &ndash; use current date and time</li>
<li>number &ndash; seconds since epoch (as returned by <a href="http://www.lua.org/manual/5.1/manual.html#pdf-os.time">os.time</a>)</li>
<li>Date &ndash; copy constructor</li>
<li>table &ndash; table containing year, month, etc as for os.time()
You may leave out year, month or day, in which case current values will be used.
</li>
<li> two to six numbers: year, month, day, hour, min, sec
</ul></li>
</ul>
</dd>
<dt>
<a name = "Date.tzone"></a>
<strong>Date.tzone&nbsp;()</strong>
</dt>
<dd>
get the time zone offset from UTC.
<h3>Returns:</h3>
<ol>
<li>hours ahead of UTC</li>
<li>minutes ahead of UTC</li>
</ol>
</dd>
<dt>
<a name = "Date:toUTC"></a>
<strong>Date:toUTC&nbsp;()</strong>
</dt>
<dd>
convert this date to UTC.
</dd>
<dt>
<a name = "Date:toLocal"></a>
<strong>Date:toLocal&nbsp;()</strong>
</dt>
<dd>
convert this UTC date to local.
</dd>
<dt>
<a name = "Date:set"></a>
<strong>Date:set&nbsp;(t)</strong>
</dt>
<dd>
set the current time of this Date object.
<h3>Parameters:</h3>
<ul>
<li><code><em>t</em></code>: seconds since epoch</li>
</ul>
</dd>
<dt>
<a name = "Date:year"></a>
<strong>Date:year&nbsp;(y)</strong>
</dt>
<dd>
set the year.
<h3>Parameters:</h3>
<ul>
<li><code><em>y</em></code>: Four-digit year</li>
</ul>
</dd>
<dt>
<a name = "Date:month"></a>
<strong>Date:month&nbsp;(m)</strong>
</dt>
<dd>
set the month.
<h3>Parameters:</h3>
<ul>
<li><code><em>m</em></code>: month</li>
</ul>
</dd>
<dt>
<a name = "Date:day"></a>
<strong>Date:day&nbsp;(d)</strong>
</dt>
<dd>
set the day.
<h3>Parameters:</h3>
<ul>
<li><code><em>d</em></code>: day</li>
</ul>
</dd>
<dt>
<a name = "Date:hour"></a>
<strong>Date:hour&nbsp;(h)</strong>
</dt>
<dd>
set the hour.
<h3>Parameters:</h3>
<ul>
<li><code><em>h</em></code>: hour</li>
</ul>
</dd>
<dt>
<a name = "Date:min"></a>
<strong>Date:min&nbsp;(min)</strong>
</dt>
<dd>
set the minutes.
<h3>Parameters:</h3>
<ul>
<li><code><em>min</em></code>: minutes</li>
</ul>
</dd>
<dt>
<a name = "Date:sec"></a>
<strong>Date:sec&nbsp;(sec)</strong>
</dt>
<dd>
set the seconds.
<h3>Parameters:</h3>
<ul>
<li><code><em>sec</em></code>: seconds</li>
</ul>
</dd>
<dt>
<a name = "Date:yday"></a>
<strong>Date:yday&nbsp;(yday)</strong>
</dt>
<dd>
set the day of year.
<h3>Parameters:</h3>
<ul>
<li><code><em>yday</em></code>: day of year</li>
</ul>
</dd>
<dt>
<a name = "Date:year"></a>
<strong>Date:year&nbsp;(y)</strong>
</dt>
<dd>
get the year.
<h3>Parameters:</h3>
<ul>
<li><code><em>y</em></code>: Four-digit year</li>
</ul>
</dd>
<dt>
<a name = "Date:month"></a>
<strong>Date:month&nbsp;()</strong>
</dt>
<dd>
get the month.
</dd>
<dt>
<a name = "Date:day"></a>
<strong>Date:day&nbsp;()</strong>
</dt>
<dd>
get the day.
</dd>
<dt>
<a name = "Date:hour"></a>
<strong>Date:hour&nbsp;()</strong>
</dt>
<dd>
get the hour.
</dd>
<dt>
<a name = "Date:min"></a>
<strong>Date:min&nbsp;()</strong>
</dt>
<dd>
get the minutes.
</dd>
<dt>
<a name = "Date:sec"></a>
<strong>Date:sec&nbsp;()</strong>
</dt>
<dd>
get the seconds.
</dd>
<dt>
<a name = "Date:yday"></a>
<strong>Date:yday&nbsp;()</strong>
</dt>
<dd>
get the day of year.
</dd>
<dt>
<a name = "Date:weekday_name"></a>
<strong>Date:weekday_name&nbsp;(full)</strong>
</dt>
<dd>
name of day of week.
<h3>Parameters:</h3>
<ul>
<li><code><em>full</em></code>: abbreviated if true, full otherwise.</li>
</ul>
<h3>Returns:</h3>
<ol>
string name
</ol>
</dd>
<dt>
<a name = "Date:month_name"></a>
<strong>Date:month_name&nbsp;(full)</strong>
</dt>
<dd>
name of month.
<h3>Parameters:</h3>
<ul>
<li><code><em>full</em></code>: abbreviated if true, full otherwise.</li>
</ul>
<h3>Returns:</h3>
<ol>
string name
</ol>
</dd>
<dt>
<a name = "Date:is_weekend"></a>
<strong>Date:is_weekend&nbsp;()</strong>
</dt>
<dd>
is this day on a weekend?.
</dd>
<dt>
<a name = "Date:add"></a>
<strong>Date:add&nbsp;(t)</strong>
</dt>
<dd>
add to a date object.
<h3>Parameters:</h3>
<ul>
<li><code><em>t</em></code>: a table containing one of the following keys and a value:<br>
year,month,day,hour,min,sec</li>
</ul>
<h3>Returns:</h3>
<ol>
this date
</ol>
</dd>
<dt>
<a name = "Date:last_day"></a>
<strong>Date:last_day&nbsp;()</strong>
</dt>
<dd>
last day of the month.
<h3>Returns:</h3>
<ol>
int day
</ol>
</dd>
<dt>
<a name = "Date:diff"></a>
<strong>Date:diff&nbsp;(other)</strong>
</dt>
<dd>
difference between two Date objects.
Note: currently the result is a regular <a href="../modules/pl.Date.html#pl.Date">?que</a> object,
but also has <code>interval</code> field set, which means a more
appropriate string rep is used.
<h3>Parameters:</h3>
<ul>
<li><code><em>other</em></code>: Date object</li>
</ul>
<h3>Returns:</h3>
<ol>
a Date object
</ol>
</dd>
<dt>
<a name = "Date:__tostring"></a>
<strong>Date:__tostring&nbsp;()</strong>
</dt>
<dd>
long numerical ISO data format version of this date.
</dd>
<dt>
<a name = "Date:__eq"></a>
<strong>Date:__eq&nbsp;()</strong>
</dt>
<dd>
equality between Date objects.
</dd>
<dt>
<a name = "Date:__lt"></a>
<strong>Date:__lt&nbsp;()</strong>
</dt>
<dd>
equality between Date objects.
</dd>
<dt>
<a name = "Date.Format"></a>
<strong>Date.Format&nbsp;(fmt.)</strong>
</dt>
<dd>
Date.Format constructor.
<h3>Parameters:</h3>
<ul>
<li><code><em>fmt.</em></code>: A string where the following fields are significant: <ul>
<li>d day (either d or dd)</li>
<li>y year (either yy or yyy)</li>
<li>m month (either m or mm)</li>
<li>H hour (either H or HH)</li>
<li>M minute (either M or MM)</li>
<li>S second (either S or SS)</li>
</ul>
Alternatively, if fmt is nil then this returns a flexible date parser
that tries various date/time schemes in turn:
<ol>
<li> <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>,</p>
<pre><code>like 2010-05-10 12:35:23Z or 2008-10-03T14:30+02&lt;li&gt;
</code></pre>
<p> <li> times like 15:30 or 8.05pm (assumed to be today&rsquo;s date)</li>
<li> dates like 28/10/02 (European order!) or 5 Feb 2012 </li>
<li> month name like march or Mar (case-insensitive, first 3 letters);
here the day will be 1 and the year this current year </li>
</ol>
A date in format 3 can be optionally followed by a time in format 2.
Please see test-date.lua in the tests folder for more examples.</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">df = Date.Format("yyyy-mm-dd HH:MM:SS")</pre>
</ul>
</dd>
<dt>
<a name = "Date.Format:parse"></a>
<strong>Date.Format:parse&nbsp;(str)</strong>
</dt>
<dd>
parse a string into a Date object.
<h3>Parameters:</h3>
<ul>
<li><code><em>str</em></code>: a date string</li>
</ul>
<h3>Returns:</h3>
<ol>
date object
</ol>
</dd>
<dt>
<a name = "Date.Format:tostring"></a>
<strong>Date.Format:tostring&nbsp;(d)</strong>
</dt>
<dd>
convert a Date object into a string.
<h3>Parameters:</h3>
<ul>
<li><code><em>d</em></code>: a date object, or a time value as returned by <a href="http://www.lua.org/manual/5.1/manual.html#pdf-os.time">os.time</a></li>
</ul>
<h3>Returns:</h3>
<ol>
string
</ol>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.2</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>