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
diff -r dddf4e85bfe4 -r e0fb8a49e031 core/src/luan/impl/LuanParser.java
--- 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("...") ) {
diff -r dddf4e85bfe4 -r e0fb8a49e031 core/src/luan/modules/Time.luan
--- /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
diff -r dddf4e85bfe4 -r e0fb8a49e031 dist/jars/luan-core-trunk.jar
Binary file dist/jars/luan-core-trunk.jar has changed
diff -r dddf4e85bfe4 -r e0fb8a49e031 dist/jars/luan-logging-trunk.jar
Binary file dist/jars/luan-logging-trunk.jar has changed
diff -r dddf4e85bfe4 -r e0fb8a49e031 dist/jars/luan-lucene-trunk.jar
Binary file dist/jars/luan-lucene-trunk.jar has changed
diff -r dddf4e85bfe4 -r e0fb8a49e031 dist/jars/luan-mail-trunk.jar
Binary file dist/jars/luan-mail-trunk.jar has changed
diff -r dddf4e85bfe4 -r e0fb8a49e031 dist/jars/luan-web-trunk.jar
Binary file dist/jars/luan-web-trunk.jar has changed