summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMike Mason <ms13sp@gmail.com>2007-11-28 15:26:13 +0000
committerMike Mason <ms13sp@gmail.com>2007-11-28 15:26:13 +0000
commitdbddbd9b0cec1bfe8e92a39552b28ab2f11195d9 (patch)
tree94bf4751bfb9f58f6854244d98d9cfac1852fc03 /lib
parent7538b26d89faab270cd90ea72415d4dd2c988708 (diff)
downloadacf-core-dbddbd9b0cec1bfe8e92a39552b28ab2f11195d9.tar.bz2
acf-core-dbddbd9b0cec1bfe8e92a39552b28ab2f11195d9.tar.xz
added split and join to fs.lua and gave them function names so we don't have to strsplit = require split. Added a date string to table function in date.lua
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@378 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/README2
-rw-r--r--lib/date.lua28
-rw-r--r--lib/fs.lua36
3 files changed, 65 insertions, 1 deletions
diff --git a/lib/README b/lib/README
index 038ec0d..0d650dc 100644
--- a/lib/README
+++ b/lib/README
@@ -2,7 +2,7 @@ Brief discription of libs so far. For more info see
http://wiki.alpinelinux.org/w/index.php?title=ACF_Libraries
date.lua - Date and Time functions
-fs.lua - Many file type functions. May need to be renamed
+fs.lua - Many file,string,and table type functions. May need to be renamed
join.lua - Takes a table and given a delimeter makes it into a string
pidof.lua - Process libraries not provided by LPOSIX
split.lua - Take a delimeted string and makes it into a table
diff --git a/lib/date.lua b/lib/date.lua
index a7ed872..0a236cc 100644
--- a/lib/date.lua
+++ b/lib/date.lua
@@ -3,6 +3,7 @@
module(..., package.seeall)
require("posix")
+require("fs")
--global for date formating see below for more information
--Mon Nov 26 19:56:10 UTC 2007 looks like most systems use this
@@ -89,6 +90,33 @@ function seconds_to_date (t)
return g
end
+--Wed Nov 28 14:01:23 UTC 2007
+--os.date(date.format) put into a table
+--year,month,day,hour,min,sec,isdst- may need a dst table to set this automatically
+function string_to_table (str)
+ if str == nil then str = os.date(format) end
+ g = {}
+ temp = fs.string_to_table("%s",str)
+ month = abr_month_num(temp[2])
+ g["month"] = month
+ day = temp[3]
+ g["day"] = day
+ --may do something with this if have a tz table ??
+ tz = temp[5]
+ year = temp[6]
+ g["year"] = year
+ temp2 = fs.string_to_table(":",temp[4])
+ hour = temp2[1]
+ g["hour"] = hour
+ min = temp2[2]
+ g["min"] = min
+ sec = temp2[3]
+ g["sec"] = sec
+ return g
+
+end
+
+
--give dates in seconds and gives the difference in years,months,days,...
--gives a table back with hour,min,month,sec,day,year to display something like
--you have 10 years, 14 hours, 10 days to renew you certificate
diff --git a/lib/fs.lua b/lib/fs.lua
index 88df9f1..79d0cdc 100644
--- a/lib/fs.lua
+++ b/lib/fs.lua
@@ -155,3 +155,39 @@ function find ( what, where )
end
end
+-- This code comes from http://lua-users.org/wiki/SplitJoin
+-- -- example: strjoin(", ", {"Anna", "Bob", "Charlie", "Dolores"})
+function table_to_string (delimiter, list)
+ local len = getn(list)
+ if len == 0 then
+ return ""
+ end
+ local string = list[1]
+ for i = 2, len do
+ string = string .. delimiter .. list[i]
+ end
+ return string
+end
+
+-- This code comes from http://lua-users.org/wiki/SplitJoin
+-- example: strsplit(",%s*", "Anna, Bob, Charlie,Dolores")
+function string_to_table (delimiter, text)
+ local list = {}
+ local pos = 1
+ -- this would result in endless loops
+ if string.find("", delimiter, 1) then
+ error("delimiter matches empty string!")
+ end
+ while 1 do
+ local first, last = string.find(text, delimiter, pos)
+ if first then -- found?
+ table.insert(list, string.sub(text, pos, first-1))
+ pos = last+1
+ else
+ table.insert(list, string.sub(text, pos))
+ break
+ end
+ end
+ return list
+end
+