diff core/src/luan/modules/Time.luan @ 290:9a0cc6d9b27b

add Time.period(); add assert_long(); git-svn-id: https://luan-java.googlecode.com/svn/trunk@291 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 09 Dec 2014 04:39:18 +0000
parents b669cdaf54b7
children 899253043270
line wrap: on
line diff
--- a/core/src/luan/modules/Time.luan	Mon Dec 08 07:45:40 2014 +0000
+++ b/core/src/luan/modules/Time.luan	Tue Dec 09 04:39:18 2014 +0000
@@ -6,6 +6,7 @@
 import "java:java.lang.System"
 import "java:java.util.Calendar"
 import "java:java.util.Date"
+import "java:java.util.TimeZone"
 import "java:java.text.SimpleDateFormat"
 
 
@@ -44,11 +45,21 @@
 function on( year, month, day, hour, minute, second, millis )
 	month = month - 1
 	local cal = Calendar.getInstance()
+	cal.setLenient(false)
 	cal.set( year, month, day, hour or 0, minute or 0, second or 0 )
 	cal.set( Calendar.MILLISECOND, millis or 0 )
 	return cal.getTimeInMillis()
 end
 
+function period( days, hours, minutes, seconds, millis )
+	local cal = Calendar.getInstance()
+	cal.setTimeZone(TimeZone.getTimeZone("GMT"))
+	days = days + 1
+	cal.set( 1970, 0, days, hours or 0, minutes or 0, seconds or 0 )
+	cal.set( Calendar.MILLISECOND, millis or 0 )
+	return cal.getTimeInMillis()
+end
+
 function parse( pattern, source )
 	return SimpleDateFormat.new(pattern).parse(source).getTime()
 end