|
@@ -32,7 +32,14 @@
|
|
There are some extra functions available in the `DateTools` class.
|
|
There are some extra functions available in the `DateTools` class.
|
|
|
|
|
|
In the context of Haxe dates, a timestamp is defined as the number of
|
|
In the context of Haxe dates, a timestamp is defined as the number of
|
|
- milliseconds elapsed since 1st January 1970.
|
|
|
|
|
|
+ milliseconds elapsed since 1st January 1970 UTC.
|
|
|
|
+
|
|
|
|
+ ## Supported range
|
|
|
|
+
|
|
|
|
+ Due to platform limitations, only dates in the range 1970 through 2038 are
|
|
|
|
+ supported consistently. Some targets may support dates outside this range,
|
|
|
|
+ depending on the OS at runtime. The `Date.fromTime` method will not work with
|
|
|
|
+ timestamps outside the range on any target.
|
|
**/
|
|
**/
|
|
extern class Date {
|
|
extern class Date {
|
|
/**
|
|
/**
|
|
@@ -41,7 +48,7 @@ extern class Date {
|
|
The behaviour of a Date instance is only consistent across platforms if
|
|
The behaviour of a Date instance is only consistent across platforms if
|
|
the the arguments describe a valid date.
|
|
the the arguments describe a valid date.
|
|
|
|
|
|
- - month: 0 to 11
|
|
|
|
|
|
+ - month: 0 to 11 (note that this is zero-based)
|
|
- day: 1 to 31
|
|
- day: 1 to 31
|
|
- hour: 0 to 23
|
|
- hour: 0 to 23
|
|
- min: 0 to 59
|
|
- min: 0 to 59
|
|
@@ -50,8 +57,11 @@ extern class Date {
|
|
function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void;
|
|
function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the timestamp (in milliseconds) of the date. It might
|
|
|
|
- only have a per-second precision depending on the platforms.
|
|
|
|
|
|
+ Returns the timestamp (in milliseconds) of `this` date.
|
|
|
|
+ On cpp and neko, this function only has a second resolution, so the
|
|
|
|
+ result will always be a multiple of `1000.0`, e.g. `1454698271000.0`.
|
|
|
|
+ To obtain the current timestamp with better precision on cpp and neko,
|
|
|
|
+ see the `Sys.time` API.
|
|
|
|
|
|
For measuring time differences with millisecond accuracy on
|
|
For measuring time differences with millisecond accuracy on
|
|
all platforms, see `haxe.Timer.stamp`.
|
|
all platforms, see `haxe.Timer.stamp`.
|
|
@@ -59,44 +69,92 @@ extern class Date {
|
|
function getTime():Float;
|
|
function getTime():Float;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the hours of `this` Date (0-23 range).
|
|
|
|
|
|
+ Returns the hours of `this` Date (0-23 range) in the local timezone.
|
|
**/
|
|
**/
|
|
function getHours():Int;
|
|
function getHours():Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the minutes of `this` Date (0-59 range).
|
|
|
|
|
|
+ Returns the minutes of `this` Date (0-59 range) in the local timezone.
|
|
**/
|
|
**/
|
|
function getMinutes():Int;
|
|
function getMinutes():Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the seconds of `this` Date (0-59 range).
|
|
|
|
|
|
+ Returns the seconds of `this` Date (0-59 range) in the local timezone.
|
|
**/
|
|
**/
|
|
function getSeconds():Int;
|
|
function getSeconds():Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the full year of `this` Date (4-digits).
|
|
|
|
|
|
+ Returns the full year of `this` Date (4 digits) in the local timezone.
|
|
**/
|
|
**/
|
|
function getFullYear():Int;
|
|
function getFullYear():Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the month of `this` Date (0-11 range).
|
|
|
|
|
|
+ Returns the month of `this` Date (0-11 range) in the local timezone.
|
|
|
|
+ Note that the month number is zero-based.
|
|
**/
|
|
**/
|
|
function getMonth():Int;
|
|
function getMonth():Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the day of `this` Date (1-31 range).
|
|
|
|
|
|
+ Returns the day of `this` Date (1-31 range) in the local timezone.
|
|
**/
|
|
**/
|
|
function getDate():Int;
|
|
function getDate():Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns the day of the week of `this` Date (0-6 range) where `0` is Sunday.
|
|
|
|
|
|
+ Returns the day of the week of `this` Date (0-6 range, where `0` is Sunday)
|
|
|
|
+ in the local timezone.
|
|
**/
|
|
**/
|
|
function getDay():Int;
|
|
function getDay():Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns a string representation of `this` Date, by using the
|
|
|
|
- standard format [YYYY-MM-DD HH:MM:SS]. See `DateTools.format` for
|
|
|
|
- other formating rules.
|
|
|
|
|
|
+ Returns the hours of `this` Date (0-23 range) in UTC.
|
|
|
|
+ **/
|
|
|
|
+ function getUTCHours():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns the minutes of `this` Date (0-59 range) in UTC.
|
|
|
|
+ **/
|
|
|
|
+ function getUTCMinutes():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns the seconds of `this` Date (0-59 range) in UTC.
|
|
|
|
+ **/
|
|
|
|
+ function getUTCSeconds():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns the full year of `this` Date (4 digits) in UTC.
|
|
|
|
+ **/
|
|
|
|
+ function getUTCFullYear():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns the month of `this` Date (0-11 range) in UTC.
|
|
|
|
+ Note that the month number is zero-based.
|
|
|
|
+ **/
|
|
|
|
+ function getUTCMonth():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns the day of `this` Date (1-31 range) in UTC.
|
|
|
|
+ **/
|
|
|
|
+ function getUTCDate():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns the day of the week of `this` Date (0-6 range, where `0` is Sunday)
|
|
|
|
+ in UTC.
|
|
|
|
+ **/
|
|
|
|
+ function getUTCDay():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns the time zone difference of `this` Date in the current locale
|
|
|
|
+ to UTC, in minutes.
|
|
|
|
+
|
|
|
|
+ Assuming the function is executed on a machine in a UTC+2 timezone,
|
|
|
|
+ `Date.now().getTimezoneOffset()` will return `-120`.
|
|
|
|
+ **/
|
|
|
|
+ function getTimezoneOffset():Int;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns a string representation of `this` Date in the local timezone
|
|
|
|
+ using the standard format `YYYY-MM-DD HH:MM:SS`. See `DateTools.format` for
|
|
|
|
+ other formatting rules.
|
|
**/
|
|
**/
|
|
function toString():String;
|
|
function toString():String;
|
|
|
|
|
|
@@ -106,67 +164,20 @@ extern class Date {
|
|
static function now():Date;
|
|
static function now():Date;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns a Date from timestamp (in milliseconds) `t`.
|
|
|
|
|
|
+ Creates a Date from the timestamp (in milliseconds) `t`.
|
|
**/
|
|
**/
|
|
static function fromTime(t:Float):Date;
|
|
static function fromTime(t:Float):Date;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Returns a Date from a formatted string `s`, with the following accepted
|
|
|
|
- formats:
|
|
|
|
|
|
+ Creates a Date from the formatted string `s`. The following formats are
|
|
|
|
+ accepted by the function:
|
|
|
|
|
|
- `"YYYY-MM-DD hh:mm:ss"`
|
|
- `"YYYY-MM-DD hh:mm:ss"`
|
|
- `"YYYY-MM-DD"`
|
|
- `"YYYY-MM-DD"`
|
|
- `"hh:mm:ss"`
|
|
- `"hh:mm:ss"`
|
|
|
|
|
|
- The first two formats are expressed in local time, the third in UTC
|
|
|
|
- Epoch.
|
|
|
|
|
|
+ The first two formats expressed a date in local time. The third is a time
|
|
|
|
+ relative to the UTC epoch.
|
|
**/
|
|
**/
|
|
static function fromString(s:String):Date;
|
|
static function fromString(s:String):Date;
|
|
-
|
|
|
|
- #if flash
|
|
|
|
- private static function __init__():Void
|
|
|
|
- untyped {
|
|
|
|
- var d:Dynamic = Date;
|
|
|
|
- d.now = function() {
|
|
|
|
- return __new__(Date);
|
|
|
|
- };
|
|
|
|
- d.fromTime = function(t) {
|
|
|
|
- var d:Date = __new__(Date);
|
|
|
|
- d.setTime(t);
|
|
|
|
- return d;
|
|
|
|
- };
|
|
|
|
- d.fromString = function(s:String) {
|
|
|
|
- switch (s.length) {
|
|
|
|
- case 8: // hh:mm:ss
|
|
|
|
- var k = s.split(":");
|
|
|
|
- var d:Date = __new__(Date);
|
|
|
|
- d.setTime(0);
|
|
|
|
- d.setUTCHours(k[0]);
|
|
|
|
- d.setUTCMinutes(k[1]);
|
|
|
|
- d.setUTCSeconds(k[2]);
|
|
|
|
- return d;
|
|
|
|
- case 10: // YYYY-MM-DD
|
|
|
|
- var k = s.split("-");
|
|
|
|
- return new Date(cast k[0], cast k[1] - 1, cast k[2], 0, 0, 0);
|
|
|
|
- case 19: // YYYY-MM-DD hh:mm:ss
|
|
|
|
- var k = s.split(" ");
|
|
|
|
- var y = k[0].split("-");
|
|
|
|
- var t = k[1].split(":");
|
|
|
|
- return new Date(cast y[0], cast y[1] - 1, cast y[2], cast t[0], cast t[1], cast t[2]);
|
|
|
|
- default:
|
|
|
|
- throw "Invalid date format : " + s;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- d.prototype[#if (as3 || no_flash_override) "toStringHX" #else "toString" #end] = function() {
|
|
|
|
- var date:Date = __this__;
|
|
|
|
- var m = date.getMonth() + 1;
|
|
|
|
- var d = date.getDate();
|
|
|
|
- var h = date.getHours();
|
|
|
|
- var mi = date.getMinutes();
|
|
|
|
- var s = date.getSeconds();
|
|
|
|
- return date.getFullYear() + "-" + (if (m < 10) "0" + m else "" + m) + "-" + (if (d < 10) "0" + d else "" + d) + " "
|
|
|
|
- + (if (h < 10) "0" + h else "" + h) + ":" + (if (mi < 10) "0" + mi else "" + mi) + ":" + (if (s < 10) "0" + s else "" + s);
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- #end
|
|
|
|
}
|
|
}
|