slint icon indicating copy to clipboard operation
slint copied to clipboard

RFC: date-time builtin type

Open WilstonOreo opened this issue 1 year ago • 3 comments

When you build Calendars and other Date/Time-Widgets, properties with a date-time builtin type might be useful. Here are a few suggestions how a builtin type date-time could look like:

component Calendar {
in property <date-time> date-time;
}

date-time should behave similar to a JavaScript Date object with convenience functions:

  • hours() -> int, minutes() -> int, month_name() -> string
  • to_string(format: string) -> string: date-time.to_string("DD/MM/YYYY"), date-time.to_string("hh:mm:ss")
  • to_locale_string(locale: string) -> string:

Additionally, there could also be a DateTime namespace to hold functions to construct date-time instances:

  • DateTime.now()
  • DateTime.new(year: int, month: int, day: int, hours: int, minutes: int, seconds: int)

Comments/Suggestions welcome!

WilstonOreo avatar Apr 23 '24 15:04 WilstonOreo

Implementation wise I think that perhaps this needs to be feature conditional and we could wrap icu_calendar’s Date<AnyCalendar>. We’d also wrap that in C++ maybe, or is there something else we should use instead?

tronical avatar Apr 23 '24 19:04 tronical

Yes it should be a feature because there might not even be a system clock on certain MCUs :) Wrapping icu_calendar Date<AnyCalendar> and exposing it as an FFI should be fine. Although it might be good to use std::time in C++ to save a few CPU cycles?

WilstonOreo avatar Apr 23 '24 19:04 WilstonOreo

I'd currently use the duration type for that, which maps to i64 and has millisecond granularity. Normally, I'd think you could add the methods to the duration type, but maybe you want the types appearing semantically different, even if they store the same type of value in the background? Anyways, if there'll be a new date-time type, I think it should allow calculations including "type erasure" like with duration (duration divided by duration yields float). In the style of Rust's SystemTime/Instant and Duration, you should also be able to calculate with one date-time and one duration operand.

Enyium avatar Aug 10 '24 15:08 Enyium