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

Clock Formatting For %OI #1469

Open
bisby opened this issue Mar 9, 2022 · 24 comments
Open

Clock Formatting For %OI #1469

bisby opened this issue Mar 9, 2022 · 24 comments

Comments

@bisby
Copy link

bisby commented Mar 9, 2022

Expected Behavior:
The clock module links to https://howardhinnant.github.io/date/date.html#to_stream_formatting - This says

%I The hour (12-hour clock) as a decimal number. If the result is a single digit, it is prefixed with 0. The modified command %OI produces the locale's alternative representation.

Previously %0I returned 8 for 8pm, whereas %I returns 08. So I would expect to have this display 8:45pm

Actual Behavior:
The clock module returns nothing. Empty space on the bar. I can still see the module underline. When I click on the module it shows the full time. When I click on the module again it doesn't clear the full time, but full time stops updating.

Relevant Config:

    "clock": {
        "format": "{:%0I:%M %p}",

Relevant Log lines:

[2022-03-08 20:38:07.854] [error] clock: invalid format

This works when the %0I is changed to %I , but then the formatting isn't quite what I want. I only consider this an issue though because the linked documentation for date formatting says this should be valid.

edit: quick follow once I saw the quote text formatting... it should be %OI not %0I ... 0 worked in the past, and O works but still displays the 0 prefix (08) so is technically still not working.

@bisby bisby changed the title Clock Formatting For %0I Clock Formatting For %OI Mar 9, 2022
@LukashonakV
Copy link
Contributor

LukashonakV commented Mar 26, 2022

At least the issue comes from the date utility and the clock module displays info which is provided by the date library.

  1. According the documentation:

The hour (12-hour clock) as a decimal number. If the result is a single digit, it is prefixed with 0. The modified command %OI produces the locale's alternative representation.

I don't see any mentions about the library should cut the leading zeros. I see it depends on you LC_TIME environment variable.

  1. Try to do the same in terminal:
    a. date +%0I
    b. date +%OI
    c. date +%I
    Result on my machine:
    ps_2022-03-26-14_09_42

So at least I would suggest you to check you local configuration to make sure in terminal local date utility shows the output you've expecting.

@bisby
Copy link
Author

bisby commented Mar 26, 2022

Interesting. It had previously worked so in my brain I registered the locale's alternative as meaning "no leading 0" (since my locale didn't change)

It seems the easiest way with date to remove the 0 is date +%-I but that isnt valid in the library waybar uses.

I also don't have any locales set up that LC_TIME will produce a non leading zero.

Seems to be an issue for me and not waybar. Though I would love to have the option to force no-prefix

@jayache80
Copy link

Is it agreed that this is indeed a bug? And, is there a known workaround?

My waybar-clock config broke recently because I use %-I that will yield single-digit hours without a leading zero. However I now must use %I which yields an undesirable leading zero, else I have an invalid waybar-clock config.

If the intent of the date library that waybar-clock uses is to mimic the functionality of the date command, I'd say it's not currently doing that, because:

date +%-I

works just fine to provide a single digit hour without leading zero (and %-I used to work just fine in waybar-clock until recently).

@LukashonakV
Copy link
Contributor

LukashonakV commented Apr 11, 2022

@bisby, @jayache80
Not sure I understand correct.
Please take a look at my screenshot:

  1. Please look at the top waybar which I ran for an example with the changed time.
  2. Please take a look a the config is opened on the left window.
    For me it looks like working correct
    ps_2022-04-11-12_19_51

@bisby
Copy link
Author

bisby commented Apr 11, 2022

image

For me i get in my logs [error] clock: invalid format and the clock shows up as an empty space. This works fine when the only change is %I but then i have the leading zeroes.

When running with waybar -l trace I get:

[2022-04-11 17:22:44.982] [warning] As using a timezone, some format args may be missing as the date library haven't got a release since 2018.

But nothing else clock related.

@LukashonakV
Copy link
Contributor

Lets summarize:

  1. You are using waybar ver. 0.9.12 ?
  2. Can you check waybar config, maybe by the mistake you filled clock block, especially "format" parameter twice or more times ?

At my screenshot I repeated format and format-alt sections like in your example.
ps_2022-04-12-11_06_21

@jayache80
Copy link

  1. You are using waybar ver. 0.9.12 ?

I tried both 0.9.12 and waybar-git-r1906.503fe9a-1 (arch linux AUR package), and have the same result.

  1. Can you check waybar config, maybe by the mistake you filled clock block, especially "format" parameter twice or more times ?

Having this clock block in my waybar config:

    "clock": {
        // "timezone": "America/New_York",
        "tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
        "format": "{:%I}"
    },

will work to show a leading 0 hour only.

