Skip to content

Commit e73a8ba

Browse files
ptomato12wrigja
authored andcommitted
Refactor ToRelativeTemporalObject
Use early returns and combine similar conditions to make the control flow through this operation slightly easier to follow. UPSTREAM_COMMIT=895854d916c2c1548d0d8744e1fccfc412e8e579
1 parent e92fc00 commit e73a8ba

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

lib/ecmascript.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,40 +1116,39 @@ export function ToRelativeTemporalObject(options: {
11161116
let ianaName, z;
11171117
({ year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar, ianaName, offset, z } =
11181118
ParseISODateTime(ToString(relativeTo)));
1119-
if (ianaName) timeZone = ianaName;
1120-
if (z) {
1121-
offsetBehaviour = 'exact';
1122-
} else if (!offset) {
1123-
offsetBehaviour = 'wall';
1119+
if (ianaName) {
1120+
timeZone = ianaName;
1121+
if (z) {
1122+
offsetBehaviour = 'exact';
1123+
} else if (!offset) {
1124+
offsetBehaviour = 'wall';
1125+
}
1126+
matchMinutes = true;
11241127
}
11251128
if (!calendar) calendar = GetISO8601Calendar();
11261129
calendar = ToTemporalCalendar(calendar);
1127-
matchMinutes = true;
11281130
}
1129-
if (timeZone !== undefined) {
1130-
timeZone = ToTemporalTimeZone(timeZone);
1131-
let offsetNs = 0;
1132-
if (offsetBehaviour === 'option') offsetNs = ParseTimeZoneOffsetString(ToString(offset));
1133-
const epochNanoseconds = InterpretISODateTimeOffset(
1134-
year,
1135-
month,
1136-
day,
1137-
hour,
1138-
minute,
1139-
second,
1140-
millisecond,
1141-
microsecond,
1142-
nanosecond,
1143-
offsetBehaviour,
1144-
offsetNs,
1145-
timeZone,
1146-
'compatible',
1147-
'reject',
1148-
matchMinutes
1149-
);
1150-
return CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar);
1151-
}
1152-
return CreateTemporalDate(year, month, day, calendar);
1131+
if (timeZone === undefined) return CreateTemporalDate(year, month, day, calendar);
1132+
timeZone = ToTemporalTimeZone(timeZone);
1133+
const offsetNs = offsetBehaviour === 'option' ? ParseTimeZoneOffsetString(ToString(offset)) : 0;
1134+
const epochNanoseconds = InterpretISODateTimeOffset(
1135+
year,
1136+
month,
1137+
day,
1138+
hour,
1139+
minute,
1140+
second,
1141+
millisecond,
1142+
microsecond,
1143+
nanosecond,
1144+
offsetBehaviour,
1145+
offsetNs,
1146+
timeZone,
1147+
'compatible',
1148+
'reject',
1149+
matchMinutes
1150+
);
1151+
return CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar);
11531152
}
11541153

11551154
export function DefaultTemporalLargestUnit(

0 commit comments

Comments
 (0)