summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMike Mason <ms13sp@gmail.com>2007-11-26 22:07:18 +0000
committerMike Mason <ms13sp@gmail.com>2007-11-26 22:07:18 +0000
commite48400ad5bc5347f25e4e010f878ddd9005fe32d (patch)
tree905d356fae2039a03cf47a6aa50d5b5ffe14ec96 /lib
parentc81b1c6057a070d7668f81f32d4182e56e753df1 (diff)
downloadacf-core-e48400ad5bc5347f25e4e010f878ddd9005fe32d.tar.bz2
acf-core-e48400ad5bc5347f25e4e010f878ddd9005fe32d.tar.xz
Added more tables and functions. Trying to document also.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@370 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/date.lua88
1 files changed, 86 insertions, 2 deletions
diff --git a/lib/date.lua b/lib/date.lua
index d588ecc..c80b3b0 100644
--- a/lib/date.lua
+++ b/lib/date.lua
@@ -4,6 +4,10 @@
module(..., package.seeall)
require("posix")
+--global for date formating see below for more information
+--Mon Nov 26 19:56:10 UTC 2007 looks like most systems use this
+--print(os.date(date.format))
+format = "%a %b %d %X %Z %Y"
months ={ {"January","Jan"},
{"February", "Feb"},
@@ -18,7 +22,6 @@ months ={ {"January","Jan"},
{"November","Nov"},
{"December","Dec"}
}
--- i am sure there is a better way to do this than a new table
revmonths = {["January"] = 1, ["Jan"] = 1,
["February"] = 2, ["Feb"] = 2,
@@ -33,7 +36,71 @@ revmonths = {["January"] = 1, ["Jan"] = 1,
["November"] = 11, ["Nov"] = 11,
["December"] = 12, ["Dec"] = 12
}
-
+
+dow = { {"Sunday","Sun"},
+ {"Monday","Mon"},
+ {"Tuesday","Tue"},
+ {"Wednesday","Wed"},
+ {"Thursday","Thu"},
+ {"Friday","Fri"},
+ {"Saturday","Sat"}
+ }
+
+revdow = { ["Sunday"] = 1, ["Sun"] = 2,
+ ["Monday"] = 2, ["Mon"] = 2,
+ ["Tuesday"] = 3, ["Tue"] = 3,
+ ["Wednesday"] = 4, ["Wed"] = 4,
+ ["Thursday"] = 5, ["Thu"] = 5,
+ ["Friday"] = 6, ["Fri"] = 6,
+ ["Saturday"] = 7, ["Sat"] =7
+ }
+
+
+--os.time() will give seconds since 1970-epoch
+--os.date() will give formated time strings
+--os.time{year=2007,month=1,day=1,hour=2,min=1,sec=1}
+--os.date(date.format,os.time())
+
+--give me a table
+--t = { {year=2007,month=1,day=2,hour=2}, {year=2006,month=1,day=5} }
+function date_to_seconds (t)
+ g = {}
+ count = table.maxn(t)
+ for i = 1,count do
+ g[#g+1] = os.time(t[i])
+ end
+ table.sort(g)
+ --will return a table sorted by oldest <-> newest
+ return g
+end
+
+-- the reverse of date_to_seconds. expecting a table of seconds
+--format can be changed. This seems to be standard, dow,mon,dom,time,zone,year
+-- seems like %z- +0000 time zone format and %Z- 3 letter timezone undocumented or new
+
+function seconds_to_date (t)
+ g = {}
+ count = table.maxn(t)
+ for i = 1,count do
+ g[#g+1] = os.date(format,t[i])
+ end
+
+ return g
+end
+
+--give dates in seconds and gives the difference in years,months,days,...
+--still working on this one. YEAR-1970 is what it needs
+function date_diff (d1, d2)
+ sum = d1 - d2
+ if sum > 0 then
+ t1,t2 = d1,d2
+ else
+ t1,t2 = d2,d1
+ end
+
+ return t1,t2
+end
+
--give a search number and return the month name
function num_month_name (search)
@@ -53,3 +120,20 @@ end
function abr_month_num (search)
return revmonths[search]
end
+
+function num_dow_full (search)
+ return dow[search][1]
+end
+
+function num_dow_abr (search)
+ return dow[search][2]
+end
+
+function name_dow_full (search)
+ return revdow[search]
+end
+
+function name_dow_abr (search)
+ return revdow[search]
+end
+