mirror of
https://github.com/TangentFoxy/lua-date.git
synced 2025-07-28 11:02:17 +00:00
Upload version 2.0
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
package = "date"
|
||||
version = "1.0-1"
|
||||
source = {
|
||||
url = "http://luaforunix.luaforge.net/packages/date-1.0-1.tar.gz",
|
||||
}
|
||||
description = {
|
||||
summary = "Lua Date and Time module for Lua 5.1",
|
||||
detailed = [[
|
||||
Date and Time string parsing; Time addition and subtraction;
|
||||
Time span calculation; Supports ISO 8601 Dates.
|
||||
]],
|
||||
license = "MIT/X11",
|
||||
homepage = "http://luaforge.net/projects/date/",
|
||||
maintainer = "Steve Donovan <steve.j.donovan@gmail.com>",
|
||||
}
|
||||
dependencies = {
|
||||
}
|
||||
build = {
|
||||
type = "none",
|
||||
copy_directories = {'doc','samples'},
|
||||
install = {
|
||||
lua = {
|
||||
date = "date.lua"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
date-2.0.1-1.rockspec
Normal file
29
date-2.0.1-1.rockspec
Normal file
@@ -0,0 +1,29 @@
|
||||
package = "date"
|
||||
version = "2.0.1-1"
|
||||
|
||||
description = {
|
||||
summary = "Date & Time module for Lua 5.x",
|
||||
detailed = [[
|
||||
Pure Lua Date & Time module for Lua 5.x featuring date and Time string
|
||||
parsing, time addition & subtraction, time span calculation, support for
|
||||
ISO 8601 Dates, local time support, strftime-like formatting.
|
||||
]],
|
||||
license = "Public Domain",
|
||||
homepage = "http://luaforge.net/projects/date/",
|
||||
}
|
||||
|
||||
dependencies = {
|
||||
"lua ~> 5.1"
|
||||
}
|
||||
|
||||
source = {
|
||||
url = "http://luaforge.net/frs/download.php/1708/date.zip",
|
||||
dir = ".",
|
||||
}
|
||||
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
date = "date.lua"
|
||||
}
|
||||
}
|
10
date.lua
10
date.lua
@@ -136,9 +136,9 @@
|
||||
local y = (n400*400) + (n100*100) + (n004*4) + n001 - ((n001 == 4 or n100 == 4) and 1 or 0)
|
||||
local d = g - dayfromyear(y)
|
||||
local mi = floor((100*d + 52)/3060)
|
||||
return (floor((mi + 2)/12) + y), mod(mi + 2,12), (d - floor((mi*306 + 5)/10) + 1)
|
||||
return (floor((mi + 2)/12) + y), mod(mi + 2,12), (d - floor((mi*306 + 5)/10) + 1)
|
||||
end
|
||||
]]
|
||||
]]
|
||||
-- day fraction from time
|
||||
local function makedayfrc(h,r,s,t)
|
||||
return ((h*60 + r)*60 + s)*TICKSPERSEC + t
|
||||
@@ -403,7 +403,6 @@
|
||||
end
|
||||
--#end -- not DATE_OBJECT_AFX
|
||||
local function date_from(...)
|
||||
local arg = {...}
|
||||
local y, m, d = fix(arg[1]), getmontharg(arg[2]), fix(arg[3])
|
||||
local h, r, s, t = tonumber(arg[4] or 0), tonumber(arg[5] or 0), tonumber(arg[6] or 0), tonumber(arg[7] or 0)
|
||||
if y and m and d and h and r and s and t then
|
||||
@@ -701,9 +700,8 @@
|
||||
end
|
||||
|
||||
function date:__call(...)
|
||||
local arg = {...}
|
||||
local n = #arg
|
||||
if n > 1 then return (date_from(...))
|
||||
local n = arg.n
|
||||
if n > 1 then return (date_from(unpack(arg)))
|
||||
elseif n == 0 then return (date_getdobj(false))
|
||||
else local o, r = date_getdobj(arg[1]); return r and o:copy() or o end
|
||||
end
|
||||
|
BIN
doc/date.doc.chm
Normal file
BIN
doc/date.doc.chm
Normal file
Binary file not shown.
@@ -32,7 +32,7 @@ local htm_head = [[
|
||||
td {vertical-align: middle; text-align:center;}
|
||||
td.sun {color: red;}
|
||||
td.sat {color: blue;}
|
||||
</style>
|
||||
</style>
|
||||
<html>
|
||||
]]
|
||||
local htm_yearhead = '\n<table align="left">'
|
||||
@@ -40,7 +40,7 @@ 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_yearfoot = '\n</table>'
|
||||
function makecalendar(y, iox)
|
||||
iox:write(htm_yearhead)
|
||||
iox:write(htm_yearhead)
|
||||
for i = 1, 12 do
|
||||
local tm = makemonth(y, i)
|
||||
iox:write(string.format(htm_monhead, tm.name, tm.year))
|
||||
@@ -49,7 +49,7 @@ function makecalendar(y, iox)
|
||||
end
|
||||
end
|
||||
iox:write(htm_yearfoot)
|
||||
|
||||
|
||||
end
|
||||
|
||||
io.stdout:write(htm_head)
|
||||
|
@@ -1,23 +0,0 @@
|
||||
require 'date'
|
||||
|
||||
d1 = date('July 4 2009')
|
||||
assert(d1:getmonth() == 7)
|
||||
d2 = d1:copy()
|
||||
d2:adddays(2)
|
||||
diff = d2 - d1
|
||||
assert(diff:spandays() == 2)
|
||||
assert(diff:spanhours() == 48)
|
||||
|
||||
assert(date 'July 4 2009' == date '2009-07-04')
|
||||
|
||||
a = date(1970, 1, 1)
|
||||
y, m, d = a:getdate()
|
||||
assert(y == 1970 and m == 1 and d == 1)
|
||||
|
||||
d = date(1966, 'sep', 6)
|
||||
assert(d:getday() == 6)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user