Bug 26226 - strftime format string for 'day of the week' does not recognize justification
Summary: strftime format string for 'day of the week' does not recognize justification
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: time (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-11 04:13 UTC by Cat22
Modified: 2020-07-11 11:43 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
C program demonstrating the issue (294 bytes, text/x-csrc)
2020-07-11 04:13 UTC, Cat22
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Cat22 2020-07-11 04:13:45 UTC
Created attachment 12690 [details]
C program demonstrating the issue

glibc 2.26 and 2.31 (x86_64)
strftime's format string %A does not recognize %-10A while %10A and %-A work as expected
see attached sample program that demonstrates that there is no difference in output between %10A and %-10A
Leaving out the width specifier (%A and %-A) produces the correct:
  Saturday Jul 11, 8:59:44 pm
Saturday Jul 11, 8:59:44 pm
but including the width specifier produces the same string for %10A and %-10A
  Saturday Jul 11, 8:57:42 pm
  Saturday Jul 11, 8:57:42 pm
Comment 1 Andreas Schwab 2020-07-11 06:47:53 UTC
The '-' flag is only valid for numeric formats.
Comment 2 Cat22 2020-07-11 07:47:11 UTC
That makes it different than the behavior of sprintf or printf.
Shouldn't it be desirable to try to conform to the same rules when possible?
Note that the "-" *is* recognized for %A even though you are correct the man page claims it is only for numeric formats. It just does not recognize it when there is a width value involved. Seems like this is also contra the man page -  either way this should be reconsidered and implemented as its worth doing imho.
Here's my reasoning:
1: It makes column alignment much easier
2: closer conformance with sprint/snprintf/printf format specifiers
3: The fix should be fairly easy (low resource requirements) considering the basic code is available in the code for printf/sprintf and already implemented for strftime with numerics
Comment 3 Florian Weimer 2020-07-11 08:27:35 UTC
'-' is already used by another GNU extension, to suppress padding.
Comment 4 Andreas Schwab 2020-07-11 11:43:44 UTC
strftime and printf formats are unrelated.