Feature #8181

New flag for strftime that supports adding ordinal suffixes to numbers

Added by Tyler Kellen about 1 year ago. Updated about 1 year ago.

[ruby-core:53808]
Status:Rejected
Priority:Normal
Assignee:-
Category:lib
Target version:2.1.0

Description

This is my first issue on the ruby tracker--hopefully I'm asking in the right place?

It would be nice if you could use strftime to generate dates with ordinal suffixes. I propose the addition of another flag to support this: the @ character.

The intended usage would be:

Date.parse('2013-03-01').strftime('%B %@d, %Y')
=> "March 1st, 2013"
Date.parse('2013-03-02').strftime('%B %@d, %Y')
=> "March 2nd, 2013"
Date.parse('2013-03-03').strftime('%B %@d, %Y')
=> "March 3rd, 2013"

...etc

Assuming this would be accepted, I'd be happy to implement the feature. Could someone tell me how to proceed?

History

#1 Updated by Zachary Scott about 1 year ago

ActiveSupport has ordinalize, maybe you want to use that instead.

#3 Updated by Yui NARUSE about 1 year ago

  • Status changed from Open to Rejected

At least, it is not the function of strftime.

#4 Updated by Tyler Kellen about 1 year ago

zzak (Zachary Scott) wrote:

ActiveSupport has ordinalize, maybe you want to use that instead.

-∞ for ActiveSupport.

I don't need or want to require that giant for this simple feature. I can (and have) written a simple ordinalize method which I am currently using.

That said, I think that this:
Time.new.strftime("%a %b %@d")

...is pretty unambigously better than:
require 'activesupport'
time = Time.new
time.strftime("%a %b #{time.day.ordinalize}")

strftime currently supports several flags for formatting the time output, why not this one?

#5 Updated by Yui NARUSE about 1 year ago

tkellen (Tyler Kellen) wrote:

strftime currently supports several flags for formatting the time output, why not this one?

Ruby's strftime is derived from a C function standardized by ISO C90/POSIX/SUV.
So it must be careful with adding minor specifier.
see also http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

#6 Updated by Martin Dürst about 1 year ago

On 2013/04/12 9:07, tkellen (Tyler Kellen) wrote:

-∞ for ActiveSupport.

I don't need or want to require that giant for this simple feature. I can (and have) written a simple ordinalize method which I am currently using.

Does your method support any languages other than English? If not, I'm
not sure it's suitable for inclusion into Ruby. If yes, I don't think it
will be that simple.

[From http://apidock.com/rails/ActiveSupport/Inflector/ordinalize, I
gather that Ruby on Rails doesn't support languages other than English,
either.]

Regards, Martin.


Feature #8181: New flag for strftime that supports adding ordinal suffixes to numbers
https://bugs.ruby-lang.org/issues/8181#change-38478

#7 Updated by Tyler Kellen about 1 year ago

duerst (Martin Dürst) wrote:

On 2013/04/12 9:07, tkellen (Tyler Kellen) wrote:

-∞ for ActiveSupport.

I don't need or want to require that giant for this simple feature. I can (and have) written a simple ordinalize method which I am currently using.

Does your method support any languages other than English? If not, I'm
not sure it's suitable for inclusion into Ruby. If yes, I don't think it
will be that simple.

[From http://apidock.com/rails/ActiveSupport/Inflector/ordinalize, I
gather that Ruby on Rails doesn't support languages other than English,
either.]

Regards, Martin.


Feature #8181: New flag for strftime that supports adding ordinal suffixes to numbers
https://bugs.ruby-lang.org/issues/8181#change-38478

Does strftime support AM/PM for different languages?

#8 Updated by Tyler Kellen about 1 year ago

naruse (Yui NARUSE) wrote:

tkellen (Tyler Kellen) wrote:

strftime currently supports several flags for formatting the time output, why not this one?

Ruby's strftime is derived from a C function standardized by ISO C90/POSIX/SUV.
So it must be careful with adding minor specifier.
see also http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

Thanks naruse, I did not know that. Could you explain what you mean by being careful?

#9 Updated by Yui NARUSE about 1 year ago

tkellen (Tyler Kellen) wrote:

naruse (Yui NARUSE) wrote:

tkellen (Tyler Kellen) wrote:

strftime currently supports several flags for formatting the time output, why not this one?

Ruby's strftime is derived from a C function standardized by ISO C90/POSIX/SUV.
So it must be careful with adding minor specifier.
see also http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

Thanks naruse, I did not know that. Could you explain what you mean by being careful?

If we add for example %@d, and then C standards add %@d as another meaning, it's a pity thing.

Therefore if you can add your extension into C standards, we can add it.

Also available in: Atom PDF