-
Notifications
You must be signed in to change notification settings - Fork 135
Formattable datetime strings with strftime #1129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Formattable datetime strings with strftime #1129
Conversation
|
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 |
|
@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. |
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.
1c725b9 to
da485e8
Compare
|
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. |
There was a problem hiding this 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!
Closes: #1096, #779, pop-os/cosmic-epoch#2255
The format follows standard
strftimespecifiers. Chrono's docs has a page listing them with examples:https://docs.rs/chrono/latest/chrono/format/strftime/index.html
The
strftimeformatter 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_strftimein 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.