Module: DockDriver::Template::DatesAndTimes
- Included in:
- DockDriver::Template
- Defined in:
- lib/dock_driver/template/dates_and_times.rb
Overview
Adds date and time related methods to the DockDriver::Template DSL.
Instance Method Summary collapse
-
#beats(fmt = "@%0.0f") ⇒ Object
(also: #internet_time)
Internet Time Examlpes:.
-
#centibeats(fmt = "@%0.2f") ⇒ Object
Internet Time with a fractional part.
-
#date(fmt = "%F %T") ⇒ Object
(also: #time)
Returns a formatted date.
-
#gmdate(fmt = "%F %T") ⇒ Object
(also: #gmtime)
Returns a formatted date in GMT.
Instance Method Details
#beats(fmt = "@%0.0f") ⇒ Object Also known as: internet_time
Internet Time Examlpes:
<%= beats %> => @203
<%= internet_time %> => @203
<%= beats "%0.1f" %> => 203.0
51 52 53 |
# File 'lib/dock_driver/template/dates_and_times.rb', line 51 def beats( fmt = "@%0.0f") return self.centibeats( fmt ) end |
#centibeats(fmt = "@%0.2f") ⇒ Object
Internet Time with a fractional part. Examples:
<%= centibeats %> => @203.44
<%= centibeats "%0.1f" %> => 203.4
37 38 39 40 41 42 |
# File 'lib/dock_driver/template/dates_and_times.rb', line 37 def centibeats( fmt = "@%0.2f" ) # UTC+1 is the time base for Interet Time. now = Time.now.utc + 3600 base = Time.gm( now.year, now.month, now.day, 1 ) return fmt % [(now.to_f - base.to_f) * 0.01157407407] end |
#date(fmt = "%F %T") ⇒ Object Also known as: time
Returns a formatted date. Examples:
<%= date %> => 2012-03-04 17:35:33
<%= time %> => 2012-03-04 17:35:33
<%= date "%A" %> => Wednesday
12 13 14 |
# File 'lib/dock_driver/template/dates_and_times.rb', line 12 def date( fmt = "%F %T" ) return Time.now.strftime( fmt ) end |
#gmdate(fmt = "%F %T") ⇒ Object Also known as: gmtime
Returns a formatted date in GMT. Examples:
<%= gmdate %> => 2012-03-04 17:35:33
<%= gmtime %> => 2012-03-04 17:35:33
<%= gmdate "%A" %> => Tuesday
25 26 27 |
# File 'lib/dock_driver/template/dates_and_times.rb', line 25 def gmdate( fmt = "%F %T" ) return Time.now.gmtime.strftime( fmt ) end |