Class: EZTime::FormattedTime

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/eztime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time) ⇒ FormattedTime

Returns a new instance of FormattedTime.



31
32
33
# File 'lib/eztime.rb', line 31

def initialize(time)
  @time = time
end

Instance Attribute Details

#timeObject

Returns the value of attribute time.



21
22
23
# File 'lib/eztime.rb', line 21

def time
  @time
end

Instance Method Details

#day_abbrObject Also known as: aday

Returns the abbreviated name of the weekday (Sun, Mon, etc.)



58
# File 'lib/eztime.rb', line 58

def day_abbr; Date::ABBR_DAYNAMES[wday]; end

#day_nameObject Also known as: nday

Returns the name of the weekday (Sunday, Monday, etc.)



54
# File 'lib/eztime.rb', line 54

def day_name; Date::DAYNAMES[wday]; end

#format(format_str) ⇒ Object



35
36
37
# 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

#hour12Object

Returns the hour in 12-hour format (5:00pm => 5)



80
# File 'lib/eztime.rb', line 80

def hour12;  hour % 12 == 0 ? 12 : hour % 12; end

#lmeridianObject

Returns the meridian in lowercase (am/pm)



104
# File 'lib/eztime.rb', line 104

def lmeridian;  meridian.downcase; end

#lsmeridianObject

Returns the meridian in lowercase, short form (first letter) (a/p)



108
# File 'lib/eztime.rb', line 108

def lsmeridian; smeridian.downcase; end

#meridianObject

Returns the meridian (AM/PM)



96
# File 'lib/eztime.rb', line 96

def meridian;   hour >= 12 ? 'PM' : 'AM'; end

#minuteObject

Returns the minute as a zero-padded string Note: If you need just the minute, use min



88
# File 'lib/eztime.rb', line 88

def minute;  '%02d' % min; end

#month_abbrObject Also known as: amonth

Returns the abbreviated name of the month (Jan, Feb, etc.)



50
# File 'lib/eztime.rb', line 50

def month_abbr; Date::ABBR_MONTHNAMES[month]; end

#month_nameObject Also known as: nmonth

Returns the name of the month (January, February, etc.)



46
# File 'lib/eztime.rb', line 46

def month_name; Date::MONTHNAMES[month]; end

#ordinalObject Also known as: ord

Returns the ordinal of the day (1 => st, 2 => nd, 3 => rd, 4.. => th)



112
# File 'lib/eztime.rb', line 112

def ordinal; EZTime.ordinal(mday, false); end

#secondObject

Returns the second as a zero-padded string Note: If you need just the second, use sec



92
# File 'lib/eztime.rb', line 92

def second;  '%02d' % sec; end

#smeridianObject

Returns the meridian in short form (first letter) (A/P)



100
# File 'lib/eztime.rb', line 100

def smeridian;  meridian[0].chr; end

#syearObject

Returns only the lower two digits of the year (i.e. 2006 => 06)



42
# File 'lib/eztime.rb', line 42

def syear; year.to_s[-2..-1]; end

#zdayObject

Returns the day as a zero-padded string (5 => 05)



72
# File 'lib/eztime.rb', line 72

def zday;   '%02d' % mday;  end

#zhourObject

Returns the hour as a zero-padded string (3 => 03)



76
# File 'lib/eztime.rb', line 76

def zhour;  '%02d' % hour; end

#zhour12Object

Returns the hour in 12-hour format as a zero-padded string (5:00pm => 05)



84
# File 'lib/eztime.rb', line 84

def zhour12; '%02d' % hour12; end

#zmonthObject

Returns the month as a zero-padded string (i.e. June => 06)



68
# File 'lib/eztime.rb', line 68

def zmonth; '%02d' % month; end