Formattable datetime strings with strftime
Closes: #1096, #779, pop-os/cosmic-epoch#2255
The format follows standard strftime specifiers. Chrono's docs has a page listing them with examples:
https://docs.rs/chrono/latest/chrono/format/strftime/index.html
The strftime formatter overrides ICU if enabled because ICU formats time in a locale appropriate manner. Strftime, by its nature, is an override. If the setting isn't used or if the strftime string is empty, the time applets defaults back to ICU.
Currently, this setting isn't exposed in cosmic-settings. I'll add it by this weekend, hopefully - though anyone else who wants to add it can do so if I don't get to it. :smile_cat:
To try it out, create a file called format_strftime in the time applet config folder. It's likely in ~/.config/cosmic/com.system76.CosmicAppletTime/v1/format_strftime.
In that file, add in your strftime format string ensuring it's correct RON. So:
"%A, %B %d %Y"
(I just realized I forgot the time in my example. Oops.)
More examples:
"%F %T"
"%s"
Unix timestamp. The last one is only for the true elite, of course of course.
The string doesn't only need to have specifiers since it's strftime:
"It's %X in %Z"
To reset: Set the same file to "", delete it, or delete its contents.
Serde has an option to treat non-None values as Some, so you can avoid the need to write Some
Good catch. I fixed it and simplified the code.
This allows me to customize the time applet, but I'm not seeing seconds counters increment. After modifying the file, the seconds counter was stuck on 00. After logging out and back in, seconds counters reflect the current time's seconds, but it is frozen on that number until the next minute count increments, and then it goes back to 00. This was both with standalone seconds counters like %S, and with the seconds counter in %T.
@leviport I'll look into it. My guess is that the "show seconds" option needs to be toggled so that the applet refreshes each second which is messy and not ideal.
Let me know if you notice any other regressions and I'll fix them when I can.
I think I figured it out, but I'll set this as a draft until I can test it tomorrow.
Okay this works again. I tested it using pop-os/cosmic-settings#1523.
I tested it by toggling "show seconds" on and off with a few specifiers that include seconds. My comments in the code mention that the specifiers are not exhaustive. I wasn't sure if some of the locale specifiers include seconds. Luckily, that's an easy fix if it ever affects anyone in the future. I didn't want to mass add specifiers to enable ticking per second needlessly.
Let me know if there are any other issues. I'll be free tomorrow evening to work on any other kinks.