Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

Samu-K
Copy link
Contributor

@Samu-K Samu-K commented Jan 23, 2025

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.

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}}}
@LGUG2Z LGUG2Z added the komorebi-bar Related to the komorebi-bar crate label Jan 23, 2025
@LGUG2Z
Copy link
Owner

LGUG2Z commented Jan 23, 2025

The reason for this change is because I'd like to display the week number, starting from 1

A fellow JIRA victim? 😅

#[serde(untagged)]
pub enum Custom {
Simple(String),
WithModifiers {
Copy link
Owner

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

@@ -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 } }
Copy link
Owner

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

@LGUG2Z LGUG2Z added the enhancement New feature or request label Jan 23, 2025
@Samu-K
Copy link
Contributor Author

Samu-K commented Jan 23, 2025

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.

@Samu-K
Copy link
Contributor Author

Samu-K commented Jan 23, 2025

The reason for this change is because I'd like to display the week number, starting from 1

A fellow JIRA victim? 😅

Also yes :D , and it is absolute pure laziness, but I hate doing the mental math every time I look at the week number.

@LGUG2Z
Copy link
Owner

LGUG2Z commented Jan 23, 2025

This looks good! Can you run cargo +nightly fmt to get the workflows passing and then squash all the changes into a single commit?

@Samu-K Samu-K force-pushed the feature/date-modifiers branch from a6183bf to bcc4323 Compare January 24, 2025 02:21
@Samu-K
Copy link
Contributor Author

Samu-K commented Jan 24, 2025

Ran format and squashed everything into bcc4323 , not the cleanest since i got some conflicts, but should be ok.

@LGUG2Z
Copy link
Owner

LGUG2Z commented Jan 24, 2025

e01f99b merged this manually from the command line here, thank you for the contribution! 🎉

@LGUG2Z LGUG2Z closed this Jan 24, 2025
@LGUG2Z
Copy link
Owner

LGUG2Z commented Jan 24, 2025

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 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request komorebi-bar Related to the komorebi-bar crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants