Freitag, 7. November 2008

Compare time

module ApplicationHelper
..SOMETIME_FORMAT = "%a %b %d %H:%M:%S %z %Y"
..SOMETIME_FORMAT_DB = '%Y-%m-%d %H:%M:%S'

..def sometime_this_month(time, format='user')
....return time.beginning_of_month.strftime(SOMETIME_FORMAT) if format == 'user'
....return time.beginning_of_month.strftime(SOMETIME_FORMAT_DB) if format == 'db'
..end

..def sometime_today(time, format='user')
....return time.beginning_of_day.strftime(SOMETIME_FORMAT) if format == 'user'
....return time.beginning_of_day.strftime(SOMETIME_FORMAT_DB) if format == 'db'
..end

end


Time based finds.

created_at time from the database is: "2008-10-24 22:06:18 +0200"

However retrieving the Time.now results in the format as follows: "Fri Nov 07 15:31:56 +0100 2008"

end

Keine Kommentare: