-
Notifications
You must be signed in to change notification settings - Fork 75
Description
Before starting
- I have searched existing issues and there is not already an open issue on the subject.
Summary
I propose extending the duration token type to also accept a JSON number value in addition to the current object value.
- duration: Number | Object
- Object
- value: number
- unit: string (
msors)
- Number (duration in
ms)<value>equivalent to{ value: <value>, unit: 'ms' }
- Object
Version
Third Editor’s Draft
Problem & motivation
I get why the granularity of "value" vs "unit" was done for dimension tokens, given the variety of dimensional units and complex conversion formulas between them.
However, a duration (i.e., length of time) has a single set of globally-known ratios to be able to convert a base unit (ms) to a larger order unit (s, min, hour, etc.). The vast majority of humans that can tell time know of these ratios (1000ms = 1s, 60s = 1min, etc.).
There might be accuracy concerns when converting to larger and larger unit values, but I'd argue that design tokens (which are used to build UI interactions that appear for seconds; at most), should rarely ever need units large enough for accuracy to be an issue.
Prior art
No response
Pros & cons
Pros
- backward-compatible syntax
- less-verbose syntax
- easy to define manually for the majority of practical durations (< 5min)
- for much larger values, software-defined values can take advantage of scientific notation to optimize the JSON definition
- some authors may prefer this syntax
Cons
- additional data type for tooling authors to support
- implementation of larger unit conversion (e.g., to
s,min, etc.) falls on tooling authors - very large durations are difficult to define manually without the aid of a calculator
- (may not be a problem for most practical use cases)
Examples
250ms
(all tokens are equivalent)
1.5s
(all tokens are equivalent)
{
"tok2": {
// most explicit / user-friendly
"a": {
"$type": "duration",
"$value": {
"value": 1.5,
"unit": "s"
}
},
"b": {
"$type": "duration",
"$value": {
"value": 1500,
"unit": "ms"
}
},
// most efficient
"c": {
"$type": "duration",
"$value": 1500
}
}
}3 3/8min
This example may not be practical, but it's possible.
(all tokens are equivalent)
{
"tok3": {
// most explicit / user-friendly
"a": {
"$type": "duration",
"$value": {
"value": 202.5,
"unit": "s"
}
},
"b": {
"$type": "duration",
"$value": {
"value": 202500,
"unit": "ms"
}
},
"c": {
"$type": "duration",
"$value": {
"value": 2.025e5,
"unit": "ms"
}
},
"d": {
"$type": "duration",
"$value": 2.025e5
},
// most efficient
"e": {
"$type": "duration",
"$value": 202500
}
}
}Alternatives
No response
Required
- I have read and agree to abide by the CODE_OF_CONDUCT
{ "tok1": { // most explicit / user-friendly "a": { "$type": "duration", "$value": { "value": 250, "unit": "ms" } }, "b": { "$type": "duration", "$value": { "value": 0.25, "unit": "s" } }, // most efficient "c": { "$type": "duration", "$value": 250 } } }