|
78 | 78 | import com.oracle.truffle.js.nodes.temporal.TemporalMonthDayFromFieldsNode; |
79 | 79 | import com.oracle.truffle.js.nodes.temporal.TemporalYearMonthFromFieldsNode; |
80 | 80 | import com.oracle.truffle.js.nodes.temporal.ToTemporalCalendarIdentifierNode; |
81 | | -import com.oracle.truffle.js.nodes.temporal.ToTemporalCalendarSlotValueNode; |
82 | 81 | import com.oracle.truffle.js.nodes.temporal.ToTemporalDateNode; |
83 | 82 | import com.oracle.truffle.js.nodes.temporal.ToTemporalDurationNode; |
84 | 83 | import com.oracle.truffle.js.nodes.temporal.ToTemporalTimeNode; |
|
88 | 87 | import com.oracle.truffle.js.runtime.JSContext; |
89 | 88 | import com.oracle.truffle.js.runtime.JSRealm; |
90 | 89 | import com.oracle.truffle.js.runtime.JSRuntime; |
| 90 | +import com.oracle.truffle.js.runtime.Strings; |
91 | 91 | import com.oracle.truffle.js.runtime.builtins.BuiltinEnum; |
92 | 92 | import com.oracle.truffle.js.runtime.builtins.JSDate; |
93 | 93 | import com.oracle.truffle.js.runtime.builtins.temporal.ISODateTimeRecord; |
|
105 | 105 | import com.oracle.truffle.js.runtime.builtins.temporal.NormalizedDurationRecord; |
106 | 106 | import com.oracle.truffle.js.runtime.objects.JSDynamicObject; |
107 | 107 | import com.oracle.truffle.js.runtime.objects.Undefined; |
| 108 | +import com.oracle.truffle.js.runtime.util.IntlUtil; |
108 | 109 | import com.oracle.truffle.js.runtime.util.TemporalConstants; |
109 | 110 | import com.oracle.truffle.js.runtime.util.TemporalErrors; |
110 | 111 | import com.oracle.truffle.js.runtime.util.TemporalUtil; |
111 | 112 | import com.oracle.truffle.js.runtime.util.TemporalUtil.Disambiguation; |
112 | 113 | import com.oracle.truffle.js.runtime.util.TemporalUtil.ShowCalendar; |
113 | 114 | import com.oracle.truffle.js.runtime.util.TemporalUtil.Unit; |
| 115 | +import org.graalvm.shadowed.com.ibm.icu.util.Calendar; |
114 | 116 |
|
115 | 117 | public class TemporalPlainDatePrototypeBuiltins extends JSBuiltinsContainer.SwitchEnum<TemporalPlainDatePrototypeBuiltins.TemporalPlainDatePrototype> { |
116 | 118 |
|
@@ -257,38 +259,46 @@ protected JSTemporalPlainDateGetterNode(JSContext context, JSBuiltin builtin, Te |
257 | 259 | } |
258 | 260 |
|
259 | 261 | @Specialization |
260 | | - protected final Object dateGetter(JSTemporalPlainDateObject temporalDT) { |
| 262 | + protected final Object dateGetter(JSTemporalPlainDateObject temporalDT, |
| 263 | + @Cached TruffleString.EqualNode equalNode, |
| 264 | + @Cached InlinedConditionProfile isoCalendarProfile) { |
| 265 | + TruffleString calendar = temporalDT.getCalendar(); |
| 266 | + boolean isoCalendar = isoCalendarProfile.profile(this, Strings.equals(equalNode, TemporalConstants.ISO8601, calendar)); |
| 267 | + Calendar cal = null; |
| 268 | + if (!isoCalendar) { |
| 269 | + cal = IntlUtil.getCalendar(calendar, temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()); |
| 270 | + } |
261 | 271 | switch (property) { |
262 | 272 | case era: |
263 | 273 | return Undefined.instance; |
264 | 274 | case eraYear: |
265 | 275 | return Undefined.instance; |
266 | 276 | case year: |
267 | | - return temporalDT.getYear(); |
| 277 | + return isoCalendar ? temporalDT.getYear() : IntlUtil.getCalendarField(cal, Calendar.YEAR); |
268 | 278 | case month: |
269 | | - return temporalDT.getMonth(); |
| 279 | + return isoCalendar ? temporalDT.getMonth() : (IntlUtil.getCalendarField(cal, Calendar.MONTH) + 1); |
270 | 280 | case day: |
271 | | - return temporalDT.getDay(); |
| 281 | + return isoCalendar ? temporalDT.getDay() : IntlUtil.getCalendarField(cal, Calendar.DAY_OF_MONTH); |
272 | 282 | case dayOfWeek: |
273 | | - return TemporalUtil.toISODayOfWeek(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()); |
| 283 | + return isoCalendar ? TemporalUtil.toISODayOfWeek(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()) : IntlUtil.getCalendarField(cal, Calendar.DAY_OF_WEEK); |
274 | 284 | case dayOfYear: |
275 | | - return TemporalUtil.toISODayOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()); |
| 285 | + return isoCalendar ? TemporalUtil.toISODayOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()) : IntlUtil.getCalendarField(cal, Calendar.DAY_OF_YEAR); |
276 | 286 | case monthCode: |
277 | | - return TemporalUtil.buildISOMonthCode(temporalDT.getMonth()); |
| 287 | + return isoCalendar ? TemporalUtil.buildISOMonthCode(temporalDT.getMonth()) : Strings.fromJavaString(IntlUtil.getTemporalMonthCode(cal)); |
278 | 288 | case weekOfYear: |
279 | | - return TemporalUtil.weekOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()); |
| 289 | + return isoCalendar ? TemporalUtil.weekOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()) : Undefined.instance; |
280 | 290 | case yearOfWeek: |
281 | | - return TemporalUtil.yearOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()); |
| 291 | + return isoCalendar ? TemporalUtil.yearOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()) : Undefined.instance; |
282 | 292 | case daysInWeek: |
283 | | - return 7; |
| 293 | + return isoCalendar ? 7 : IntlUtil.getCalendarFieldMax(cal, Calendar.DAY_OF_WEEK); |
284 | 294 | case daysInMonth: |
285 | | - return TemporalUtil.isoDaysInMonth(temporalDT.getYear(), temporalDT.getMonth()); |
| 295 | + return isoCalendar ? TemporalUtil.isoDaysInMonth(temporalDT.getYear(), temporalDT.getMonth()) : IntlUtil.getCalendarFieldMax(cal, Calendar.DAY_OF_MONTH); |
286 | 296 | case daysInYear: |
287 | | - return TemporalUtil.isoDaysInYear(temporalDT.getYear()); |
| 297 | + return isoCalendar ? TemporalUtil.isoDaysInYear(temporalDT.getYear()) : IntlUtil.getCalendarFieldMax(cal, Calendar.DAY_OF_YEAR); |
288 | 298 | case monthsInYear: |
289 | | - return 12; |
| 299 | + return isoCalendar ? 12 : (IntlUtil.getCalendarFieldMax(cal, Calendar.MONTH) + 1); |
290 | 300 | case inLeapYear: |
291 | | - return JSDate.isLeapYear(temporalDT.getYear()); |
| 301 | + return isoCalendar ? JSDate.isLeapYear(temporalDT.getYear()) : IntlUtil.isLeapYear(cal); |
292 | 302 | } |
293 | 303 | throw Errors.shouldNotReachHere(); |
294 | 304 | } |
@@ -380,10 +390,10 @@ protected JSTemporalPlainDateWithCalendar(JSContext context, JSBuiltin builtin) |
380 | 390 | } |
381 | 391 |
|
382 | 392 | @Specialization |
383 | | - protected final JSTemporalPlainDateObject withCalendar(JSTemporalPlainDateObject date, Object calendarParam, |
384 | | - @Cached ToTemporalCalendarSlotValueNode toCalendarSlotValue, |
| 393 | + protected final JSTemporalPlainDateObject withCalendar(JSTemporalPlainDateObject date, Object calendarLike, |
| 394 | + @Cached ToTemporalCalendarIdentifierNode toCalendarIdentifier, |
385 | 395 | @Cached InlinedBranchProfile errorBranch) { |
386 | | - TruffleString calendar = toCalendarSlotValue.execute(calendarParam); |
| 396 | + TruffleString calendar = toCalendarIdentifier.executeString(calendarLike); |
387 | 397 | return JSTemporalPlainDate.create(getContext(), getRealm(), date.getYear(), date.getMonth(), date.getDay(), calendar, this, errorBranch); |
388 | 398 | } |
389 | 399 |
|
|
0 commit comments