Browse Source

[js] added js.Date.fromHaxeDate()

Alexander Kuzmenko 7 years ago
parent
commit
af6c89fe4d
2 changed files with 10 additions and 1 deletions
  1. 9 0
      std/js/Date.hx
  2. 1 1
      tests/server/src/Vfs.hx

+ 9 - 0
std/js/Date.hx

@@ -21,6 +21,8 @@
  */
 package js;
 
+import Date in HaxeDate;
+
 /**
 	Creates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January 1970 UTC.
 **/
@@ -32,6 +34,13 @@ extern class Date
 	@:overload(function(year:Int, month:Int, ?day:Int, ?hours:Int, ?minutes:Int, ?seconds:Int, ?milliseconds:Int):Void {})
 	function new() : Void;
 
+	/**
+		Cast Haxe's Date to js.Date.
+	**/
+	static public inline function fromHaxeDate(date:HaxeDate):js.Date {
+		return cast date;
+	}
+
 	/**
 		Returns the numeric value corresponding to the current time - the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC, with leap seconds ignored
 	**/

+ 1 - 1
tests/server/src/Vfs.hx

@@ -16,7 +16,7 @@ class Vfs {
 	public function touchFile(path:String) {
 		var path = getPhysicalPath(path);
 		FileSystem.createDirectory(path.dir);
-		var notNow = DateTools.delta(Date.now(), 1000);
+		var notNow = js.Date.fromHaxeDate(DateTools.delta(Date.now(), 1000));
 		var file = Fs.openSync(path.dir + "/" + path.file + "." + path.ext, 'a');
 		Fs.futimesSync(file, notNow, notNow);
 		Fs.closeSync(file);