This project is archived and is in readonly mode.
Date Formatting requires a to_date conversion before format
-
Neeraj Singh
It is working fine for me with rails edge. Can you try again with rails edge?
Time::DATE_FORMATS[:dashy_format] = '%Y-%m-%d-%H-%m-%S' # => 2007-10-23-17-23-23 ruby-1.8.7-p249 > User.first.created_at.to_s(:dashy_format) User Load (0.3ms) SELECT "users".* FROM "users" LIMIT 1 => "2010-06-25-20-06-41" -
Neil Middleton
- Importance changed from to Low
Tested against edge rails and can confirm Time::DATE_FORMATS works correctly as described above.
However, when using Date::DATE_FORMATS it fails which suggests that the comments in the code linked above are either incorrect, or the code isn't working (or I'm doing something wrong, which indicates bad docs).
Link to sample application showing the issue here: http://github.com/neilmiddleton/lh4793 See users#show.
-
Neil Middleton
- Assigned user set to Neeraj Singh
-
Neil Middleton
- No changes were found…
-
Neeraj Singh
Date::DATE_FORMATS is working for me.
ActiveRecord::Schema.define(:version => 20100627025642) do create_table "users", :force => true do |t| t.string "name" t.date "dob" t.datetime "created_at" t.datetime "updated_at" end end class User < ActiveRecord::Base end User.create(:dob => Date.today) ruby-1.8.7-p249 > User.first.dob.to_s(:dashy) User Load (0.3ms) SELECT "users".* FROM "users" LIMIT 1 => "2010-06-26" -
Neil Middleton
So is it simply that DateTime columns don't use Date::DATE_FORMATS without a conversion first? This needs to be a little clearer (in fact all of date/time formatting could do with some docs...)
-
Neeraj Singh
- State changed from new to invalid
That is true. DateTime columns use Time::DATE_FORMATS.