Skip to content

Conversation

@joshuamegnauth54
Copy link
Contributor

@joshuamegnauth54 joshuamegnauth54 commented Oct 31, 2025

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

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.

@mmstick
Copy link
Member

mmstick commented Oct 31, 2025

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

@joshuamegnauth54 joshuamegnauth54 marked this pull request as draft October 31, 2025 17:09
@joshuamegnauth54 joshuamegnauth54 marked this pull request as ready for review October 31, 2025 18:09
@joshuamegnauth54
Copy link
Contributor Author

Good catch. I fixed it and simplified the code.

joshuamegnauth54 added a commit to joshuamegnauth54/cosmic-settings that referenced this pull request Nov 1, 2025
joshuamegnauth54 added a commit to joshuamegnauth54/cosmic-settings that referenced this pull request Nov 4, 2025
wash2
wash2 previously approved these changes Nov 4, 2025
@wash2 wash2 requested a review from a team November 4, 2025 16:46
@leviport
Copy link
Member

leviport commented Nov 4, 2025

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.

@joshuamegnauth54
Copy link
Contributor Author

@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
Copy link
Contributor Author

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

joshuamegnauth54 added a commit to joshuamegnauth54/cosmic-settings that referenced this pull request Nov 6, 2025
Closes: pop-os#1096, pop-os#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.
It's possible to have a discrepancy between strftime and the
show_seconds setting. If show_seconds is disabled but a user's strftime
formatter has a seconds specifier, then the time applet won't update
seconds because it's internally ticking per minute.

The fix is to ensure that the time applet updates per second regardless
of the user's setting if strftime has a seconds specifier. This is an
internal flag and shouldn't affect the user's show_seconds setting.
@joshuamegnauth54 joshuamegnauth54 force-pushed the issue-1096-custom-date-format branch from 1c725b9 to da485e8 Compare November 6, 2025 18:38
@joshuamegnauth54 joshuamegnauth54 marked this pull request as ready for review November 6, 2025 18:58
@joshuamegnauth54
Copy link
Contributor Author

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.

Copy link
Member

@leviport leviport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the seconds counters are now working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Custom Date Formats

4 participants