Skip to content

Commit 9f84cba

Browse files
authored
Start work on 2025-05-12 discussion
Start working on error section, add references to ICU4X field sets, including a table
1 parent 754c53f commit 9f84cba

File tree

1 file changed

+67
-8
lines changed

1 file changed

+67
-8
lines changed

exploration/semantic-skeletons.md

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Status: **Proposed**
77
<dl>
88
<dt>Contributors</dt>
99
<dd>@sffc</dd>
10-
<dd>@aphillips</dd>
10+
<dd>@aphillips</dd>
1111
<dt>First proposed</dt>
1212
<dd>2024-04-06</dd>
1313
<dt>Pull Requests</dt>
@@ -296,6 +296,31 @@ For example, as shown above,
296296
I want the month name to be inflected for standalone when used by itself,
297297
but properly inflected when used in a month-day combination.
298298

299+
### Error Conditions and Value Forcing
300+
One challenge with formatting date/time values is
301+
deciding what effect the function has on the resolved value of the operand.
302+
For example, consider a _declaration_ that uses a function `:time`:
303+
>```
304+
>.local $myTime = {$d :time}
305+
>```
306+
307+
Does the variable `$myTime` contain any date information, such as year or month?
308+
What if `$d` (the original value) is an incremental time? Or a datetime value?
309+
Does the declaration strip the visibility of the date fields, assuming that they _were_ previously present?
310+
311+
On the other hand, many combinations of functions and semantic skeletons seem to imply an implicit conversion.
312+
Implementations that use, for example, `java.time` or JS `Temporal` types
313+
have very specific requirements for some of their types.
314+
Some operations on these types can produce error conditions in the function handler,
315+
even if the _message_ itself is well-formed and other, differently-typed, values do not produce errors.
316+
317+
As noted elsewhere, many programming languages and operating environments do not have
318+
more-modern temporal-like date/time types.
319+
Incremental values or field-based values in these environments
320+
use calendar and time zone information to compute the displayed field.
321+
Users of these kinds of date/time values sometime can need access to calendar, time zone, and possibly offset controls
322+
in order to achieve effects similar to what temporal types provide.
323+
299324
## Requirements
300325
301326
_What properties does the solution have to manifest to enable the use-cases above?_
@@ -352,27 +377,60 @@ _What other properties they have?_
352377
353378
### Design: Use Option Naming
354379
355-
In this section, we use a scheme similar to `FieldSetBuilder` linked earlier.
380+
In this design, we use a capability similar to `FieldSetBuilder` (proposed for ICU4X).
381+
These have the following built-in "fieldsets" (see [here](https://unicode-org.github.io/icu4x/rustdoc/icu/datetime/fieldsets/index.html)):
382+
383+
| Fieldset | Description |
384+
|------------|-------------|
385+
| `Combo` | Struct for combining date/time fields with zone fields. |
386+
| `D` | “17” ⇒ day of month (standalone) |
387+
| `DE` | “17 Friday” ⇒ day of month and weekday |
388+
| `DET` | “17 Friday, 3:47:50 PM” ⇒ day of month and weekday with time |
389+
| `DT` | “17, 3:47:50 PM” ⇒ day of month (standalone) with time |
390+
| `E` | “Friday” ⇒ weekday (standalone) |
391+
| `ET` | “Friday 3:47:50 PM” ⇒ weekday (standalone) with time |
392+
| `M` | “May” ⇒ month (standalone) |
393+
| `MD` | “May 17” ⇒ month and day |
394+
| `MDE` | “Fri, May 17” ⇒ month, day, and weekday |
395+
| `MDET` | “Fri, May 17, 3:47:50 PM” ⇒ month, day, and weekday with time |
396+
| `MDT` | “May 17, 3:47:50 PM” ⇒ month and day with time |
397+
| `T` | “3:47:50 PM” ⇒ time (locale-dependent hour cycle) |
398+
| `Y` | “2024” ⇒ year (standalone) |
399+
| `YM` | “May 2024” ⇒ year and month |
400+
| `YMD` | “5/17/24” ⇒ year, month, and day |
401+
| `YMDE` | “Fri, 5/17/24” ⇒ year, month, day, and weekday |
402+
| `YMDET` | “Fri, 5/17/24, 3:47:50 PM” ⇒ year, month, day, and weekday with time |
403+
| `YMDT` | “5/17/24, 3:47:50 PM” ⇒ year, month, and day with time |
404+
356405
357406
#### DateTime fields
407+
Use the function `:datetime` and use an _option_ to indicate the fieldset.
358408
359-
Options:
409+
The _option_ might have a generic name, such as `fields`,
410+
or it might have sematic names such as `date`/`dateFields`/`time`/`timeFields`.
411+
Option values would be as shown in the table above.
360412
361413
```
362414
{$date :datetime dateFields=YMD}
363415
{$date :datetime date=YMD}
364416
{$date :datetime fields=YMD}
365417
```
366418
367-
The names `dateFields`, `date`, and `fields` are candidate names for the option that specifies the semantic skeleton string to be used for formatting the date/time value.
368419
#### TimePrecision
420+
Note that in the table above, there is only one fieldset of "time" values.
421+
Use a `timePrecision` option to indicate which subfields of a time are desired.
422+
Time formats within a locale don't generally have field lengths
423+
(although zero- versus non-zero filled hours is a variation)
424+
and thus it is sufficient to say what the "last field to show" would be.
369425
370-
Options:
426+
The name `timePrecision` is a placeholder.
427+
This option might be shortened to just `time`.
428+
429+
For example:
371430
```
372-
{$date :datetime timePrecision=minute}
373-
{$date :datetime time=minute}
431+
{$date :datetime timePrecision=minute} ⇒ 11:39 AM
432+
{$date :datetime time=second} ⇒ 11:39:00 AM
374433
```
375-
(TODO: Add others)
376434
377435
### Design: Use Separate Functions
378436
@@ -395,6 +453,7 @@ _Pros_
395453
396454
_Cons_
397455
- Not fully type-safe.
456+
- The `:datetime` function might duplicate functionality
398457
399458
#### Use separate typed functions
400459

0 commit comments

Comments
 (0)