-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.hx
More file actions
191 lines (163 loc) · 5.53 KB
/
Date.hx
File metadata and controls
191 lines (163 loc) · 5.53 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package;
extern class Date {
@:nativeFunctionCode("__Date_new__({arg0}, {arg1}, {arg2}, {arg3}, {arg4}, {arg5})")
function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int);
@:nativeFunctionCode("__Date_getFullYear__({this})")
function getFullYear():Int;
@:nativeFunctionCode("__Date_getMonth__({this})")
function getMonth():Int;
@:nativeFunctionCode("__Date_getDate__({this})")
function getDate():Int;
@:nativeFunctionCode("__Date_getDay__({this})")
function getDay():Int;
@:nativeFunctionCode("__Date_getHours__({this})")
function getHours():Int;
@:nativeFunctionCode("__Date_getMinutes__({this})")
function getMinutes():Int;
@:nativeFunctionCode("__Date_getSeconds__({this})")
function getSeconds():Int;
@:nativeFunctionCode("__Date_getTime__({this})")
function getTime():Float;
@:nativeFunctionCode("__Date_getTimezoneOffset__({this})")
function getTimezoneOffset():Int;
@:nativeFunctionCode("__Date_toString__({this})")
function toString():String;
@:nativeFunctionCode("__Date_now__()")
static function now():Date;
@:nativeFunctionCode("__Date_fromTime__({arg0})")
static function fromTime(t:Float):Date;
@:nativeFunctionCode("__Date_fromString__({arg0})")
static function fromString(s:String):Date;
}
@:keep @:brs_global function __Date_new__(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Dynamic {
untyped __brs__('
__y = Int({0})
__mo = Int({1}) + 1
__d = Int({2})
__h = Int({3})
__mi = Int({4})
__se = Int({5})
__iso = Str(__y).Trim() + "-" + Right("0" + Str(__mo).Trim(), 2) + "-" + Right("0" + Str(__d).Trim(), 2) + "T" + Right("0" + Str(__h).Trim(), 2) + ":" + Right("0" + Str(__mi).Trim(), 2) + ":" + Right("0" + Str(__se).Trim(), 2) + "Z"
__dt = CreateObject("roDateTime")
__dt.FromISO8601String(__iso)
__secs = __dt.AsSeconds() + __dt.GetTimeZoneOffset() * 60
', year, month, day, hour, min, sec);
return untyped __brs__('{"s": __secs}');
}
@:keep @:brs_global function __Date_now__():Dynamic {
untyped __brs__('
__dt = CreateObject("roDateTime")
__secs = __dt.AsSeconds()
');
return untyped __brs__('{"s": __secs}');
}
@:keep @:brs_global function __Date_fromTime__(t:Float):Dynamic {
untyped __brs__('__secs = Int({0} / 1000)', t);
return untyped __brs__('{"s": __secs}');
}
@:keep @:brs_global function __Date_fromString__(s:String):Dynamic {
untyped __brs__('
__hasDate = Instr(1, {0}, "-") > 0
__hasTime = Instr(1, {0}, ":") > 0
__secs = 0
if __hasDate and __hasTime then
__parts = {0}.Split(" ")
__iso = __parts[0] + "T" + __parts[1] + "Z"
__dt = CreateObject("roDateTime")
__dt.FromISO8601String(__iso)
__secs = __dt.AsSeconds() + __dt.GetTimeZoneOffset() * 60
else if __hasDate then
__iso = {0} + "T00:00:00Z"
__dt = CreateObject("roDateTime")
__dt.FromISO8601String(__iso)
__secs = __dt.AsSeconds() + __dt.GetTimeZoneOffset() * 60
else
__iso = "1970-01-01T" + {0} + "Z"
__dt = CreateObject("roDateTime")
__dt.FromISO8601String(__iso)
__secs = __dt.AsSeconds()
end if
', s);
return untyped __brs__('{"s": __secs}');
}
@:keep @:brs_global function __Date_getFullYear__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
', self);
return untyped __brs__('__dt.GetYear()');
}
@:keep @:brs_global function __Date_getMonth__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
', self);
return untyped __brs__('__dt.GetMonth() - 1');
}
@:keep @:brs_global function __Date_getDate__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
', self);
return untyped __brs__('__dt.GetDayOfMonth()');
}
@:keep @:brs_global function __Date_getDay__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
', self);
return untyped __brs__('__dt.GetDayOfWeek()');
}
@:keep @:brs_global function __Date_getHours__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
', self);
return untyped __brs__('__dt.GetHours()');
}
@:keep @:brs_global function __Date_getMinutes__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
', self);
return untyped __brs__('__dt.GetMinutes()');
}
@:keep @:brs_global function __Date_getSeconds__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
', self);
return untyped __brs__('__dt.GetSeconds()');
}
@:keep @:brs_global function __Date_getTimezoneOffset__(self:Dynamic):Int {
untyped __brs__('
__dt = CreateObject("roDateTime")
');
return untyped __brs__('__dt.GetTimeZoneOffset()');
}
@:keep @:brs_global function __Date_toString__(self:Dynamic):String {
untyped __brs__('
__dt = CreateObject("roDateTime")
__dt.FromSeconds({0}.s)
__dt.ToLocalTime()
__y = Str(__dt.GetYear()).Trim()
__mo = Right("0" + Str(__dt.GetMonth()).Trim(), 2)
__d = Right("0" + Str(__dt.GetDayOfMonth()).Trim(), 2)
__h = Right("0" + Str(__dt.GetHours()).Trim(), 2)
__mi = Right("0" + Str(__dt.GetMinutes()).Trim(), 2)
__se = Right("0" + Str(__dt.GetSeconds()).Trim(), 2)
__result = __y + "-" + __mo + "-" + __d + " " + __h + ":" + __mi + ":" + __se
', self);
return untyped __brs__('__result');
}
@:keep @:brs_global function __Date_getTime__(self:Dynamic):Float {
untyped __brs__('__ms = {0}.s * 1000.0', self);
return untyped __brs__('__ms');
}