forked from hyperfiction/HypSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTools.hx
93 lines (77 loc) · 2.47 KB
/
DateTools.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package hypsystem.system;
class DateTools
{
public static function getTimezoneOffset():Float
{
return DateNative.getTimezoneOffset();
}
static inline function getDateTime(date:Date):Float
{
return date.getTime();
}
public static function getUTCFullYear(date:Date):Float
{
return DateNative.getUTCFullYear(getDateTime(date));
}
public static function getUTCMonth(date:Date):Float
{
return DateNative.getUTCMonth(getDateTime(date));
}
public static function getUTCDay(date:Date):Float
{
return DateNative.getUTCDay(getDateTime(date));
}
public static function getUTCDate(date:Date):Float
{
return DateNative.getUTCDate(getDateTime(date));
}
public static function getUTCHours(date:Date):Float
{
return DateNative.getUTCHours(getDateTime(date));
}
public static function getUTCMinutes(date:Date):Float
{
return DateNative.getUTCMinutes(getDateTime(date));
}
public static function getUTCSeconds(date:Date):Float
{
return DateNative.getUTCSeconds(getDateTime(date));
}
public static function getUTCMilliseconds(date:Date):Float
{
return DateNative.getUTCMilliseconds(getDateTime(date));
}
public static function toUTCString(date:Date):String
{
return DateNative.toUTCString(getDateTime(date));
}
public static function toISOString(date:Date, ?utc:Bool):String
{
return DateNative.toISOString(getDateTime(date), utc);
}
public static function fromISO(s:String):Date
{
var t:Float = DateNative.fromISO(s);
t -= getTimezoneOffset();
var date = Date.fromTime(t);
return date;
}
}
@:build(ShortCuts.mirrors())
@CPP_DEFAULT_LIBRARY("hyp-system")
@CPP_PRIMITIVE_PREFIX("hypsystem_datetools")
class DateNative
{
@JNI @IOS public static function fromISO(s:String):Float;
@JNI @IOS public static function getTimezoneOffset():Float;
@JNI @IOS public static function getUTCDate(timestamp:Float):Float;
@JNI @IOS public static function getUTCDay(timestamp:Float):Float;
@JNI @IOS public static function getUTCFullYear(timestamp:Float):Float;
@JNI @IOS public static function getUTCHours(timestamp:Float):Float;
@JNI @IOS public static function getUTCMilliseconds(timestamp:Float):Float;
@JNI @IOS public static function getUTCMinutes(timestamp:Float):Float;
@JNI @IOS public static function getUTCMonth(timestamp:Float):Float;
@JNI @IOS public static function getUTCSeconds(timestamp:Float):Float;
@JNI @IOS public static function toISOString(timestamp:Float, gmt:Bool):String;
@JNI @IOS public static function toUTCString(timestamp:Float):String;
}