Pārlūkot izejas kodu

added DateTools.makeUtc

Simon Krajewski 12 gadi atpakaļ
vecāks
revīzija
55f54dde68
2 mainītis faili ar 20 papildinājumiem un 1 dzēšanām
  1. 16 0
      std/DateTools.hx
  2. 4 1
      tests/unit/unitstd/DateTools.unit.hx

+ 16 - 0
std/DateTools.hx

@@ -199,5 +199,21 @@ class DateTools {
 	public static function make( o : { ms : Float, seconds : Int, minutes : Int, hours : Int, days : Int } ) {
 		return o.ms + 1000.0 * (o.seconds + 60.0 * (o.minutes + 60.0 * (o.hours + 24.0 * o.days)));
 	}
+	
+	/**
+		Retrieve Unix timestamp value from Date components. Takes same argument sequence as the Date constructor.
+	**/
+	public static #if (js || flash || php) inline #end function makeUtc(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ):Float {
+	    #if (js || flash)
+		   return untyped Date.UTC(year, month, day, hour, min, sec);
+		#elseif php
+		   return untyped __call__("gmmktime", hour, min, sec, month + 1, day, year) * 1000;
+		#elseif cpp
+		  return untyped __global__.__hxcpp_utc_date(year,month,day,hour,min,sec)*1000.0 ;  
+		#else
+			//TODO
+		   return 0.;
+		#end
+	}
 
 }

+ 4 - 1
tests/unit/unitstd/DateTools.unit.hx

@@ -5,4 +5,7 @@ DateTools.getMonthDays(d) == 29;
 // seconds/delta
 var diff = DateTools.seconds(59);
 var d2 = DateTools.delta(d, diff);
-d2.toString() == "2012-02-17 01:03:02";
+d2.toString() == "2012-02-17 01:03:02";
+
+//UTC based timestamp generation
+DateTools.makeUtc(1982, 10, 10, 14, 2, 20) == 405784940000.;