Skip to content

Commit

Permalink
Deploying to gh-pages from @ 6b3ca82 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Nov 11, 2024
1 parent 03d0e15 commit 21fe944
Show file tree
Hide file tree
Showing 5 changed files with 687 additions and 700 deletions.
4 changes: 2 additions & 2 deletions docs/cookbook.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ <h2 id="converting-between-temporal-types-and-legacy-date"><a class="heading-lin
assert<span class="token punctuation">.</span><span class="token function">equal</span><span class="token punctuation">(</span>instant<span class="token punctuation">.</span>epochMilliseconds<span class="token punctuation">,</span> legacyDate<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
assert<span class="token punctuation">.</span><span class="token function">equal</span><span class="token punctuation">(</span>instant<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'1970-01-01T00:00:01Z'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// If you need a ZonedDateTime, use the toZonedDateTime() or</span>
<span class="token comment">// toZonedDateTimeISO() method of the resulting Instant.</span>
<span class="token comment">// If you need a ZonedDateTime, use the toZonedDateTimeISO()</span>
<span class="token comment">// method of the resulting Instant.</span>
<span class="token comment">// You will need to specify a time zone, because legacy Date only</span>
<span class="token comment">// stores an exact time, and does not store a time zone.</span>

Expand Down
63 changes: 28 additions & 35 deletions docs/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -10669,6 +10669,12 @@
}
}

// Same as above, but throws a different, non-user-facing error
function AssertISODateTimeWithinLimits(isoDateTime) {
const ns = GetUTCEpochNanoseconds(isoDateTime);
assert(ns.geq(DATETIME_NS_MIN) && ns.leq(DATETIME_NS_MAX), `${ISODateTimeToString(isoDateTime)} is outside the representable range`);
}

