Skip to content

Commit

Permalink
Define function composition for date/time values (#814)
Browse files Browse the repository at this point in the history
* Define function composition for date/time values

* Apply suggestions from code review

Co-authored-by: Stanisław Małolepszy <[email protected]>

* Drop the "only"

* Update spec/registry.md

* Update spec/registry.md

Co-authored-by: Eemeli Aro <[email protected]>

* Update spec/registry.md

Co-authored-by: Eemeli Aro <[email protected]>

* Update spec/registry.md

Co-authored-by: Eemeli Aro <[email protected]>

* Make :date and :time composition implementation-defined

---------

Co-authored-by: Stanisław Małolepszy <[email protected]>
Co-authored-by: Addison Phillips <[email protected]>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent 9e595f6 commit 2334e16
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
42 changes: 39 additions & 3 deletions spec/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ output.
If both are specified, a _Bad Option_ error MUST be emitted
and a _fallback value_ used as the _resolved value_ of the _expression_.
If the _operand_ of the _expression_ is an implementation-defined date/time type,
it can include _style options_, _field options_, or other option values.
These are included in the resolved option values of the _expression_,
with _options_ on the _expression_ taking priority over any option values of the _operand_.
> [!NOTE]
> The names of _options_ and their _values_ were derived from the
> [options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#description)
Expand Down Expand Up @@ -692,7 +697,15 @@ are encouraged to track development of these options during Tech Preview:
- valid [Unicode Number System Identifier](https://cldr-smoke.unicode.org/spec/main/ldml/tr35.html#UnicodeNumberSystemIdentifier)
- `timeZone` (default is system default time zone or UTC)
- valid identifier per [BCP175](https://www.rfc-editor.org/rfc/rfc6557)
#### Composition
When an _operand_ or an _option_ value uses a _variable_ annotated,
directly or indirectly, by a `:datetime` _annotation_,
its _resolved value_ contains an implementation-defined date/time value
of the _operand_ of the annotated _expression_,
together with the resolved options values.
### The `:date` function
The function `:date` is used to format the date portion of date/time values.
Expand All @@ -716,6 +729,19 @@ The function `:date` has these _options_:
- `medium` (default)
- `short`
If the _operand_ of the _expression_ is an implementation-defined date/time type,
it can include other option values.
Any _operand_ option values matching the `:datetime` _style options_ or _field options_ are ignored,
as is any `style` option.
#### Composition
When an _operand_ or an _option_ value uses a _variable_ annotated,
directly or indirectly, by a `:date` _annotation_,
its _resolved value_ is implementation-defined.
An implementation MAY emit a _Bad Operand_ or _Bad Option_ error (as appropriate)
when this happens.
### The `:time` function
The function `:time` is used to format the time portion of date/time values.
Expand All @@ -739,6 +765,18 @@ The function `:time` has these _options_:
- `medium`
- `short` (default)
If the _operand_ of the _expression_ is an implementation-defined date/time type,
it can include other option values.
Any _operand_ option values matching the `:datetime` _style options_ or _field options_ are ignored,
as is any `style` option.
#### Composition
When an _operand_ or an _option_ value uses a _variable_ annotated,
directly or indirectly, by a `:time` _annotation_,
its _resolved value_ is implementation-defined.
An implementation MAY emit a _Bad Operand_ or _Bad Option_ error (as appropriate)
when this happens.
### Date and Time Operands
Expand Down Expand Up @@ -788,5 +826,3 @@ For more information, see [Working with Timezones](https://w3c.github.io/timezon
> The form of these serializations is known and is a de facto standard.
> Support for these extensions is expected to be required in the post-tech preview.
> See: https://datatracker.ietf.org/doc/draft-ietf-sedate-datetime-extended/
4 changes: 2 additions & 2 deletions test/tests/functions/date.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"src": "{|2006-01-02| :date style=long}"
},
{
"src": ".local $d = {|2006-01-02| :date style=long} {{{$d :date}}}"
"src": ".local $d = {|2006-01-02| :date style=long} {{{$d}}}"
},
{
"src": ".local $t = {|2006-01-02T15:04:06| :time} {{{$t :date}}}"
"src": ".local $d = {|2006-01-02| :datetime dateStyle=long timeStyle=long} {{{$d :date}}}"
}
]
}
4 changes: 2 additions & 2 deletions test/tests/functions/time.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"src": "{|2006-01-02T15:04:06| :time style=medium}"
},
{
"src": ".local $t = {|2006-01-02T15:04:06| :time style=medium} {{{$t :time}}}"
"src": ".local $t = {|2006-01-02T15:04:06| :time style=medium} {{{$t}}}"
},
{
"src": ".local $d = {|2006-01-02T15:04:06| :date} {{{$d :time}}}"
"src": ".local $t = {|2006-01-02T15:04:06| :datetime dateStyle=long timeStyle=long} {{{$t :time}}}"
}
]
}

0 comments on commit 2334e16

Please sign in to comment.