Having this in the clock block of my waybar config:

    "clock": {
        // "timezone": "America/New_York",
        "tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
        "format": "{:%-I}"

will break, and then I get nothing in the clock area.

As @bisby has alluded, is this perhaps caused by a timezone locale configuration, a system date library thing, or some other system config thing?

Using the clock block's timezone field yielded even stranger results.

This clock block:

    "clock": {
        "timezone": "America/New_York",
        "tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
        "format": "{:%I}"
    },

yields a leading 0 hour (in NY time, a different timezone than mine. Neat.)

This clock block:

    "clock": {
        "timezone": "America/New_York",
        "tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
        "format": "{:%-I}"
    },

strangely yields a literal %-I in the clock area.

@LukashonakV
Copy link
Contributor

As @bisby has alluded, is this perhaps caused by a timezone locale configuration, a system date library thing, or some other system config thing?

I'm using GNU coreutils with the fmt package version - 8.32-r1. Can you check is the same version is installed on your machine or you're using another one or even another fmt package. Actually according the code this fmt package handles text formatting.

@bisby
Copy link
Author

bisby commented Apr 13, 2022

fmt (GNU coreutils) 9.0

@jayache80
Copy link

jayache80 commented Apr 13, 2022

fmt 8.1.1-2 is what I was using to produce the above mentioned behavior.

I installed fmt-git 8.1.1.r180.g86e27ccb-1 and tried to build waybar-git-r636.67593b8-1 but I got in library hell and couldn't build:

/usr/include/fmt/core.h:1725:7: error: static assertion failed: Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt
 1725 |       formattable,
      |       ^~~~~~~~~~~
/usr/include/fmt/core.h:1725:7: note: ‘formattable’ evaluates to false

@jayache80
Copy link

I made a request to fmtlib:
fmtlib/fmt#2959

Either some strftime features are no longer fully implemented in fmt (as %-I used to work on Waybar and now it doesn't, but Waybar has always used fmt from what I gather) or the usage is now different and there's now user error.

@hajosattila
Copy link

OFF
LukashonakV
please share your waybar css and config file! (very nice)

@LukashonakV
Copy link
Contributor

Hi @hajosattila , config is Dotfiles

@LukashonakV
Copy link
Contributor

Hi @bisby is this still actual ?

@bisby
Copy link
Author

bisby commented Jan 27, 2023

I've been back on i3wm so not using waybar recently. but booting it up to check...

[2023-01-27 15:28:12.955] [error] clock: invalid format

for

"clock": {
    "format": "{:%-I:%M %p}",

So yes. clock formatting with no leading zeroes is seemingly still not possible in my locale.
And I'm now on fmt (GNU coreutils) 9.1

@iambumblehead
Copy link

I want my waybar to look like gnome's date time area --no leading '0' on the month number

@jayache80
Copy link

Upstream fmt has brought in a commit to master (but not in any releases yet) that should resolve this issue:

fmtlib/fmt@7718eee

I had trouble building waybar with latest fmt (problems with spdlog) so I couldn't test yet.

Also, these are related and possibly the same underlying issue:
#1696
#1447

@LukashonakV
Copy link
Contributor

LukashonakV commented Feb 23, 2023

Hi @jayache80 , @bisby, @iambumblehead according upstream this feature was implemented by the PR#3271 . I've checked the source code and looks like once fmt will be official release Waybar can use this feature.
For example see: test/chrono-test.cc

@kohsine
Copy link

kohsine commented Jan 21, 2024

Stumbled onto this issue while googling how to remove leading zero. Is this still an issue a year later?

@hhhorb
Copy link

hhhorb commented Apr 23, 2024

Still an issue in today's release...

❯ waybar -v
Waybar v0.10.1 (branch 'master')

Module formatting...

    "clock": {
         "format": "{:%OI:%M}"
         }

Expected output (example)...

9:45

Actual output...

09:45

@hhhorb
Copy link

hhhorb commented Apr 24, 2024

Still an issue on v0.10.2.

@jayache80
Copy link

I don't believe fmt uses O alone to strip the leading zeroes, but rather -. So to get

9:45

you'd want to use:

{:%-I:%M}

Anywho, this will be fixed in waybar once

  1. fmt cuts a new release, as the latest fmt release doesn't contain this commit which gets - working correctly to strip leading zeroes where the user requests (latest release has this bug which causes all leading zeroes to get stripped, not just the requested ones)
  2. meson wrapdb gets that new release
  3. waybar updates the dependency

@trevin-j
Copy link

This issue has been very frustrating for me because it seems so simple. For a temporary workaround until the fmt side of things is worked out, you can output the date command in a custom module e.g.:

    "custom/clock": {
        "exec": "date +\"%a %b %e %-I:%M %p\"",
        "interval": 1
    },

In the jsonc file and add "custom/clock" to one of the modules list.

@hhhorb
Copy link

hhhorb commented Jun 25, 2024

@trevin-j, brilliant. THANK YOU for the workaround!

Style selector is #custom-clock

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

No branches or pull requests

8 participants