// In the spec, IsValidEpochNanoseconds returns a boolean and call sites are
// responsible for throwing. In the polyfill, ValidateEpochNanoseconds takes its
// place so that we can DRY the throwing code.
Expand Down Expand Up @@ -10887,6 +10893,8 @@
return CombineDateAndTimeDuration(ZeroDateDuration(), timeDuration);
}
function DifferenceISODateTime(isoDateTime1, isoDateTime2, calendar, largestUnit) {
AssertISODateTimeWithinLimits(isoDateTime1);
AssertISODateTimeWithinLimits(isoDateTime2);
let timeDuration = DifferenceTime(isoDateTime1.time, isoDateTime2.time);
const timeSign = timeDuration.sign();
const dateSign = CompareISODate(isoDateTime2.isoDate, isoDateTime1.isoDate);
Expand Down Expand Up @@ -11141,23 +11149,23 @@
const timeDuration = duration.time.add24HourDays(duration.date.days);
// Convert to nanoseconds and round
const unitLength = Call$1(MapPrototypeGet, NS_PER_TIME_UNIT, [smallestUnit]);
const roundedNorm = timeDuration.round(increment * unitLength, roundingMode);
const diffNorm = roundedNorm.subtract(timeDuration);
const roundedTime = timeDuration.round(increment * unitLength, roundingMode);
const diffTime = roundedTime.subtract(timeDuration);

// Determine if whole days expanded
const {
quotient: wholeDays
} = timeDuration.divmod(DAY_NANOS);
const {
quotient: roundedWholeDays
} = roundedNorm.divmod(DAY_NANOS);
} = roundedTime.divmod(DAY_NANOS);
const didExpandDays = MathSign(roundedWholeDays - wholeDays) === timeDuration.sign();
const nudgedEpochNs = diffNorm.addToEpochNs(destEpochNs);
const nudgedEpochNs = diffTime.addToEpochNs(destEpochNs);
let days = 0;
let remainder = roundedNorm;
let remainder = roundedTime;
if (TemporalUnitCategory(largestUnit) === 'date') {
days = roundedWholeDays;
remainder = roundedNorm.add(TimeDuration.fromComponents(-roundedWholeDays * 24, 0, 0, 0, 0, 0));
remainder = roundedTime.add(TimeDuration.fromComponents(-roundedWholeDays * 24, 0, 0, 0, 0, 0));
}
const dateDuration = AdjustDateDurationRecord(duration.date, days);
return {
Expand Down Expand Up @@ -11695,42 +11703,26 @@
const incrementNs = Call$1(MapPrototypeGet, NS_PER_TIME_UNIT, [unit]) * increment;
return RoundNumberToIncrementAsIfPositive(epochNs, incrementNs, roundingMode);
}
function RoundISODateTime(_ref10, increment, unit, roundingMode) {
let {
isoDate: {
year,
month,
day
},
time: {
hour,
minute,
second,
millisecond,
microsecond,
nanosecond
}
} = _ref10;
const time = RoundTime({
hour,
minute,
second,
millisecond,
microsecond,
nanosecond
}, increment, unit, roundingMode);
function RoundISODateTime(isoDateTime, increment, unit, roundingMode) {
AssertISODateTimeWithinLimits(isoDateTime);
const {
year,
month,
day
} = isoDateTime.isoDate;
const time = RoundTime(isoDateTime.time, increment, unit, roundingMode);
const isoDate = BalanceISODate(year, month, day + time.deltaDays);
return CombineISODateAndTimeRecord(isoDate, time);
}
function RoundTime(_ref11, increment, unit, roundingMode) {
function RoundTime(_ref10, increment, unit, roundingMode) {
let {
hour,
minute,
second,
millisecond,
microsecond,
nanosecond
} = _ref11;
} = _ref10;
let quantity;
switch (unit) {
case 'day':
Expand Down Expand Up @@ -16034,7 +16026,7 @@
quotient,
remainder
} = internalDuration.time.divmod(DAY_NANOS);
let days = internalDuration.date.days + quotient + remainder.fdiv(DAY_NANOS);
let days = internalDuration.date.days + quotient + TotalTimeDuration(remainder, 'day');
days = RoundNumberToIncrement(days, roundingIncrement, roundingMode);
const dateDuration = {
years: 0,
Expand Down Expand Up @@ -16788,7 +16780,7 @@
const todayNs = GetStartOfDay(timeZone, today);
const tomorrowNs = GetStartOfDay(timeZone, tomorrow);
const diff = TimeDuration.fromEpochNsDiff(tomorrowNs, todayNs);
return diff.fdiv(3.6e12);
return TotalTimeDuration(diff, 'hour');
}
get daysInWeek() {
if (!IsTemporalZonedDateTime(this)) throw new TypeError$1('invalid receiver');
Expand Down Expand Up @@ -16949,7 +16941,8 @@
assert(thisNs.lt(endNs), 'cannot produce an instant during a day that occurs on or after end-of-day instant');
const dayLengthNs = endNs.subtract(startNs);
const dayProgressNs = TimeDuration.fromEpochNsDiff(thisNs, startNs);
epochNanoseconds = dayProgressNs.round(dayLengthNs, roundingMode).add(new TimeDuration(startNs)).totalNs;
const roundedDayNs = dayProgressNs.round(dayLengthNs, roundingMode);
epochNanoseconds = roundedDayNs.addToEpochNs(startNs);
} else {
// smallestUnit < day
// Round based on ISO-calendar time units
Expand Down
2 changes: 1 addition & 1 deletion docs/playground.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/strings.html
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ <h4 id="why-is-a-bracketed-time-zone-annotation-required-to-parse-a-string-into-
If timezone-aware results are not needed, then use another type like <code>Temporal.Instant</code>.</p>
<h4 id="how-can-i-parse-the-offset-of-timestamp-strings-like-2022-02-28t0306000200-or-2022-02-28t030600z"><a class="heading-link" href="#how-can-i-parse-the-offset-of-timestamp-strings-like-2022-02-28t0306000200-or-2022-02-28t030600z"></a>How can I parse the offset of timestamp strings like <code>2022-02-28T03:06:00+02:00</code> or <code>2022-02-28T03:06:00Z</code>?</h3><p>Timestamp strings like <code>2022-02-28T03:06:00+02:00</code> or <code>2022-02-28T03:06:00Z</code> are normally parsed by <code>Temporal.Instant</code>.
Because the data model of <code>Temporal.Instant</code> is limited to the number of nanoseconds since January 1, 1970 UTC), the offset is not stored when parsing a string into a <code>Temporal.Instant</code>.
If the offset of the string is needed, use <code>Temporal.Instant.toZonedDateTime()</code> with the string as the time zone:</p>
If the offset of the string is needed, use <code>Temporal.Instant.toZonedDateTimeISO()</code> with the string as the time zone:</p>
<pre class="language-javascript"><code class="language-javascript">s <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">2022-02-28T03:06:00Z</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>
offset <span class="token operator">=</span> Temporal<span class="token punctuation">.</span>Instant<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toZonedDateTimeISO</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">.</span>timeZoneId<span class="token punctuation">;</span> <span class="token comment">// => UTC</span>

Expand Down
1,316 changes: 655 additions & 661 deletions index.html

Large diffs are not rendered by default.

0 comments on commit 21fe944

Please sign in to comment.