|
87 | 87 | import com.oracle.truffle.js.runtime.JSContext; |
88 | 88 | import com.oracle.truffle.js.runtime.JSRealm; |
89 | 89 | import com.oracle.truffle.js.runtime.JSRuntime; |
| 90 | +import com.oracle.truffle.js.runtime.Strings; |
90 | 91 | import com.oracle.truffle.js.runtime.builtins.BuiltinEnum; |
91 | 92 | import com.oracle.truffle.js.runtime.builtins.JSDate; |
92 | 93 | import com.oracle.truffle.js.runtime.builtins.temporal.ISODateTimeRecord; |
|
104 | 105 | import com.oracle.truffle.js.runtime.builtins.temporal.NormalizedDurationRecord; |
105 | 106 | import com.oracle.truffle.js.runtime.objects.JSDynamicObject; |
106 | 107 | import com.oracle.truffle.js.runtime.objects.Undefined; |
| 108 | +import com.oracle.truffle.js.runtime.util.IntlUtil; |
107 | 109 | import com.oracle.truffle.js.runtime.util.TemporalConstants; |
108 | 110 | import com.oracle.truffle.js.runtime.util.TemporalErrors; |
109 | 111 | import com.oracle.truffle.js.runtime.util.TemporalUtil; |
110 | 112 | import com.oracle.truffle.js.runtime.util.TemporalUtil.Disambiguation; |
111 | 113 | import com.oracle.truffle.js.runtime.util.TemporalUtil.ShowCalendar; |
112 | 114 | import com.oracle.truffle.js.runtime.util.TemporalUtil.Unit; |
| 115 | +import org.graalvm.shadowed.com.ibm.icu.util.Calendar; |
113 | 116 |
|
114 | 117 | public class TemporalPlainDatePrototypeBuiltins extends JSBuiltinsContainer.SwitchEnum<TemporalPlainDatePrototypeBuiltins.TemporalPlainDatePrototype> { |
115 | 118 |
|
@@ -256,38 +259,46 @@ protected JSTemporalPlainDateGetterNode(JSContext context, JSBuiltin builtin, Te |
256 | 259 | } |
257 | 260 |
|
258 | 261 | @Specialization |
259 | | - 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 | + } |
260 | 271 | switch (property) { |
261 | 272 | case era: |
262 | 273 | return Undefined.instance; |
263 | 274 | case eraYear: |
264 | 275 | return Undefined.instance; |
265 | 276 | case year: |
266 | | - return temporalDT.getYear(); |
| 277 | + return isoCalendar ? temporalDT.getYear() : IntlUtil.getCalendarField(cal, Calendar.YEAR); |
267 | 278 | case month: |
268 | | - return temporalDT.getMonth(); |
| 279 | + return isoCalendar ? temporalDT.getMonth() : (IntlUtil.getCalendarField(cal, Calendar.MONTH) + 1); |
269 | 280 | case day: |
270 | | - return temporalDT.getDay(); |
| 281 | + return isoCalendar ? temporalDT.getDay() : IntlUtil.getCalendarField(cal, Calendar.DAY_OF_MONTH); |
271 | 282 | case dayOfWeek: |
272 | | - 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); |
273 | 284 | case dayOfYear: |
274 | | - 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); |
275 | 286 | case monthCode: |
276 | | - return TemporalUtil.buildISOMonthCode(temporalDT.getMonth()); |
| 287 | + return isoCalendar ? TemporalUtil.buildISOMonthCode(temporalDT.getMonth()) : Strings.fromJavaString(IntlUtil.getTemporalMonthCode(cal)); |
277 | 288 | case weekOfYear: |
278 | | - return TemporalUtil.weekOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()); |
| 289 | + return isoCalendar ? TemporalUtil.weekOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()) : Undefined.instance; |
279 | 290 | case yearOfWeek: |
280 | | - return TemporalUtil.yearOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()); |
| 291 | + return isoCalendar ? TemporalUtil.yearOfToISOWeekOfYear(temporalDT.getYear(), temporalDT.getMonth(), temporalDT.getDay()) : Undefined.instance; |
281 | 292 | case daysInWeek: |
282 | | - return 7; |
| 293 | + return isoCalendar ? 7 : IntlUtil.getCalendarFieldMax(cal, Calendar.DAY_OF_WEEK); |
283 | 294 | case daysInMonth: |
284 | | - return TemporalUtil.isoDaysInMonth(temporalDT.getYear(), temporalDT.getMonth()); |
| 295 | + return isoCalendar ? TemporalUtil.isoDaysInMonth(temporalDT.getYear(), temporalDT.getMonth()) : IntlUtil.getCalendarFieldMax(cal, Calendar.DAY_OF_MONTH); |
285 | 296 | case daysInYear: |
286 | | - return TemporalUtil.isoDaysInYear(temporalDT.getYear()); |
| 297 | + return isoCalendar ? TemporalUtil.isoDaysInYear(temporalDT.getYear()) : IntlUtil.getCalendarFieldMax(cal, Calendar.DAY_OF_YEAR); |
287 | 298 | case monthsInYear: |
288 | | - return 12; |
| 299 | + return isoCalendar ? 12 : (IntlUtil.getCalendarFieldMax(cal, Calendar.MONTH) + 1); |
289 | 300 | case inLeapYear: |
290 | | - return JSDate.isLeapYear(temporalDT.getYear()); |
| 301 | + return isoCalendar ? JSDate.isLeapYear(temporalDT.getYear()) : IntlUtil.isLeapYear(cal); |
291 | 302 | } |
292 | 303 | throw Errors.shouldNotReachHere(); |
293 | 304 | } |
|
0 commit comments