Date.hx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright (C)2005-2018 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. package js;
  23. import Date in HaxeDate;
  24. /**
  25. Creates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January 1970 UTC.
  26. **/
  27. @:native("Date")
  28. extern class Date
  29. {
  30. @:overload(function(value:Float):Void {})
  31. @:overload(function(dateString:String):Void {})
  32. @:overload(function(year:Int, month:Int, ?day:Int, ?hours:Int, ?minutes:Int, ?seconds:Int, ?milliseconds:Int):Void {})
  33. function new() : Void;
  34. /**
  35. Cast Haxe's Date to js.Date.
  36. **/
  37. static public inline function fromHaxeDate(date:HaxeDate):js.Date {
  38. return cast date;
  39. }
  40. /**
  41. Cast js.Date to Haxe's Date.
  42. **/
  43. static public inline function toHaxeDate(date:Date):HaxeDate {
  44. return cast date;
  45. }
  46. /**
  47. Returns the numeric value corresponding to the current time - the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC, with leap seconds ignored
  48. **/
  49. static function now() : Float;
  50. /**
  51. Parses a string representation of a date and returns the number of milliseconds since 1 January, 1970, 00:00:00, UTC, with leap seconds ignored.
  52. **/
  53. static function parse( str:String ) : Float;
  54. /**
  55. Returns the number of milliseconds since January 1, 1970, 00:00:00 UTC, with leap seconds ignored.
  56. **/
  57. static function UTC( year:Int, month:Int, ?day:Int, ?hours:Int, ?minutes:Int, ?seconds:Int, ?milliseconds:Int ) : Float;
  58. /**
  59. Returns the day of the month (1-31) for the specified date according to local time.
  60. **/
  61. function getDate() : Int;
  62. /**
  63. Returns the day of the week (0-6) for the specified date according to local time.
  64. **/
  65. function getDay() : Int;
  66. /**
  67. Returns the year (4 digits for 4-digit years) of the specified date according to local time.
  68. **/
  69. function getFullYear() : Int;
  70. /**
  71. Returns the hour (0-23) in the specified date according to local time.
  72. **/
  73. function getHours() : Int;
  74. /**
  75. Returns the milliseconds (0-999) in the specified date according to local time.
  76. **/
  77. function getMilliseconds() : Int;
  78. /**
  79. Returns the minutes (0-59) in the specified date according to local time.
  80. **/
  81. function getMinutes() : Int;
  82. /**
  83. Returns the month (0-11) in the specified date according to local time.
  84. **/
  85. function getMonth() : Int;
  86. /**
  87. Returns the seconds (0-59) in the specified date according to local time.
  88. **/
  89. function getSeconds() : Int;
  90. /**
  91. Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC (negative for prior times).
  92. **/
  93. function getTime() : Float;
  94. /**
  95. Returns the time-zone offset in minutes for the current locale.
  96. **/
  97. function getTimezoneOffset() : Int;
  98. /**
  99. Returns the day (date) of the month (1-31) in the specified date according to universal time.
  100. **/
  101. function getUTCDate() : Int;
  102. /**
  103. Returns the day of the week (0-6) in the specified date according to universal time.
  104. **/
  105. function getUTCDay() : Int;
  106. /**
  107. Returns the year (4 digits for 4-digit years) in the specified date according to universal time.
  108. **/
  109. function getUTCFullYear() : Int;
  110. /**
  111. Returns the hours (0-23) in the specified date according to universal time.
  112. **/
  113. function getUTCHours() : Int;
  114. /**
  115. Returns the milliseconds (0-999) in the specified date according to universal time.
  116. **/
  117. function getUTCMilliseconds() : Int;
  118. /**
  119. Returns the minutes (0-59) in the specified date according to universal time.
  120. **/
  121. function getUTCMinutes() : Int;
  122. /**
  123. Returns the month (0-11) in the specified date according to universal time.
  124. **/
  125. function getUTCMonth() : Int;
  126. /**
  127. Returns the seconds (0-59) in the specified date according to universal time.
  128. **/
  129. function getUTCSeconds() : Int;
  130. /**
  131. Sets the day of the month for a specified date according to local time.
  132. **/
  133. function setDate( value:Int ) : Void;
  134. /**
  135. Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to local time.
  136. **/
  137. function setFullYear( value:Int ) : Void;
  138. /**
  139. Sets the hours for a specified date according to local time.
  140. **/
  141. function setHours( value:Int ) : Void;
  142. /**
  143. Sets the milliseconds for a specified date according to local time.
  144. **/
  145. function setMilliseconds( value:Int ) : Void;
  146. /**
  147. Sets the minutes for a specified date according to local time.
  148. **/
  149. function setMinutes( value:Int ) : Void;
  150. /**
  151. Sets the month for a specified date according to local time.
  152. **/
  153. function setMonth( value:Int ) : Void;
  154. /**
  155. Sets the seconds for a specified date according to local time.
  156. **/
  157. function setSeconds( value:Int ) : Void;
  158. /**
  159. Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC, allowing for negative numbers for times prior.
  160. **/
  161. function setTime( value:Float ) : Void;
  162. /**
  163. Sets the day of the month for a specified date according to universal time.
  164. **/
  165. function setUTCDate( value:Int ) : Void;
  166. /**
  167. Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to universal time.
  168. **/
  169. function setUTCFullYear( value:Int ) : Void;
  170. /**
  171. Sets the hour for a specified date according to universal time.
  172. **/
  173. function setUTCHours( value:Int ) : Void;
  174. /**
  175. Sets the milliseconds for a specified date according to universal time.
  176. **/
  177. function setUTCMilliseconds( value:Int ) : Void;
  178. /**
  179. Sets the minutes for a specified date according to universal time.
  180. **/
  181. function setUTCMinutes( value:Int ) : Void;
  182. /**
  183. Sets the month for a specified date according to universal time.
  184. **/
  185. function setUTCMonth( value:Int ) : Void;
  186. /**
  187. Sets the seconds for a specified date according to universal time.
  188. **/
  189. function setUTCSeconds( value:Int ) : Void;
  190. /**
  191. Returns the "date" portion of the Date as a human-readable string.
  192. **/
  193. function toDateString() : String;
  194. /**
  195. Converts a date to a string following the ISO 8601 Extended Format.
  196. **/
  197. function toISOString() : String;
  198. /**
  199. Returns a string representing the Date using toISOString(). Intended for use by JSON.stringify().
  200. **/
  201. function toJSON() : String;
  202. /**
  203. Returns a string with a locality sensitive representation of the date portion of this date based on system settings.
  204. **/
  205. function toLocaleDateString( ?locales:String, ?options:Dynamic<Dynamic> ) : String;
  206. /**
  207. Converts a date to a string, using a format string.
  208. **/
  209. function toLocaleFormat( format:String ) : String;
  210. /**
  211. Returns a string with a locality sensitive representation of this date. Overrides the Object.prototype.toLocaleString() method.
  212. **/
  213. function toLocaleString( ?locales:String, ?options:Dynamic<Dynamic> ) : String;
  214. /**
  215. Returns a string with a locality sensitive representation of the time portion of this date based on system settings.
  216. **/
  217. function toLocaleTimeString( ?locales:String, ?options:Dynamic<Dynamic> ) : String;
  218. /**
  219. Returns a string representing the source for an equivalent Date object; you can use this value to create a new object. Overrides the Object.prototype.toSource() method.
  220. **/
  221. function toSource() : String;
  222. /**
  223. Returns a string representing the specified Date object. Overrides the Object.prototype.toString() method.
  224. **/
  225. function toString() : String;
  226. /**
  227. Returns the "time" portion of the Date as a human-readable string.
  228. **/
  229. function toTimeString() : String;
  230. /**
  231. Converts a date to a string using the UTC timezone.
  232. **/
  233. function toUTCString() : String;
  234. }