mirror of
https://github.com/TangentFoxy/lua-date.git
synced 2025-07-28 02:52:18 +00:00
chore(*) replace tabs with spaces
This commit is contained in:
@@ -2,36 +2,36 @@
|
|||||||
This script makes an html calendar
|
This script makes an html calendar
|
||||||
Syntax: mkcalendar.lua year1 year2 year3 .. yearn > file
|
Syntax: mkcalendar.lua year1 year2 year3 .. yearn > file
|
||||||
arg:
|
arg:
|
||||||
year1 .. yearn - the year(s) of the calendar to generate
|
year1 .. yearn - the year(s) of the calendar to generate
|
||||||
file - the name of the file to write the generated text calendar
|
file - the name of the file to write the generated text calendar
|
||||||
--]]---------------------
|
--]]---------------------
|
||||||
|
|
||||||
local date = require"date"
|
local date = require"date"
|
||||||
|
|
||||||
function makemonth(y,m)
|
function makemonth(y,m)
|
||||||
local t = {}
|
local t = {}
|
||||||
local d = date(y,m,1)
|
local d = date(y,m,1)
|
||||||
t.name = d:fmt("%B")
|
t.name = d:fmt("%B")
|
||||||
t.year = y
|
t.year = y
|
||||||
-- get back to the nearest sunday
|
-- get back to the nearest sunday
|
||||||
d:adddays(-(d:getweekday()-1))
|
d:adddays(-(d:getweekday()-1))
|
||||||
repeat
|
repeat
|
||||||
local tt = {}
|
local tt = {}
|
||||||
table.insert(t,tt)
|
table.insert(t,tt)
|
||||||
repeat -- insert the week days
|
repeat -- insert the week days
|
||||||
table.insert(tt, d:getday())
|
table.insert(tt, d:getday())
|
||||||
until d:adddays(1):getweekday() == 1
|
until d:adddays(1):getweekday() == 1
|
||||||
until d:getmonth() ~= m
|
until d:getmonth() ~= m
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local htm_foot = '\n</html>'
|
local htm_foot = '\n</html>'
|
||||||
local htm_head = [[
|
local htm_head = [[
|
||||||
<style>
|
<style>
|
||||||
th {background:black; color: silver; vertical-align: middle;}
|
th {background:black; color: silver; vertical-align: middle;}
|
||||||
td {vertical-align: middle; text-align:center;}
|
td {vertical-align: middle; text-align:center;}
|
||||||
td.sun {color: red;}
|
td.sun {color: red;}
|
||||||
td.sat {color: blue;}
|
td.sat {color: blue;}
|
||||||
</style>
|
</style>
|
||||||
<html>
|
<html>
|
||||||
]]
|
]]
|
||||||
@@ -40,23 +40,23 @@ local htm_monhead = '\n<tr><th colspan = "7">%s, %s</th></tr><tr><td>sun</td><t
|
|||||||
local htm_monweek = '\n<tr><td class="sun">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td class="sat">%s</td></tr>'
|
local htm_monweek = '\n<tr><td class="sun">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td class="sat">%s</td></tr>'
|
||||||
local htm_yearfoot = '\n</table>'
|
local htm_yearfoot = '\n</table>'
|
||||||
function makecalendar(y, iox)
|
function makecalendar(y, iox)
|
||||||
iox:write(htm_yearhead)
|
iox:write(htm_yearhead)
|
||||||
for i = 1, 12 do
|
for i = 1, 12 do
|
||||||
local tm = makemonth(y, i)
|
local tm = makemonth(y, i)
|
||||||
iox:write(string.format(htm_monhead, tm.name, tm.year))
|
iox:write(string.format(htm_monhead, tm.name, tm.year))
|
||||||
for k, v in ipairs(tm) do
|
for k, v in ipairs(tm) do
|
||||||
iox:write(string.format(htm_monweek, v[1], v[2], v[3], v[4], v[5], v[6], v[7]))
|
iox:write(string.format(htm_monweek, v[1], v[2], v[3], v[4], v[5], v[6], v[7]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
iox:write(htm_yearfoot)
|
iox:write(htm_yearfoot)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
io.stdout:write(htm_head)
|
io.stdout:write(htm_head)
|
||||||
|
|
||||||
for k, v in ipairs(arg) do
|
for k, v in ipairs(arg) do
|
||||||
local y = tonumber(v)
|
local y = tonumber(v)
|
||||||
if y then makecalendar(y, io.stdout) end
|
if y then makecalendar(y, io.stdout) end
|
||||||
end
|
end
|
||||||
|
|
||||||
io.stdout:write(htm_foot)
|
io.stdout:write(htm_foot)
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
This script makes an iso year-week-day calendar
|
This script makes an iso year-week-day calendar
|
||||||
Syntax: mkisocal.lua year1 year2 year3 .. yearn > file
|
Syntax: mkisocal.lua year1 year2 year3 .. yearn > file
|
||||||
arg:
|
arg:
|
||||||
year1 .. yearn - the year(s) of the calendar to generate
|
year1 .. yearn - the year(s) of the calendar to generate
|
||||||
file - the name of the file to write the generated text calendar
|
file - the name of the file to write the generated text calendar
|
||||||
--]]---------------------
|
--]]---------------------
|
||||||
|
|
||||||
local date = require"date"
|
local date = require"date"
|
||||||
@@ -13,16 +13,16 @@ local htm_head = [[<html><head><style>body{color:#000000;background-color:#FFFFF
|
|||||||
local htm_yearhead = [[<table align="center" width="100%" border="1"><tr><th>Year</th><th>Week</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr>]]
|
local htm_yearhead = [[<table align="center" width="100%" border="1"><tr><th>Year</th><th>Week</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr>]]
|
||||||
local htm_yearfoot = [[</table>]]
|
local htm_yearfoot = [[</table>]]
|
||||||
function makecalendar(year, iow)
|
function makecalendar(year, iow)
|
||||||
local d = date():setisoyear(year,1,1)
|
local d = date():setisoyear(year,1,1)
|
||||||
iow(htm_yearhead)
|
iow(htm_yearhead)
|
||||||
iow("<!--".. d .. "-->\n")
|
iow("<!--".. d .. "-->\n")
|
||||||
while d:getisoyear() == year do
|
while d:getisoyear() == year do
|
||||||
iow(d:fmt("<tr><td>%G</td><td>%V<br/><small class='s'>%Y-%j</small></td>"))
|
iow(d:fmt("<tr><td>%G</td><td>%V<br/><small class='s'>%Y-%j</small></td>"))
|
||||||
repeat iow(d:fmt("<td>%u<br/><small class='s'>%b %d %Y</small></td>"))
|
repeat iow(d:fmt("<td>%u<br/><small class='s'>%b %d %Y</small></td>"))
|
||||||
until d:adddays(1):getisoweekday() == 1
|
until d:adddays(1):getisoweekday() == 1
|
||||||
iow("</tr>\n")
|
iow("</tr>\n")
|
||||||
end
|
end
|
||||||
iow(htm_yearfoot)
|
iow(htm_yearfoot)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ local out = io.write
|
|||||||
out(htm_head)
|
out(htm_head)
|
||||||
|
|
||||||
for k, v in ipairs(arg) do
|
for k, v in ipairs(arg) do
|
||||||
local d = tonumber(v);
|
local d = tonumber(v);
|
||||||
if d then makecalendar(d, out) end
|
if d then makecalendar(d, out) end
|
||||||
end
|
end
|
||||||
|
|
||||||
out(htm_foot)
|
out(htm_foot)
|
||||||
|
@@ -35,7 +35,7 @@ describe("Testing the 'date' module", function()
|
|||||||
|
|
||||||
-- Supported ISO 8601 Formats.
|
-- Supported ISO 8601 Formats.
|
||||||
-- YYYY-MM-DDwhere YYYY is the year, MM is the month of the year, and DD is the
|
-- YYYY-MM-DDwhere YYYY is the year, MM is the month of the year, and DD is the
|
||||||
-- day of the month.
|
-- day of the month.
|
||||||
assert(date("2000-12-31")==date(2000,12,31))
|
assert(date("2000-12-31")==date(2000,12,31))
|
||||||
assert(date(" 20001231 ")==date(2000,12,31)) -- Compact version
|
assert(date(" 20001231 ")==date(2000,12,31)) -- Compact version
|
||||||
-- YYYY-DDDwhere YYYY is the year, DDD is the day of the year.
|
-- YYYY-DDDwhere YYYY is the year, DDD is the day of the year.
|
||||||
|
Reference in New Issue
Block a user