-
Notifications
You must be signed in to change notification settings - Fork 711
[css-values-5][css-content-3] Add functions for time-sensitive styling #12146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What are the expected use-cases for this? This is a lot of complexity to pull in, and needs a reasonably good use-case to justify it.
This would not be a good use-case, fwiw. That's meaningful information in the page, and should be expressed in the page markup, not hidden in attributes and then exposed via CSS. |
In #9877, I’ve mentioned already that I believe it should be in scope of CSS to describe and select different datetime representations depending on the available width, especially in table columns, e.g. as part of Only remotely related, I proposed MQ features to deal with user-local dates and times in #9710. |
@tabatkins It might be helpful to think of it as an offshoot of WICG/webcomponents#1064. I'm also open to it being at least partly done in HTML instead. But, the incredibly regular structure of them already gives me some pause, and I can go ahead and close this and file an HTML issue with proposals related to |
Update: filed whatwg/html#4630 (comment) and came up with a (much) better (hybrid) HTML/CSS solution. |
I'm thinking the following:
wall-time(load)
: Get load-time wall clock time at millisecond resolution. Useful for starting infinite, time-dependent animations like clocks at the right phase.wall-time(current)
: Get current wall clock time at millisecond resolution. Updates every frame. Useful for some advanced uses, as well as stuff likecontent: datetime(var(--post-time), if(calc(wall-time(current) - 86400s < var(--post-time)), relative, absolute)
(see below). The lack of timers makes it way simpler to code.datetime(offset? <datetime-option>+)
: Display a localized date-time string. Takes a number of options, mostly inspired byIntl.DateTimeFormat
(but with a different syntax). If omitted,offset
is the current time, continuously updated. Possible options:relative
,absolute
: Display as relative or absolute. Default is absolute. If relative, it'll update in real time, so you don't have to keep it in sync.locale(<locale-ident> | default)
: Display using the given locale. Optionally can follow the identifier withlookup
or (default)best-fit
to set the matching algorithm. This is also used for specifying numbering system, calendar, and optionally hour cycle.format(lookup | best-fit)
: Sets the format matcher algorithm. Default isbest-fit
.timezone(<string>? + [long | short]? + [localized | offset | generic]?)
: Set the time zone to display as. Default is the runtime's default time zone (usually the local one). The other options control the equivalent of thetimeZoneName
parameter forDateTimeFormat
.weekday(long | short | narrow)
: Set the weekday representation.era(long | short | narrow)
: Set the era (CE/BCE/etc.) representation.year(numeric | two-digit)
: Set the year representation.month(numeric | two-digit | long | short | narrow)
: Set the month representation.day(numeric | two-digit)
: Set the day representation.hour([numeric | two-digit] + [12 | 24] + [long | short | narrow])
: Set the hour representation.12
forces 12-hour, while24
forces 24-hour.minute(numeric | two-digit)
: Set the minute representation.second(numeric | two-digit)
: Set the second representation.fractional-digits(0 | 1 | 2 | 3)
: Set the number of fractional second digits. Default is zero.date-style(full | long | medium | short)
: Set the date style, like indateStyle
forIntl.DateTimeFormat
time-style(full | long | medium | short)
: Set the time style, like intimeStyle
forIntl.DateTimeFormat
I've noticed date displaying shows up pretty much constantly, and it'd be nice to be able to simply do
content: datetime(attr(data-time ms));
in CSS withdata-time="{{ms}}"
rather than having to roll a<span>{{date_time}}</span>
possibly across hundreds of instances.The text was updated successfully, but these errors were encountered: