浏览代码

[cs] Fixed Date getDate/getDay mixup. Fixed Issue #1149

Caue Waneck 13 年之前
父节点
当前提交
7fafdbfe59
共有 4 个文件被更改,包括 36 次插入6 次删除
  1. 8 4
      std/cs/_std/Date.hx
  2. 10 1
      std/cs/_std/Type.hx
  3. 17 0
      tests/unit/TestMisc.hx
  4. 1 1
      tests/unit/unit.hxml

+ 8 - 4
std/cs/_std/Date.hx

@@ -11,8 +11,9 @@ import haxe.Int64;
 	**/
 	public function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ) : Void
 	{
+		if (day <= 0) day = 1;
 		if (year <= 0) year = 1;
-		date = new DateTime(year, month + 1, day + 1, hour, min, sec);
+		date = new DateTime(year, month + 1, day, hour, min, sec);
 	}
 
 	/**
@@ -70,15 +71,18 @@ import haxe.Int64;
 	**/
 	public inline function getDate() : Int
 	{
-		return cast date.DayOfWeek;
+		return date.Day;
 	}
 
 	/**
 		Returns the week day of the date (0-6 range).
 	**/
-	public inline function getDay() : Int
+	public function getDay() : Int
 	{
-		return date.Day;
+		var ret = cast(date.DayOfWeek, Int) - 1;
+		if (ret == -1)
+			ret = 6;
+		return ret;
 	}
 
 	/**

+ 10 - 1
std/cs/_std/Type.hx

@@ -331,7 +331,16 @@ import cs.internal.Runtime;
 
 	public static function allEnums<T>( e : Enum<T> ) : Array<T> 
 	{
-		return null;
+		var ctors = getEnumConstructs(e);
+		var ret = [];
+		for (ctor in ctors)
+		{
+			var v = Reflect.field(e, ctor);
+			if (Std.is(v, e))
+				ret.push(v);
+		}
+
+		return ret;
 	}
 
 }

+ 17 - 0
tests/unit/TestMisc.hx

@@ -104,6 +104,23 @@ class SubConstrOpt3 extends BaseConstrOpt {
 
 class TestMisc extends Test {
 
+	function testDate() {
+		var d = new Date(2012, 07, 17, 01, 02, 03);
+		eq( d.getDay(), 5 );
+
+		eq( d.getDate(), 17 );
+		eq( d.getMonth(), 7 );
+		eq( d.getFullYear(), 2012 );
+
+		eq( d.getHours(), 1 );
+		eq( d.getMinutes(), 2 );
+		eq( d.getSeconds(), 3 );
+
+		//seems to be system-dependent?
+		//eq( d.getTime(), 1345158123000 );
+		eq( d.toString(), "2012-08-17 01:02:03" );
+	}
+
 	function testClosure() {
 		var c = new MyClass(100);
 		var add = c.add;

+ 1 - 1
tests/unit/unit.hxml

@@ -80,5 +80,5 @@ unit.Test
 #cs-unsafe
 --next
 -main unit.Test
+-cs cs_unsafe
 -D unsafe
--cs cs_unsafe