class EZTime::FormattedTime
Attributes
Public Class Methods
# File lib/eztime.rb, line 31 def initialize(time) @time = time end
Public Instance Methods
Returns the abbreviated name of the weekday (Sun, Mon, etc.)
# File lib/eztime.rb, line 58 def day_abbr; Date::ABBR_DAYNAMES[wday]; end
Returns the name of the weekday (Sunday, Monday, etc.)
# File lib/eztime.rb, line 54 def day_name; Date::DAYNAMES[wday]; end
# File lib/eztime.rb, line 35 def format(format_str) eval("'" + format_str.gsub(/:([a-z_]{1,}[0-9]{0,2})/, '\' + \1.to_s + \'') + "'") end
Returns the hour in 12-hour format (5:00pm => 5)
# File lib/eztime.rb, line 80 def hour12; hour % 12 == 0 ? 12 : hour % 12; end
Returns the meridian in lowercase (am/pm)
# File lib/eztime.rb, line 104 def lmeridian; meridian.downcase; end
Returns the meridian in lowercase, short form (first letter) (a/p)
# File lib/eztime.rb, line 108 def lsmeridian; smeridian.downcase; end
Returns the meridian (AM/PM)
# File lib/eztime.rb, line 96 def meridian; hour >= 12 ? 'PM' : 'AM'; end
Returns the minute as a zero-padded string Note: If you need just the minute, use min
# File lib/eztime.rb, line 88 def minute; '%02d' % min; end
Returns the abbreviated name of the month (Jan, Feb, etc.)
# File lib/eztime.rb, line 50 def month_abbr; Date::ABBR_MONTHNAMES[month]; end
Returns the name of the month (January, February, etc.)
# File lib/eztime.rb, line 46 def month_name; Date::MONTHNAMES[month]; end
Returns the ordinal of the day (1 => st, 2 => nd, 3 => rd, 4.. => th)
# File lib/eztime.rb, line 112 def ordinal; EZTime.ordinal(mday, false); end
Returns the second as a zero-padded string Note: If you need just the second, use sec
# File lib/eztime.rb, line 92 def second; '%02d' % sec; end
Returns the meridian in short form (first letter) (A/P)
# File lib/eztime.rb, line 100 def smeridian; meridian[0].chr; end
Returns only the lower two digits of the year (i.e. 2006 => 06)
# File lib/eztime.rb, line 42 def syear; year.to_s[-2..-1]; end
Returns the day as a zero-padded string (5 => 05)
# File lib/eztime.rb, line 72 def zday; '%02d' % mday; end
Returns the hour as a zero-padded string (3 => 03)
# File lib/eztime.rb, line 76 def zhour; '%02d' % hour; end
Returns the hour in 12-hour format as a zero-padded string (5:00pm => 05)
# File lib/eztime.rb, line 84 def zhour12; '%02d' % hour12; end
Returns the month as a zero-padded string (i.e. June => 06)
# File lib/eztime.rb, line 68 def zmonth; '%02d' % month; end