1

I'm successfully using a duck punch to reformat the date returned by datetime, based on the helpful response given to someone else's question here:

rails dates with json

I'm now trying to do a very similar thing for a date object (rather than datetime), so I've modified the patch as follows:

class ActiveSupport::Date        # I've changed TimeWithZone to Date
    def as_json(options = {})
        strftime('%Y')
    end
end

...but it's not working (the date format is unchanged from the default 2011-02-03).

Any hints on how to get this going much appreciated.

Community
  • 1
  • 1
Snips
  • 6,575
  • 7
  • 40
  • 64

1 Answers1

0

The Date object does not contain the hour, minute and second attributes you are wishing to format. DateTime and Time objects do, as you already know.

seeingidog
  • 1,166
  • 9
  • 5
  • Ah, that's my error with the example code above (which I cut&pasted from the original question to ask this question, and now edited). I've tried it with lots of formats that just include day, month, year. Sorry to take up your time with that mistake. – Snips Feb 03 '11 at 11:38