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

Date#to_formatted_s bug #25251

Closed
ilyakarol opened this issue Jun 2, 2016 · 4 comments
Closed

Date#to_formatted_s bug #25251

ilyakarol opened this issue Jun 2, 2016 · 4 comments

Comments

@ilyakarol
Copy link

ilyakarol commented Jun 2, 2016

Hi all, it seems like a little bug:

Date.today 
=> Thu, 02 Jun 2016
Date.today.to_formatted_s(:long)
=> "June  2, 2016" # 2 spaces between June and 2

Expected behavior

Date.today.to_formatted_s(:long)
=> "June 2, 2016" # 1 space between June and 2

System configuration

Rails version: 4.2.6

Ruby version: 2.2.3

@ilyakarol ilyakarol changed the title DateTime#to_formatted_s bug Date#to_formatted_s bug Jun 2, 2016
@maclover7
Copy link
Contributor

Can reproduce on master.

sgrif added a commit that referenced this issue Jun 2, 2016
We are currently using `%e` which adds a space before the result if the
digit is a single number. This leads to strings like `February  2, 2016`
which is undesireable. I've opted to replace with 0 padding instead of
removing the padding entirely, to preserve compatibility for those
relying on the fact that the width is constant, and to be consistent
with time formatting.

Fixes #25251.
@sgrif sgrif closed this as completed in 2c5a8ba Jun 2, 2016
@jonathanhefner
Copy link
Member

jonathanhefner commented Jun 2, 2016

@sgrif What about using %-e (or %-d) instead of %d?

EDIT: Although :short does look better with a leading zero.

@sgrif
Copy link
Contributor

sgrif commented Jun 2, 2016

I specifically mentioned the reasoning in the commit message.

@jonathanhefner
Copy link
Member

@sgrif My fault! I did miss that last sentence!

However, in the case of the more human-readable :long, I think people are more likely to expect no leading zeros, rather than constant width (particularly in HTML output).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants