slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.33k stars 538 forks source link

Time formatting #3597

Open xentec opened 9 months ago

xentec commented 9 months ago

I often display lists with dated items and filter them in UI logic to avoid updating the whole list over and over again. The date values themselves are simple ints in seconds. But to display said dates I also need to format a string inside the app logic and send it to the UI. This seems redundant. Since formatting the data should be an UI job, I'd like to request new feature: time (and date) formatting.

It could be a simple macro like: @fmt-time(time, "<strftime>") 1 or a new time type with a Window.default-time-format property and localization integration.

ogoffart commented 9 months ago

Right now, it is possible to do that using a pure callback in a global object, and implement the time formatting in native code.

But yes, we should support local-aware time formatting somehow through @tr("...") in the future

tronical commented 9 months ago

Alternatively, would it perhaps make sense to provide time formatting independent from @tr and insteadas a built-in functionality that uses icu4x behind the scenes?