Skip to content

Commit e29b5e2

Browse files
authored
Add materials about field width specification
1 parent 9f84cba commit e29b5e2

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

exploration/semantic-skeletons.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,72 @@ use calendar and time zone information to compute the displayed field.
321321
Users of these kinds of date/time values sometime can need access to calendar, time zone, and possibly offset controls
322322
in order to achieve effects similar to what temporal types provide.
323323
324+
### Dealing with Field Widths
325+
326+
The current design of date/time functions includes "option bags" derived from `Intl.DateTimeFormat`.
327+
These option bags serve as both classical skeletons _and_ as a source for field width.
328+
The current options are specified as:
329+
330+
- `weekday`
331+
- `long`
332+
- `short`
333+
- `narrow`
334+
- `era`
335+
- `long`
336+
- `short`
337+
- `narrow`
338+
- `year`
339+
- `numeric`
340+
- `2-digit`
341+
- `month`
342+
- `numeric`
343+
- `2-digit`
344+
- `long`
345+
- `short`
346+
- `narrow`
347+
- `day`
348+
- `numeric`
349+
- `2-digit`
350+
- `hour`
351+
- `numeric`
352+
- `2-digit`
353+
- `minute`
354+
- `numeric`
355+
- `2-digit`
356+
- `second`
357+
- `numeric`
358+
- `2-digit`
359+
- `fractionalSecondDigits`
360+
- `1`
361+
- `2`
362+
- `3`
363+
- `timeZoneName`
364+
- `long`
365+
- `short`
366+
- `shortOffset`
367+
- `longOffset`
368+
- `shortGeneric`
369+
- `longGeneric`
370+
371+
Notice that each of these options is specifically about field width or presentation.
372+
The "skeleton" functionality in `Intl` is based on the idea that only the fields mentioned are formatted.
373+
If a separate option specifies which fields to use,
374+
then the above options could be used independently to control field presentation.
375+
376+
> Examples.
377+
> ```
378+
> {{{$d :datetime fields=YMDE month=short} prints Wednesday, Jun 4, 2025}}
379+
> {{{$d :datetime fields=YMDE month=short weekday=short} prints Wed, Jun 4, 2025}}
380+
> {{{$d :datetime fields=T timePrecision=minutes} prints 9:53 AM}}
381+
> {{{$d :datetime fields=T timePrecision=seconds hour=2-digit} prints 09:53:00 AM}}
382+
> {{{$d :datetime fields=T timePrecision=fractionalSeconds hour=2-digit fractionalSecondDigits=2} prints 09:53:00.17 AM}}
383+
> ```
384+
385+
In the above design, it would be an error to specify a field width for a field that is not in the skeleton:
386+
```
387+
{{{$d :datetime fields=T month=short} is an error.}}
388+
```
389+
324390
## Requirements
325391
326392
_What properties does the solution have to manifest to enable the use-cases above?_
@@ -432,6 +498,15 @@ For example:
432498
{$date :datetime time=second} ⇒ 11:39:00 AM
433499
```
434500
501+
Pros:
502+
- Reduces the number of skeleton strings and associated alphabet soup
503+
for message authors (developers, translators) to memorize
504+
505+
Cons:
506+
- Different mechanism from that used for the date portion.
507+
Greater learning curve/cognitive burden for users?
508+
509+
435510
### Design: Use Separate Functions
436511
437512
Some choices:
@@ -505,7 +580,7 @@ _Pros_
505580
- Reserves options for field width
506581
507582
_Cons_
508-
- _Nineteen_ (or so) functions
583+
- _Eighteen_ (or so) functions
509584
- Names appear generative, but aren't actually
510585
- Options might be baroque. Some option values might not be compatible with one another.
511586
- Expression-wide options (short/medium/long/full) and field-level options might both be needed together
@@ -522,4 +597,3 @@ _Cons_
522597
---
523598
524599
525-

0 commit comments

Comments
 (0)