Date.hx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. import hl.Ref;
  23. @:coreApi final class Date {
  24. private var t:Int;
  25. public function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void {
  26. t = date_new(year, month, day, hour, min, sec);
  27. }
  28. public function getTime():Float {
  29. return date_get_time(t);
  30. }
  31. public function getFullYear():Int {
  32. var v = 0;
  33. date_get_inf(t, v, null, null, null, null, null, null);
  34. return v;
  35. }
  36. public function getMonth():Int {
  37. var v = 0;
  38. date_get_inf(t, null, v, null, null, null, null, null);
  39. return v;
  40. }
  41. public function getDate():Int {
  42. var v = 0;
  43. date_get_inf(t, null, null, v, null, null, null, null);
  44. return v;
  45. }
  46. public function getHours():Int {
  47. var v = 0;
  48. date_get_inf(t, null, null, null, v, null, null, null);
  49. return v;
  50. }
  51. public function getMinutes():Int {
  52. var v = 0;
  53. date_get_inf(t, null, null, null, null, v, null, null);
  54. return v;
  55. }
  56. public function getSeconds():Int {
  57. var v = 0;
  58. date_get_inf(t, null, null, null, null, null, v, null);
  59. return v;
  60. }
  61. public function getDay():Int {
  62. var v = 0;
  63. date_get_inf(t, null, null, null, null, null, null, v);
  64. return v;
  65. }
  66. public function getUTCFullYear():Int {
  67. var v = 0;
  68. date_get_utc_inf(t, v, null, null, null, null, null, null);
  69. return v;
  70. }
  71. public function getUTCMonth():Int {
  72. var v = 0;
  73. date_get_utc_inf(t, null, v, null, null, null, null, null);
  74. return v;
  75. }
  76. public function getUTCDate():Int {
  77. var v = 0;
  78. date_get_utc_inf(t, null, null, v, null, null, null, null);
  79. return v;
  80. }
  81. public function getUTCHours():Int {
  82. var v = 0;
  83. date_get_utc_inf(t, null, null, null, v, null, null, null);
  84. return v;
  85. }
  86. public function getUTCMinutes():Int {
  87. var v = 0;
  88. date_get_utc_inf(t, null, null, null, null, v, null, null);
  89. return v;
  90. }
  91. public function getUTCSeconds():Int {
  92. var v = 0;
  93. date_get_utc_inf(t, null, null, null, null, null, v, null);
  94. return v;
  95. }
  96. public function getUTCDay():Int {
  97. var v = 0;
  98. date_get_utc_inf(t, null, null, null, null, null, null, v);
  99. return v;
  100. }
  101. public function getTimezoneOffset():Int {
  102. var y = 0;
  103. var mo = 0;
  104. var d = 0;
  105. var h = 0;
  106. var m = 0;
  107. var s = 0;
  108. date_get_utc_inf(t, y, mo, d, h, m, s, null);
  109. return Std.int((date_new(y, mo, d, h, m, s) - t) / 60);
  110. }
  111. @:keep public function toString():String {
  112. var outLen = 0;
  113. var bytes = date_to_string(t, outLen);
  114. return @:privateAccess String.__alloc__(bytes, outLen);
  115. }
  116. public static function now():Date {
  117. var d:Date = untyped $new(Date);
  118. d.t = date_now();
  119. return d;
  120. }
  121. static function fromInt(t:Int):Date {
  122. var d:Date = untyped $new(Date);
  123. d.t = t;
  124. return d;
  125. }
  126. public static function fromTime(t:Float):Date {
  127. var d:Date = untyped $new(Date);
  128. d.t = date_from_time(t);
  129. return d;
  130. }
  131. public static function fromString(s:String):Date {
  132. var d:Date = untyped $new(Date);
  133. d.t = date_from_string(@:privateAccess s.bytes, s.length << 1);
  134. return d;
  135. }
  136. @:hlNative
  137. static function date_new(year:Int, month:Int, day:Int, hours:Int, minutes:Int, seconds:Int):Int {
  138. return 0;
  139. }
  140. @:hlNative
  141. static function date_now():Int {
  142. return 0;
  143. }
  144. @:hlNative
  145. static function date_from_time(t:Float):Int {
  146. return 0;
  147. }
  148. @:hlNative
  149. static function date_from_string(b:hl.Bytes, len:Int):Int {
  150. return 0;
  151. }
  152. @:hlNative
  153. static function date_get_time(t:Int):Float {
  154. return 0.;
  155. }
  156. @:hlNative
  157. static function date_get_inf(t:Int, year:Ref<Int>, month:Ref<Int>, day:Ref<Int>, hours:Ref<Int>, minutes:Ref<Int>, seconds:Ref<Int>, wday:Ref<Int>):Void {}
  158. @:hlNative(1.11)
  159. static function date_get_utc_inf(t:Int, year:Ref<Int>, month:Ref<Int>, day:Ref<Int>, hours:Ref<Int>, minutes:Ref<Int>, seconds:Ref<Int>, wday:Ref<Int>):Void {}
  160. @:hlNative
  161. static function date_to_string(t:Int, outLen:Ref<Int>):hl.Bytes {
  162. return null;
  163. }
  164. }