Date.hx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C)2005-2017 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. @:keep public function toString():String {
  67. var outLen = 0;
  68. var bytes = date_to_string(t, outLen);
  69. return @:privateAccess String.__alloc__(bytes,outLen);
  70. }
  71. public static function now() : Date {
  72. var d : Date = untyped $new(Date);
  73. d.t = date_now();
  74. return d;
  75. }
  76. static function fromInt( t : Int ) : Date {
  77. var d : Date = untyped $new(Date);
  78. d.t = t;
  79. return d;
  80. }
  81. public static function fromTime( t : Float ) : Date {
  82. var d : Date = untyped $new(Date);
  83. d.t = date_from_time(t);
  84. return d;
  85. }
  86. public static function fromString( s : String ) : Date {
  87. var d : Date = untyped $new(Date);
  88. d.t = date_from_string(@:privateAccess s.bytes, s.length<<1);
  89. return d;
  90. }
  91. @:hlNative
  92. static function date_new( year : Int, month : Int, day : Int, hours : Int, minutes : Int, seconds : Int ) : Int {
  93. return 0;
  94. }
  95. @:hlNative
  96. static function date_now() : Int {
  97. return 0;
  98. }
  99. @:hlNative
  100. static function date_from_time( t : Float ) : Int {
  101. return 0;
  102. }
  103. @:hlNative
  104. static function date_from_string( b : hl.Bytes, len : Int ) : Int {
  105. return 0;
  106. }
  107. @:hlNative
  108. static function date_get_time( t : Int ) : Float {
  109. return 0.;
  110. }
  111. @:hlNative
  112. 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 {
  113. }
  114. @:hlNative
  115. static function date_to_string( t : Int, outLen : Ref<Int> ) : hl.Bytes {
  116. return null;
  117. }
  118. }