https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ADate%2Fexample
Module:Date/example - Revision history
2025-05-26T04:15:22Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.2
https://en.wikipedia.org/w/index.php?title=Module:Date/example&diff=719185863&oldid=prev
Johnuniq: examples of nbsp in input and of retaining input date format
2016-05-08T04:49:17Z
<p>examples of nbsp in input and of retaining input date format</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 04:49, 8 May 2016</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 11:</td>
<td colspan="2" class="diff-lineno">Line 11:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('2016-03-09'),</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('2016-03-09'),</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('2016-3-9'),</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('2016-3-9'),</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> Date('9<del style="font-weight: bold; text-decoration: none;"> </del>March 2016'),</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> Date('9<ins style="font-weight: bold; text-decoration: none;">&nbsp;</ins>March 2016'),</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('09 mar 2016'),</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('09 mar 2016'),</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('MAR 09 2016'),</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> Date('MAR 09 2016'),</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 58:</td>
<td colspan="2" class="diff-lineno">Line 58:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> show(nil, date:text(format, option))</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> show(nil, date:text(format, option))</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>end</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>-- When an input date is parsed, its format is stored.</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>local function keep_format()</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_0_lhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_3_5_rhs"></a> show('<ins style="font-weight: bold; text-decoration: none;">Keep format of input</ins> date')</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local somedate = Date('March 9, 2016')</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local dates = {</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> Date(2016, 3, 9),</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> Date('2016-3-9'),</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> Date('9&nbsp;Mar 2016'),</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> Date('March 9, 2016'),</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> Date(somedate, {day = 1}), -- somedate with day changed</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> somedate + 23, -- 23 days after somedate</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> somedate - '3 months', -- 3 months before somedate</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> Date('3:45&nbsp;p.m. March&nbsp;9, 2016'),</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> }</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> show(nil, 'Format of somedate was ' .. somedate.format)</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> for _, date in ipairs(dates) do</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> show(nil, date:text() .. ' or ' .. date:text(date.format))</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 124:</td>
<td colspan="2" class="diff-lineno">Line 144:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- Julian day number and date arithmetic.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- Julian day number and date arithmetic.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function julian_date(year, month, count, calendar_name)</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function julian_date(year, month, count, calendar_name)</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> if calendar_name then</div></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_3_5_rhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_0_lhs"></a> show('<del style="font-weight: bold; text-decoration: none;">Julian</del> date')</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> show('Julian date (' .. calendar_name .. ')')</div></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_9_1_rhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_8_0_lhs"></a><del style="font-weight: bold; text-decoration: none;"> if</del> <del style="font-weight: bold; text-decoration: none;">not</del> <del style="font-weight: bold; text-decoration: none;">calendar_name then</del> -- Gregorian calendar by default</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> else</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_8_0_lhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_9_1_rhs"></a><ins style="font-weight: bold; text-decoration: none;"> show('Julian</ins> <ins style="font-weight: bold; text-decoration: none;">date</ins> <ins style="font-weight: bold; text-decoration: none;">(Gregorian)')</ins> -- Gregorian calendar by default</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local date = Date('24 November 4714 BCE')</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local date = Date('24 November 4714 BCE')</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> show(nil, 'Julian day number was ' .. date.jd .. ' on ' .. date:text('mdy'))</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> show(nil, 'Julian day number was ' .. date.jd .. ' on ' .. date:text('mdy'))</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 213:</td>
<td colspan="2" class="diff-lineno">Line 235:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> make_a_date()</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> make_a_date()</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> show_a_date()</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> show_a_date()</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> keep_format()</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> current_date()</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> current_date()</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> current_as_default(nil, nil, nil, 14, 30, 0) -- 2:30 pm today</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> current_as_default(nil, nil, nil, 14, 30, 0) -- 2:30 pm today</div></td>
</tr>
</table>
Johnuniq
https://en.wikipedia.org/w/index.php?title=Module:Date/example&diff=713885697&oldid=prev
Johnuniq: demonstrate using Module:Date
2016-04-06T10:51:47Z
<p>demonstrate using <a href="/wiki/Module:Date" title="Module:Date">Module:Date</a></p>
<p><b>New page</b></p><div>-- Examples showing how to use [[Module:Date]]. See the talk page for output.<br />
local Date = require('Module:Date')._Date<br />
<br />
local show -- function defined below to display results<br />
<br />
-- A date can be constructed using various input formats.<br />
local function make_a_date()<br />
show('Make a date')<br />
local same_dates = {<br />
Date(2016, 3, 9),<br />
Date('2016-03-09'),<br />
Date('2016-3-9'),<br />
Date('9 March 2016'),<br />
Date('09 mar 2016'),<br />
Date('MAR 09 2016'),<br />
Date('March 9, 2016'),<br />
Date('March 9, 2016 CE'),<br />
Date('March 9, 2016 A.D.'),<br />
Date('3:45 pm 9 March 2016'),<br />
Date('3:45 p.m. 9 March 2016'),<br />
Date(2016, 3, 9, 15, 45),<br />
Date('9 March 2016 15:45'),<br />
}<br />
for _, date in ipairs(same_dates) do<br />
show(nil, date:text() .. ' or ' .. date:text('mdy'))<br />
end<br />
local more_dates = {<br />
Date('4 October 1582', 'Julian'),<br />
Date('juliandate', 2299160),<br />
Date('15 October 1582'),<br />
}<br />
for _, date in ipairs(more_dates) do<br />
show(nil, date.dayname .. ' ' .. date:text() .. ' in the ' ..<br />
date.calendar .. ' calendar is Julian day ' .. date.jd)<br />
end<br />
end<br />
<br />
-- A date can be displayed using various output formats.<br />
local function show_a_date()<br />
show('Show a date')<br />
local dates = {<br />
Date(2016, 3, 9),<br />
Date('9 March 2016 BC'),<br />
}<br />
local format_option = {<br />
{ 'ymd' },<br />
{ 'mdy' },<br />
{ 'dmy' },<br />
{ 'dmy', 'era=B.C.E.' },<br />
{ '%A %B %-d, %Y %{era}' },<br />
{ '%A %B %-d, %Y %{era}', 'era=A.D.' },<br />
{ 'a %{dayname} in %{monthname} %Y %{era}' },<br />
}<br />
for _, t in ipairs(format_option) do<br />
local format = t[1]<br />
local option = t[2]<br />
for _, date in ipairs(dates) do<br />
show(nil, date:text(format, option))<br />
end<br />
end<br />
end<br />
<br />
-- Using Date to get the current date, or current date and time.<br />
local function current_date()<br />
local now_date = Date('currentdate')<br />
local now_datetime = Date('currentdatetime')<br />
show('Current date showing when this page was last purged',<br />
now_date:text(), -- 7 March 2016 (for example)<br />
now_date:text('mdy'), -- March 7, 2016<br />
now_date:text('ymd'), -- 2016-03-07<br />
now_date:text('%A %-d %B %-Y'), -- Monday 7 March 2016<br />
now_datetime:text(), -- 21:32:45 7 March 2016<br />
now_datetime:text('hms'), -- 21:32:45<br />
now_datetime:text('%c') -- 9:32 pm 7 March 2016<br />
)<br />
end<br />
<br />
-- Using current to provide default values.<br />
local function current_as_default(year, month, day, hour, minute, second)<br />
local current = require('Module:Date')._current<br />
year = year or current.year<br />
month = month or current.month<br />
day = day or current.day<br />
hour = hour or current.hour<br />
minute = minute or current.minute<br />
second = second or current.second<br />
show('Using the current date as a default',<br />
year, month, day, hour, minute, second)<br />
-- Alternatively, a date can be constructed with specified items overridden.<br />
show(nil, Date('currentdatetime', {<br />
year = year,<br />
month = month,<br />
day = day,<br />
hour = hour,<br />
minute = minute,<br />
second = second }):text('%c'))<br />
end<br />
<br />
-- Make a date from the day number in a year.<br />
local function date_from_day_of_year()<br />
-- Example: day 123 in 2015 and in 2016.<br />
show('Make a date from the day number in a year')<br />
local offset = 123 - 1 -- 1 January has day-of-year = 1<br />
for _, year in ipairs({ 2015, 2016 }) do<br />
local date = Date(year, 1, 1) + offset<br />
show(nil, 'Day ' .. date.dayofyear .. ' in ' .. year .. ' is ' .. date:text())<br />
end<br />
end<br />
<br />
-- Number of days in a month for Gregorian (default) and Julian calendars.<br />
local function days_in_month(year, month, calendar_name)<br />
local title = 'Days in month'<br />
if calendar_name then<br />
title = title .. ' (' .. calendar_name .. ' calendar)'<br />
end<br />
local monthdays = require('Module:Date')._days_in_month<br />
show(title, monthdays(year, month, calendar_name))<br />
-- Alternative method, using Date.<br />
local date = Date(year, month, 1, calendar_name)<br />
show(nil, date.monthname .. ' ' .. date.year .. ' had ' .. date.monthdays .. ' days')<br />
show(nil, date:text('%{monthname} %{year} had %{monthdays} days')) -- same<br />
end<br />
<br />
-- Julian day number and date arithmetic.<br />
local function julian_date(year, month, count, calendar_name)<br />
show('Julian date')<br />
if not calendar_name then -- Gregorian calendar by default<br />
local date = Date('24 November 4714 BCE')<br />
show(nil, 'Julian day number was ' .. date.jd .. ' on ' .. date:text('mdy'))<br />
end<br />
local first_of_month = Date(year, month, 1, calendar_name)<br />
for _ = 1, count do<br />
first_of_month = first_of_month + '1m' -- next month<br />
local date = first_of_month - '1d' -- last day of month<br />
show(nil,<br />
'Last day in month (' .. date:text() .. ' ' .. date.calendar ..<br />
' calendar) had Julian day number ' .. date.jd<br />
)<br />
end<br />
end<br />
<br />
-- Number of days a date was in the past, or will be in the future.<br />
local function how_long(date_text)<br />
local now_date = Date('currentdate')<br />
local then_date = Date(date_text)<br />
if not then_date then<br />
show('How long', 'Invalid date: ' .. (date_text or ''))<br />
return<br />
end<br />
local fmt = '%A %B %-d, %-Y %{era} (day of year = %{dayofyear}, serial day = %{gsd}) '<br />
local info = then_date:text(fmt)<br />
if then_date == now_date then<br />
fmt = 'is now (%d day%s)'<br />
elseif then_date > now_date then<br />
fmt = 'will be in %d day%s'<br />
else<br />
fmt = 'was %d day%s ago'<br />
end<br />
local diff = then_date - now_date<br />
local days = diff.age_days<br />
local s = days == 1 and '' or 's'<br />
show('How long', info .. string.format(fmt, days, s))<br />
local y, m, d = diff:age('ymd') -- age in years, months, days<br />
show(nil, string.format('(%d years + %d months + %d days)', y, m, d))<br />
end<br />
<br />
-- First and third Fridays in each month of the given year.<br />
local function fridays(year)<br />
show('First and third Fridays in each month of ' .. year)<br />
for month = 1, 12 do<br />
local dates = Date(year, month, 1):list('Friday >=')<br />
show(nil, dates[1] .. ', ' .. dates[3])<br />
end<br />
end<br />
<br />
-- Next Friday after or before a particular date.<br />
local function next_friday()<br />
show('Next Friday and last Friday for certain dates')<br />
local dates = {<br />
Date('1 Jan 2016'),<br />
Date('2 Jan 2016'),<br />
Date('3 Mar 1980'),<br />
}<br />
for _, date in ipairs(dates) do<br />
-- 1 = number of Fridays that are wanted in the list<br />
local after = date:list('1 Friday')[1]<br />
local before = date:list('1 Friday <')[1]<br />
local format = '%A %-d %B %-Y'<br />
show(nil,<br />
'For ' .. date:text(format) ..<br />
', the next is ' .. after:text(format) ..<br />
', and the last is ' .. before:text(format)<br />
)<br />
end<br />
end<br />
<br />
-- Results are held in the lines table.<br />
local lines<br />
function show(title, ...) -- for forward declaration above<br />
if title then<br />
if lines[1] then<br />
table.insert(lines, '')<br />
end<br />
table.insert(lines, "'''" .. title .. "'''")<br />
end<br />
for _, text in ipairs({...}) do<br />
table.insert(lines, ':' .. tostring(text))<br />
end<br />
end<br />
<br />
local function main()<br />
lines = {}<br />
make_a_date()<br />
show_a_date()<br />
current_date()<br />
current_as_default(nil, nil, nil, 14, 30, 0) -- 2:30 pm today<br />
date_from_day_of_year()<br />
days_in_month(1900, 2)<br />
days_in_month(1900, 2, 'Julian')<br />
julian_date(1899, 11, 4)<br />
julian_date(-120, 11, 4, 'Julian')<br />
how_long('29 Feb 2100') -- an invalid date<br />
how_long('currentdate')<br />
how_long('29 Feb 2400')<br />
how_long('29 Feb 2401 BCE')<br />
fridays(2016)<br />
next_friday()<br />
return table.concat(lines, '\n')<br />
end<br />
<br />
return { main = main }</div>
Johnuniq