Class: EZTime::FormattedTime
- Inherits:
-
Object
- Object
- EZTime::FormattedTime
- Extended by:
- Forwardable
- Defined in:
- lib/eztime.rb
Instance Attribute Summary collapse
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#day_abbr ⇒ Object
(also: #aday)
Returns the abbreviated name of the weekday (Sun, Mon, etc.).
-
#day_name ⇒ Object
(also: #nday)
Returns the name of the weekday (Sunday, Monday, etc.).
- #format(format_str) ⇒ Object
-
#hour12 ⇒ Object
Returns the hour in 12-hour format (5:00pm => 5).
-
#initialize(time) ⇒ FormattedTime
constructor
A new instance of FormattedTime.
-
#lmeridian ⇒ Object
Returns the meridian in lowercase (am/pm).
-
#lsmeridian ⇒ Object
Returns the meridian in lowercase, short form (first letter) (a/p).
-
#meridian ⇒ Object
Returns the meridian (AM/PM).
-
#minute ⇒ Object
Returns the minute as a zero-padded string Note: If you need just the minute, use min.
-
#month_abbr ⇒ Object
(also: #amonth)
Returns the abbreviated name of the month (Jan, Feb, etc.).
-
#month_name ⇒ Object
(also: #nmonth)
Returns the name of the month (January, February, etc.).
-
#ordinal ⇒ Object
(also: #ord)
Returns the ordinal of the day (1 => st, 2 => nd, 3 => rd, 4.. => th).
-
#second ⇒ Object
Returns the second as a zero-padded string Note: If you need just the second, use sec.
-
#smeridian ⇒ Object
Returns the meridian in short form (first letter) (A/P).
-
#syear ⇒ Object
Returns only the lower two digits of the year (i.e. 2006 => 06).
-
#zday ⇒ Object
Returns the day as a zero-padded string (5 => 05).
-
#zhour ⇒ Object
Returns the hour as a zero-padded string (3 => 03).
-
#zhour12 ⇒ Object
Returns the hour in 12-hour format as a zero-padded string (5:00pm => 05).
-
#zmonth ⇒ Object
Returns the month as a zero-padded string (i.e. June => 06).
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
#time ⇒ Object
Returns the value of attribute time.
21 22 23 |
# File 'lib/eztime.rb', line 21 def time @time end |
Instance Method Details
#day_abbr ⇒ Object 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_name ⇒ Object 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 |
#hour12 ⇒ Object
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 |
#lmeridian ⇒ Object
Returns the meridian in lowercase (am/pm)
104 |
# File 'lib/eztime.rb', line 104 def lmeridian; meridian.downcase; end |
#lsmeridian ⇒ Object
Returns the meridian in lowercase, short form (first letter) (a/p)
108 |
# File 'lib/eztime.rb', line 108 def lsmeridian; smeridian.downcase; end |
#meridian ⇒ Object
Returns the meridian (AM/PM)
96 |
# File 'lib/eztime.rb', line 96 def meridian; hour >= 12 ? 'PM' : 'AM'; end |
#minute ⇒ Object
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_abbr ⇒ Object 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_name ⇒ Object 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 |
#ordinal ⇒ Object 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 |
#second ⇒ Object
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 |
#smeridian ⇒ Object
Returns the meridian in short form (first letter) (A/P)
100 |
# File 'lib/eztime.rb', line 100 def smeridian; meridian[0].chr; end |
#syear ⇒ Object
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 |
#zday ⇒ Object
Returns the day as a zero-padded string (5 => 05)
72 |
# File 'lib/eztime.rb', line 72 def zday; '%02d' % mday; end |
#zhour ⇒ Object
Returns the hour as a zero-padded string (3 => 03)
76 |
# File 'lib/eztime.rb', line 76 def zhour; '%02d' % hour; end |
#zhour12 ⇒ Object
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 |
#zmonth ⇒ Object
Returns the month as a zero-padded string (i.e. June => 06)
68 |
# File 'lib/eztime.rb', line 68 def zmonth; '%02d' % month; end |