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

Support %P (lowercase am/pm) glibc extension #3314

Closed
wants to merge 1 commit into from

Conversation

chris-morgan
Copy link

Fun fact: in glibc you can also spell %P %#p, # meaning “swap case”. I haven’t implemented glibc’s ^ or # flags (and don’t think there’s any particularly urgent need for it, so long as %P is around).


When #2544 broke this functionality for me and many other users of Waybar, I gathered from the response in #2811 that there was actively no interest in supporting glibc extensions. But now that #3271 has added the other important glibc extension (unpadded hours), I figured it might be worth making and trying submitting this patch after all.

The naming is arbitrary, and the code order for a quite possibly misguided form of consistency. I’m not fussed about it, feel free to amend it as you desire.

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

Looks good to me but please address the inline comments and update the docs (https://github.com/fmtlib/fmt/blob/master/doc/syntax.rst). Make sure to mention that %P is a non-standard extension.

Comment on lines 838 to 840
case 'P':
handler.on_am_pm_lower();
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd suggest moving this after the 'p' case to keep the standard version first (and similarly for am_pm_lower functions below).

Copy link
Author

Choose a reason for hiding this comment

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

The funny thing is that I wrote it in that order initially, then changed it to match what I observed at the start of the switch block, Y before y, without then checking to see if there was subsequent consistency in this way.

*out_++ = tm_hour() < 12 ? 'a' : 'p';
*out_++ = 'm';
} else {
format_localized('P');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test case to ensure that it actually works with localized formatting.

Copy link
Author

Choose a reason for hiding this comment

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

I don’t know how to do this. I wrote the code by blindly copying and modifying, not by deeply understanding what’s going on. 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Something along the lines of

fmt/test/chrono-test.cc

Lines 756 to 757 in 0502936

EXPECT_THAT((std::vector<std::string>{"пн", "Пн", "пнд", "Пнд"}),
Contains(fmt::format(loc, "{:%a}", tm)));

but with %P instead of %a and in a separate test case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any updates? We'll need to have locale path tested before this can be merged.

Fun fact: in glibc you can also spell %P %#p, # meaning “swap case”.
I haven’t implemented glibc’s ^ or # flags.
@chris-morgan
Copy link
Author

I’ve made the requested changes that I know how to, and request assistance on how to test the format_localized('P') branch.

update the docs

I missed this because #3271 also missed this.

@vitaut
Copy link
Contributor

vitaut commented Apr 30, 2023

Closing for now but feel free to resubmit with locale questions addressed.

@vitaut vitaut closed this Apr 30, 2023
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.

2 participants