@@ -12,7 +12,7 @@ extension type JSDate._(JSObject _) implements JSObject {
1212 /// The [Date constructor] that returns the current date and time.
1313 ///
1414 /// [Date constructor] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
15- external JSDate .now ();
15+ external JSDate .nowAsDate ();
1616
1717 /// The [Date constructor] with the number of milliseconds since the epoch of
1818 /// January 1, 1970, UTC.
@@ -24,20 +24,74 @@ extension type JSDate._(JSObject _) implements JSObject {
2424 ///
2525 /// [Date constructor] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
2626 /// [from a string] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#date_string
27- external JSDate .parse (String dateString);
27+ external JSDate .parseAsDate (String dateString);
2828
2929 /// The [Date constructor] that copies its value [from an existing Date] .
3030 ///
3131 /// [Date constructor] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
3232 /// [from an existing Date] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#date_object
3333 external JSDate .from (JSDate other);
3434
35- /// The [Date constructor] that uses [individual component integers] .
35+ /// The [Date constructor] that uses [individual component integers] ,
36+ /// interpreted in the local time zone.
3637 ///
3738 /// [Date constructor] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
3839 /// [individual component integers] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#individual_date_and_time_component_values
39- external JSDate (int year, int month,
40- [int ? day, int ? hours, int ? minutes, int ? seconds, int ? milliseconds]);
40+ external JSDate .localDate (
41+ int year,
42+ int month, [
43+ int ? day,
44+ int ? hours,
45+ int ? minutes,
46+ int ? seconds,
47+ int ? milliseconds,
48+ ]);
49+
50+ /// The [Date constructor] that uses [individual component integers] ,
51+ /// interpreted in the UTC time zone.
52+ ///
53+ /// [Date constructor] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
54+ /// [individual component integers] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#individual_date_and_time_component_values
55+ factory JSDate .utcDate (
56+ int year,
57+ int month, [
58+ int ? day,
59+ int ? hours,
60+ int ? minutes,
61+ int ? seconds,
62+ int ? milliseconds,
63+ ]) {
64+ var ms = switch ((day, hours, minutes, seconds, milliseconds)) {
65+ (_, _, _, _, var milliseconds? ) => JSDate .utcAsMillisecondsSinceEpoch (
66+ year,
67+ month,
68+ day,
69+ hours,
70+ minutes,
71+ seconds,
72+ milliseconds,
73+ ),
74+ (_, _, _, var seconds? , _) => JSDate .utcAsMillisecondsSinceEpoch (
75+ year,
76+ month,
77+ day,
78+ hours,
79+ minutes,
80+ seconds,
81+ ),
82+ (_, _, var minutes? , _, _) => JSDate .utcAsMillisecondsSinceEpoch (
83+ year,
84+ month,
85+ day,
86+ hours,
87+ minutes,
88+ ),
89+ (_, var hours? , _, _, _) => JSDate .utcAsMillisecondsSinceEpoch (year, month, day, hours),
90+ (var day? , _, _, _, _) => JSDate .utcAsMillisecondsSinceEpoch (year, month, day),
91+ _ => JSDate .utcAsMillisecondsSinceEpoch (year, month),
92+ };
93+ return JSDate .fromMillisecondsSinceEpoch (ms);
94+ }
4195
4296 /// Dee [`Date.now()`] .
4397 ///
@@ -55,13 +109,15 @@ extension type JSDate._(JSObject _) implements JSObject {
55109 ///
56110 /// [`Date.utc()`] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC
57111 @JS ('UTC' )
58- external static int utc (int year,
59- [int ? month,
60- int ? day,
61- int ? hours,
62- int ? minutes,
63- int ? seconds,
64- int ? milliseconds]);
112+ external static int utcAsMillisecondsSinceEpoch (
113+ int year, [
114+ int ? month,
115+ int ? day,
116+ int ? hours,
117+ int ? minutes,
118+ int ? seconds,
119+ int ? milliseconds,
120+ ]);
65121
66122 /// See [`Date.getDate()`] and [`Date.setDate()`] .
67123 ///
@@ -81,14 +137,10 @@ extension type JSDate._(JSObject _) implements JSObject {
81137 /// [`Date.getDay()`] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay
82138 /// [`Date.setDay()`] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDay
83139 int get day => _getDay ();
84- set day (int value) => _setDay (value);
85140
86141 @JS ('getDay' )
87142 external int _getDay ();
88143
89- @JS ('setDay' )
90- external void _setDay (int value);
91-
92144 /// See [`Date.getFullYear()`] and [`Date.setFullYear()`] .
93145 ///
94146 /// [`Date.getFullYear()`] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear
0 commit comments