Date.hx 8.5 KB

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