cosmic-applets icon indicating copy to clipboard operation
cosmic-applets copied to clipboard

Formattable datetime strings with strftime

Open joshuamegnauth54 opened this issue 1 month ago • 2 comments

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"

date1

(I just realized I forgot the time in my example. Oops.)

More examples:

"%F %T"

date2

"%s" date3

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"

date4

To reset: Set the same file to "", delete it, or delete its contents.

joshuamegnauth54 avatar Oct 31 '25 01:10 joshuamegnauth54

Serde has an option to treat non-None values as Some, so you can avoid the need to write Some

mmstick avatar Oct 31 '25 02:10 mmstick

Good catch. I fixed it and simplified the code.

joshuamegnauth54 avatar Oct 31 '25 18:10 joshuamegnauth54

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 avatar Nov 04 '25 23:11 leviport

@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.

joshuamegnauth54 avatar Nov 05 '25 00:11 joshuamegnauth54

I think I figured it out, but I'll set this as a draft until I can test it tomorrow.

joshuamegnauth54 avatar Nov 05 '25 03:11 joshuamegnauth54

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.

joshuamegnauth54 avatar Nov 06 '25 19:11 joshuamegnauth54