changeset 254:e0fb8a49e031

add Time.luan git-svn-id: https://luan-java.googlecode.com/svn/trunk@255 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 27 Oct 2014 20:45:05 +0000
parents dddf4e85bfe4
children e5ad26746c94
files core/src/luan/impl/LuanParser.java core/src/luan/modules/Time.luan dist/jars/luan-core-trunk.jar dist/jars/luan-logging-trunk.jar dist/jars/luan-lucene-trunk.jar dist/jars/luan-mail-trunk.jar dist/jars/luan-web-trunk.jar
diffstat 7 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/impl/LuanParser.java	Tue Oct 21 02:08:21 2014 +0000
+++ b/core/src/luan/impl/LuanParser.java	Mon Oct 27 20:45:05 2014 +0000
@@ -799,6 +799,7 @@
 				Spaces(inParens);
 				if( !parser.match("...") )
 					throw parser.exception();
+				Spaces(inParens);
 				frame.isVarArg = true;
 			}
 		} else if( parser.match("...") ) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/Time.luan	Mon Oct 27 20:45:05 2014 +0000
@@ -0,0 +1,41 @@
+-- incomplete, will add as needed
+
+import "String"
+import "Table"
+import "Java"
+import "java.lang.System"
+import "java.util.Calendar"
+import "java.util.Date"
+import "java.text.SimpleDateFormat"
+
+
+function now()
+	return System.currentTimeMillis()
+end
+
+-- add more as needed
+local fields = {
+	year = Calendar.YEAR;
+	month = Calendar.MONTH;
+	day_of_month = Calendar.DAY_OF_MONTH;
+}
+
+function get( time, ... )
+	local cal = Calendar.getInstance()
+	cal.setTimeInMillis(time)
+	local rtn = {}
+	for i, v in ipairs{...} do
+		local fld = fields[v.lower()]
+		fld or error("invalid field: "+v)
+		local n = cal.get(fld)
+		if fld == "month" then
+			n = n + 1
+		end
+		rtn[i] = n
+	end
+	return Table.unpack(rtn)
+end
+
+function format(time,pattern)
+	return SimpleDateFormat.new(pattern).format(Date.new(time))
+end
Binary file dist/jars/luan-core-trunk.jar has changed
Binary file dist/jars/luan-logging-trunk.jar has changed
Binary file dist/jars/luan-lucene-trunk.jar has changed
Binary file dist/jars/luan-mail-trunk.jar has changed
Binary file dist/jars/luan-web-trunk.jar has changed