summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMike Mason <ms13sp@gmail.com>2007-11-27 15:02:29 +0000
committerMike Mason <ms13sp@gmail.com>2007-11-27 15:02:29 +0000
commitdfd2e72d1e995a12ba7d13345af3d5589f71fdcf (patch)
tree8ae0b68817290cf8c57732182648e41cb55131cd /lib
parente48400ad5bc5347f25e4e010f878ddd9005fe32d (diff)
downloadacf-core-dfd2e72d1e995a12ba7d13345af3d5589f71fdcf.tar.bz2
acf-core-dfd2e72d1e995a12ba7d13345af3d5589f71fdcf.tar.xz
fixed functions and updated with a date_diff
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@371 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/date.lua42
1 files changed, 30 insertions, 12 deletions
diff --git a/lib/date.lua b/lib/date.lua
index c80b3b0..9be0a45 100644
--- a/lib/date.lua
+++ b/lib/date.lua
@@ -63,6 +63,8 @@ revdow = { ["Sunday"] = 1, ["Sun"] = 2,
--give me a table
--t = { {year=2007,month=1,day=2,hour=2}, {year=2006,month=1,day=5} }
+--will return a table sorted by oldest <-> newest
+--to grab the largest and smallest a,b=g[1],g[table.maxn(g)]
function date_to_seconds (t)
g = {}
count = table.maxn(t)
@@ -70,7 +72,6 @@ function date_to_seconds (t)
g[#g+1] = os.time(t[i])
end
table.sort(g)
- --will return a table sorted by oldest <-> newest
return g
end
@@ -89,16 +90,33 @@ function seconds_to_date (t)
end
--give dates in seconds and gives the difference in years,months,days,...
---still working on this one. YEAR-1970 is what it needs
+--gives a table back with hour,min,month,sec,day,year to display something like
+--you have 10 years, 14 hours, 2 months and 10 days to renew you certificate
function date_diff (d1, d2)
+ g = {}
+ temp = {}
sum = d1 - d2
- if sum > 0 then
- t1,t2 = d1,d2
- else
- t1,t2 = d2,d1
+ if sum < 0 then
+ sum = d2 - d1
+ end
+ temp = os.date("*t",sum)
+ for a,b in pairs(temp) do
+ if a == "year" then
+ hold = b - 1970
+ g[a] = hold
+ elseif a == "hour" then
+ g[a] = b
+ elseif a == "min" then
+ g[a] = b
+ elseif a == "month" then
+ g[a] = b
+ elseif a == "sec" then
+ g[a] = b
+ elseif a == "day" then
+ g[a] = b
end
-
- return t1,t2
+ end
+ return g
end
--give a search number and return the month name
@@ -121,19 +139,19 @@ function abr_month_num (search)
return revmonths[search]
end
-function num_dow_full (search)
+function num_dow_name (search)
return dow[search][1]
end
-function num_dow_abr (search)
+function num_dow_name_abr (search)
return dow[search][2]
end
-function name_dow_full (search)
+function name_dow_num (search)
return revdow[search]
end
-function name_dow_abr (search)
+function abr_dow_num (search)
return revdow[search]
end