2
0

Date.hx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /**
  23. The Date class provides a basic structure for date and time related
  24. information. Date instances can be created by
  25. - `new Date()` for a specific date,
  26. - `Date.now()` to obtain information about the current time,
  27. - `Date.fromTime()` with a given timestamp or
  28. - `Date.fromString()` by parsing from a String.
  29. There are some extra functions available in the `DateTools` class.
  30. In the context of Haxe dates, a timestamp is defined as the number of
  31. milliseconds elapsed since 1st January 1970 UTC.
  32. ## Supported range
  33. Due to platform limitations, only dates in the range 1970 through 2038 are
  34. supported consistently. Some targets may support dates outside this range,
  35. depending on the OS at runtime. The `Date.fromTime` method will not work with
  36. timestamps outside the range on any target.
  37. **/
  38. extern class Date {
  39. /**
  40. Creates a new date object from the given arguments.
  41. The behaviour of a Date instance is only consistent across platforms if
  42. the the arguments describe a valid date.
  43. - month: 0 to 11 (note that this is zero-based)
  44. - day: 1 to 31
  45. - hour: 0 to 23
  46. - min: 0 to 59
  47. - sec: 0 to 59
  48. **/
  49. function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void;
  50. /**
  51. Returns the timestamp (in milliseconds) of `this` date.
  52. On cpp and neko, this function only has a second resolution, so the
  53. result will always be a multiple of `1000.0`, e.g. `1454698271000.0`.
  54. To obtain the current timestamp with better precision on cpp and neko,
  55. see the `Sys.time` API.
  56. For measuring time differences with millisecond accuracy on
  57. all platforms, see `haxe.Timer.stamp`.
  58. **/
  59. function getTime():Float;
  60. /**
  61. Returns the hours of `this` Date (0-23 range) in the local timezone.
  62. **/
  63. function getHours():Int;
  64. /**
  65. Returns the minutes of `this` Date (0-59 range) in the local timezone.
  66. **/
  67. function getMinutes():Int;
  68. /**
  69. Returns the seconds of `this` Date (0-59 range) in the local timezone.
  70. **/
  71. function getSeconds():Int;
  72. /**
  73. Returns the full year of `this` Date (4 digits) in the local timezone.
  74. **/
  75. function getFullYear():Int;
  76. /**
  77. Returns the month of `this` Date (0-11 range) in the local timezone.
  78. Note that the month number is zero-based.
  79. **/
  80. function getMonth():Int;
  81. /**
  82. Returns the day of `this` Date (1-31 range) in the local timezone.
  83. **/
  84. function getDate():Int;
  85. /**
  86. Returns the day of the week of `this` Date (0-6 range, where `0` is Sunday)
  87. in the local timezone.
  88. **/
  89. function getDay():Int;
  90. /**
  91. Returns the hours of `this` Date (0-23 range) in UTC.
  92. **/
  93. function getUTCHours():Int;
  94. /**
  95. Returns the minutes of `this` Date (0-59 range) in UTC.
  96. **/
  97. function getUTCMinutes():Int;
  98. /**
  99. Returns the seconds of `this` Date (0-59 range) in UTC.
  100. **/
  101. function getUTCSeconds():Int;
  102. /**
  103. Returns the full year of `this` Date (4 digits) in UTC.
  104. **/
  105. function getUTCFullYear():Int;
  106. /**
  107. Returns the month of `this` Date (0-11 range) in UTC.
  108. Note that the month number is zero-based.
  109. **/
  110. function getUTCMonth():Int;
  111. /**
  112. Returns the day of `this` Date (1-31 range) in UTC.
  113. **/
  114. function getUTCDate():Int;
  115. /**
  116. Returns the day of the week of `this` Date (0-6 range, where `0` is Sunday)
  117. in UTC.
  118. **/
  119. function getUTCDay():Int;
  120. /**
  121. Returns the time zone difference of `this` Date in the current locale
  122. to UTC, in minutes.
  123. Assuming the function is executed on a machine in a UTC+2 timezone,
  124. `Date.now().getTimezoneOffset()` will return `-120`.
  125. **/
  126. function getTimezoneOffset():Int;
  127. /**
  128. Returns a string representation of `this` Date in the local timezone
  129. using the standard format `YYYY-MM-DD HH:MM:SS`. See `DateTools.format` for
  130. other formatting rules.
  131. **/
  132. function toString():String;
  133. /**
  134. Returns a Date representing the current local time.
  135. **/
  136. static function now():Date;
  137. /**
  138. Creates a Date from the timestamp (in milliseconds) `t`.
  139. **/
  140. static function fromTime(t:Float):Date;
  141. /**
  142. Creates a Date from the formatted string `s`. The following formats are
  143. accepted by the function:
  144. - `"YYYY-MM-DD hh:mm:ss"`
  145. - `"YYYY-MM-DD"`
  146. - `"hh:mm:ss"`
  147. The first two formats expressed a date in local time. The third is a time
  148. relative to the UTC epoch.
  149. **/
  150. static function fromString(s:String):Date;
  151. }