You can call strftime on date inside the lambda - :long_ordinal in
Rails' code is
lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }
Allowing lambda's was introduced relatively recently, I think - maybe
2.2
--
Pat
On 23/03/2009, at 5:21 PM, Bodaniel Jeanes wrote:
>
> I didn't know you could pass a lambda ... that's cool. Can you still
> do the strftime tokens in there or only pull out the info from the
> date object itself?
>
> On Mon, Mar 23, 2009 at 4:17 PM, Pat Allan <p...@freelancing-
> gods.com> wrote:
>>
>> You're right, it's not - and that's not how Rails does it (and I
>> forgot to mention, this is an ActiveSupport extension, not core
>> Ruby).
>> But you can add your own format keys:
>>
>> Date::DATE_FORMATS[:fancy] = lambda { |date|
>> "On the #{date.day.ordinalize} day of the #{date.month.ordinalize}"
>> }
>>
>> The same applies to Time and DateTime.
>>
>> Cheers
>>
>> --
>> Pat
>>
>> On 23/03/2009, at 5:13 PM, Bodaniel Jeanes wrote:
>>
>>>
>>> I was wondering this a few weeks ago. Pat, that doesn't let you
>>> cusomize it nicely. What if you wanted something like "on the 3rd
>>> day
>>> of the 8th month" or something non standard. I wish it was part of
>>> strftime but my initial googling said no
>>>
>>> On Mon, Mar 23, 2009 at 3:49 PM, Pat Allan <p...@freelancing-
>>> gods.com> wrote:
>>>>
>>>> Try date.to_s(:long_ordinal)
>>>>
>>>> --
>>>> Pat
>>>>
>>>> On 23/03/2009, at 4:47 PM, Torm3nt wrote:
>>>>
>>>>> Need days to be displayed as:
>>>>>
>>>>> 1st January, 2009.
>>>>>
>>>>> Currently, it seems the strftime method in ruby only allows for 1
>>>>> January 2009. How can I get the ordinal suffix for the day value?
>>>>>
>>>>>
>>>>> Kirk
>>>>>
>>>>>>
>>>>
>>>>
>>>>>
>>>>
>>>
>>>>
>>
>>
>>>
>>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en
-~----------~----~----~----~------~----~------~--~---