Module: OrdinalizedFormatting

Defined in:
lib/merb-helpers/date_time_formatting.rb

Overview

Time.now.to_ordinalized_s :long

> “February 28th, 2006 21:10”

Instance Method Summary collapse

Instance Method Details

#strftime_ordinalized(fmt, format = nil) ⇒ Object

Gives you a relative date in an attractive format

Parameters

format<String>

strftime string used to format a time/date object

locale<String, Symbol>

An optional value which can be used by localization plugins

Returns

String

Ordinalized time/date object

Examples

5.days.ago.strftime_ordinalized('%b %d, %Y')     # =>


153
154
155
# File 'lib/merb-helpers/date_time_formatting.rb', line 153

def strftime_ordinalized(fmt, format=nil)
  strftime(fmt.gsub(/(^|[^-])%d/, '\1_%d_')).gsub(/_(\d+)_/) { $1.to_i.ordinalize }
end

#to_ordinalized_s(format = :default) ⇒ Object



136
137
138
139
140
# File 'lib/merb-helpers/date_time_formatting.rb', line 136

def to_ordinalized_s(format = :default)
  format = Date.formats[format] 
  return self.to_s if format.nil?
  strftime_ordinalized(format)
end