-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
feat(date-widget): allow modifiers for strftime integer formatters #1243
Conversation
Added the ability of use modifiers with custom format. For example if using %U returns 04, you can add a modifier so that bar date widget shows 05. Config is formatted like format: {"Custom": {"Custom": format_str, "Modifiers": {formatter: mod_value}}}
A fellow JIRA victim? 😅 |
komorebi-bar/src/date.rs
Outdated
#[serde(untagged)] | ||
pub enum Custom { | ||
Simple(String), | ||
WithModifiers { |
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.
Let's separate this out into its own struct
komorebi-bar/src/date.rs
Outdated
@@ -44,7 +54,9 @@ pub enum DateFormat { | |||
/// Day Date Month Year format (8 September 2024) | |||
DayDateMonthYear, | |||
/// Custom format (https://docs.rs/chrono/latest/chrono/format/strftime/index.html) | |||
Custom(String), | |||
/// Allow modifiers for any integer formatter | |||
/// Use format: { Custom: "format_str", "Modifiers": { "formatter": value } } |
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.
And move these docstrings onto that new struct
Alright, I made CustomModifiers into it's own struct. I ended up just making it another member of the DateFormat enum and moved the apply_modifiers function to be a part of CustomModifiers instead of DateFormat. Should be a lot cleaner now and still has no conflicts with old configurations. |
Also yes :D , and it is absolute pure laziness, but I hate doing the mental math every time I look at the week number. |
This looks good! Can you run |
a6183bf
to
bcc4323
Compare
Ran format and squashed everything into bcc4323 , not the cleanest since i got some conflicts, but should be ok. |
e01f99b merged this manually from the command line here, thank you for the contribution! 🎉 |
Also a reminder that if you are using komorebi at work to please make sure you get an appropriate individual commercial use license and submit a software reimbursement request to your employer 🙏 |
Added the ability of use modifiers with custom format.
For example if using %U returns 04, you can add a modifier so that bar date widget shows 05. Config is formatted like format: {"Custom": {"Custom": format_str, "Modifiers": {formatter: mod_value}}}
Accepts config with format: {"Custom": format_str}, so does not break any existing configs.
The reason for this change is because I'd like to display the week number, starting from 1, but strftime only has options to start from 0, so the only option is to modify the starting value by 1. I then expanded this ability to any other numerical value.
Current notes:
This does not take into account "overflows" with dates or months, so it could make you display month 13 or day 32.