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;">&amp;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">&#x26AB;</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&amp;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&amp;nbsp;p.m. March&amp;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">&#x26AB;</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">&#x26AB;</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">&#x26AB;</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(&#039;Module:Date&#039;)._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(&#039;Make a date&#039;)<br /> local same_dates = {<br /> Date(2016, 3, 9),<br /> Date(&#039;2016-03-09&#039;),<br /> Date(&#039;2016-3-9&#039;),<br /> Date(&#039;9 March 2016&#039;),<br /> Date(&#039;09 mar 2016&#039;),<br /> Date(&#039;MAR 09 2016&#039;),<br /> Date(&#039;March 9, 2016&#039;),<br /> Date(&#039;March 9, 2016 CE&#039;),<br /> Date(&#039;March 9, 2016 A.D.&#039;),<br /> Date(&#039;3:45 pm 9 March 2016&#039;),<br /> Date(&#039;3:45 p.m. 9 March 2016&#039;),<br /> Date(2016, 3, 9, 15, 45),<br /> Date(&#039;9 March 2016 15:45&#039;),<br /> }<br /> for _, date in ipairs(same_dates) do<br /> show(nil, date:text() .. &#039; or &#039; .. date:text(&#039;mdy&#039;))<br /> end<br /> local more_dates = {<br /> Date(&#039;4 October 1582&#039;, &#039;Julian&#039;),<br /> Date(&#039;juliandate&#039;, 2299160),<br /> Date(&#039;15 October 1582&#039;),<br /> }<br /> for _, date in ipairs(more_dates) do<br /> show(nil, date.dayname .. &#039; &#039; .. date:text() .. &#039; in the &#039; ..<br /> date.calendar .. &#039; calendar is Julian day &#039; .. 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(&#039;Show a date&#039;)<br /> local dates = {<br /> Date(2016, 3, 9),<br /> Date(&#039;9 March 2016 BC&#039;),<br /> }<br /> local format_option = {<br /> { &#039;ymd&#039; },<br /> { &#039;mdy&#039; },<br /> { &#039;dmy&#039; },<br /> { &#039;dmy&#039;, &#039;era=B.C.E.&#039; },<br /> { &#039;%A %B %-d, %Y %{era}&#039; },<br /> { &#039;%A %B %-d, %Y %{era}&#039;, &#039;era=A.D.&#039; },<br /> { &#039;a %{dayname} in %{monthname} %Y %{era}&#039; },<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(&#039;currentdate&#039;)<br /> local now_datetime = Date(&#039;currentdatetime&#039;)<br /> show(&#039;Current date showing when this page was last purged&#039;,<br /> now_date:text(), -- 7 March 2016 (for example)<br /> now_date:text(&#039;mdy&#039;), -- March 7, 2016<br /> now_date:text(&#039;ymd&#039;), -- 2016-03-07<br /> now_date:text(&#039;%A %-d %B %-Y&#039;), -- Monday 7 March 2016<br /> now_datetime:text(), -- 21:32:45 7 March 2016<br /> now_datetime:text(&#039;hms&#039;), -- 21:32:45<br /> now_datetime:text(&#039;%c&#039;) -- 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(&#039;Module:Date&#039;)._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(&#039;Using the current date as a default&#039;,<br /> year, month, day, hour, minute, second)<br /> -- Alternatively, a date can be constructed with specified items overridden.<br /> show(nil, Date(&#039;currentdatetime&#039;, {<br /> year = year,<br /> month = month,<br /> day = day,<br /> hour = hour,<br /> minute = minute,<br /> second = second }):text(&#039;%c&#039;))<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(&#039;Make a date from the day number in a year&#039;)<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, &#039;Day &#039; .. date.dayofyear .. &#039; in &#039; .. year .. &#039; is &#039; .. 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 = &#039;Days in month&#039;<br /> if calendar_name then<br /> title = title .. &#039; (&#039; .. calendar_name .. &#039; calendar)&#039;<br /> end<br /> local monthdays = require(&#039;Module:Date&#039;)._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 .. &#039; &#039; .. date.year .. &#039; had &#039; .. date.monthdays .. &#039; days&#039;)<br /> show(nil, date:text(&#039;%{monthname} %{year} had %{monthdays} days&#039;)) -- same<br /> end<br /> <br /> -- Julian day number and date arithmetic.<br /> local function julian_date(year, month, count, calendar_name)<br /> show(&#039;Julian date&#039;)<br /> if not calendar_name then -- Gregorian calendar by default<br /> local date = Date(&#039;24 November 4714 BCE&#039;)<br /> show(nil, &#039;Julian day number was &#039; .. date.jd .. &#039; on &#039; .. date:text(&#039;mdy&#039;))<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 + &#039;1m&#039; -- next month<br /> local date = first_of_month - &#039;1d&#039; -- last day of month<br /> show(nil,<br /> &#039;Last day in month (&#039; .. date:text() .. &#039; &#039; .. date.calendar ..<br /> &#039; calendar) had Julian day number &#039; .. 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(&#039;currentdate&#039;)<br /> local then_date = Date(date_text)<br /> if not then_date then<br /> show(&#039;How long&#039;, &#039;Invalid date: &#039; .. (date_text or &#039;&#039;))<br /> return<br /> end<br /> local fmt = &#039;%A %B %-d, %-Y %{era} (day of year = %{dayofyear}, serial day = %{gsd}) &#039;<br /> local info = then_date:text(fmt)<br /> if then_date == now_date then<br /> fmt = &#039;is now (%d day%s)&#039;<br /> elseif then_date &gt; now_date then<br /> fmt = &#039;will be in %d day%s&#039;<br /> else<br /> fmt = &#039;was %d day%s ago&#039;<br /> end<br /> local diff = then_date - now_date<br /> local days = diff.age_days<br /> local s = days == 1 and &#039;&#039; or &#039;s&#039;<br /> show(&#039;How long&#039;, info .. string.format(fmt, days, s))<br /> local y, m, d = diff:age(&#039;ymd&#039;) -- age in years, months, days<br /> show(nil, string.format(&#039;(%d years + %d months + %d days)&#039;, 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(&#039;First and third Fridays in each month of &#039; .. year)<br /> for month = 1, 12 do<br /> local dates = Date(year, month, 1):list(&#039;Friday &gt;=&#039;)<br /> show(nil, dates[1] .. &#039;, &#039; .. dates[3])<br /> end<br /> end<br /> <br /> -- Next Friday after or before a particular date.<br /> local function next_friday()<br /> show(&#039;Next Friday and last Friday for certain dates&#039;)<br /> local dates = {<br /> Date(&#039;1 Jan 2016&#039;),<br /> Date(&#039;2 Jan 2016&#039;),<br /> Date(&#039;3 Mar 1980&#039;),<br /> }<br /> for _, date in ipairs(dates) do<br /> -- 1 = number of Fridays that are wanted in the list<br /> local after = date:list(&#039;1 Friday&#039;)[1]<br /> local before = date:list(&#039;1 Friday &lt;&#039;)[1]<br /> local format = &#039;%A %-d %B %-Y&#039;<br /> show(nil,<br /> &#039;For &#039; .. date:text(format) ..<br /> &#039;, the next is &#039; .. after:text(format) ..<br /> &#039;, and the last is &#039; .. 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, &#039;&#039;)<br /> end<br /> table.insert(lines, &quot;&#039;&#039;&#039;&quot; .. title .. &quot;&#039;&#039;&#039;&quot;)<br /> end<br /> for _, text in ipairs({...}) do<br /> table.insert(lines, &#039;:&#039; .. 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, &#039;Julian&#039;)<br /> julian_date(1899, 11, 4)<br /> julian_date(-120, 11, 4, &#039;Julian&#039;)<br /> how_long(&#039;29 Feb 2100&#039;) -- an invalid date<br /> how_long(&#039;currentdate&#039;)<br /> how_long(&#039;29 Feb 2400&#039;)<br /> how_long(&#039;29 Feb 2401 BCE&#039;)<br /> fridays(2016)<br /> next_friday()<br /> return table.concat(lines, &#039;\n&#039;)<br /> end<br /> <br /> return { main = main }</div> Johnuniq