## `Intl.DurationFormat` ⏲ ## Stage 3 Update #### Ujjwal Sharma (@ryzokuken) from Igalia --- ## Act I: The bug πŸ› --- ![Frank's issue](https://i.imgur.com/CePdkpU.png) --- ``` 1.4.3 Intl.DurationFormat.prototype.format ( duration ) ... 3. Let record be ? ToPartialDuration(duration). 4. Let formatted be ? PartitionDurationFormatPattern(df, record). ``` --- ### `ToPartialDuration` * Accepts: A "duration-like" (options bag, but could also be a `Duration` instance). * Returns: A Partial Duration Record (Duration Record but with undefined). * The rest of the code assumed no undefined fields, so we clearly needed a Duration Record instead. This was a bug. --- ## Act II: The bugfix πŸ›  --- ```diff diff --git a/spec.emu b/spec.emu index 40ccd8f..63b1749 100644 --- a/spec.emu +++ b/spec.emu @@ -323,7 +323,7 @@ contributors: Ujjwal Sharma, Younies Mahmoud <emu-alg> 1. Let _df_ be *this* value. 1. Perform ? RequireInternalSlot(_df_, [[InitializedDurationFormat]]). - 1. Let _record_ be ? ToPartialDuration(_duration_). + 1. Let _record_ be ? ToTemporalDurationRecord(_duration_). 1. Let _formatted_ be ? PartitionDurationFormatPattern(_df_, _record_). 1. Let _result_ be a new empty String. 1. For each element _part_ in _formatted_, in List order, do @@ -341,7 +341,7 @@ contributors: Ujjwal Sharma, Younies Mahmoud <emu-alg> 1. Let _df_ be *this* value. 1. Perform ? RequireInternalSlot(_df_, [[InitializedDurationFormat]]). - 1. Let _record_ be ? ToPartialDuration(_duration_). + 1. Let _record_ be ? ToTemporalDurationRecord(_duration_). 1. Let _formatted_ be ? PartitionDurationFormatPattern(_df_, _record_). 1. Let _result_ be ArrayCreate(0). 1. Let _n_ be `0`. ``` --- ### `ToPartialDuration` -> `ToTemporalDurationRecord` --- ### `ToTemporalDurationRecord` * Accepts: A "duration-like" (options bag, but could also be a `Duration` instance as well as valid duration strings). * Returns: A Duration Record (exactly what we needed). * Since it was assumed to be a bug in the original spec text, I was keen to fix this ASAP to unblock implementations. --- ### `ToTemporalDurationRecord` accepts strings ❗ --- ## Act III: The concern πŸ€” --- ![Jordan's comment](https://i.imgur.com/DB8UOq7.png) --- > I think it’s a big issue to assume that one stage 3 proposal will land before another - this one seems likely far simpler and faster than Temporal solely due to its size. > If this proposal must wait for Temporal, that’s something plenary needs consensus on. --- ## Two Problems 1. Proposal depends on Temporal. 2. There's a bug! String parsing shouldn't be allowed (especially without Temporal). --- ## Act IV: The reconciliation πŸ‘€ --- ### Question: Does `DurationFormat` makes sense irrespective of Temporal? --- ### Answer: Yes --- ## Solution * `DurationFormmat` will explicitly avoid depending on Temporal. * This means only accepting options bags (and `Duration` objects by co-incidence). * A follow-up should later add support for strings (and `Duration`s if needed), blocked on Temporal. --- ## Question How should we do this? 1. Merge the follow-on part into Temporal. 2. Split into two distinct Stage 3 proposals. 3. Move the follow-up part into a fresh proposal. --- # Thanks πŸ™
{"type":"slide","title":"DurationFormat Stage 3 Update"}