Top Level Namespace
Defined Under Namespace
Modules: Morpheus
Instance Method Summary collapse
- #format_date(dt, options = {}) ⇒ Object
- #format_dt(dt, options = {}) ⇒ Object
-
#format_dt_as_param(dt) ⇒ Object
returns.
- #format_local_date(dt, options = {}) ⇒ Object
- #format_local_dt(dt, options = {}) ⇒ Object
-
#parse_time(dt) ⇒ Object
returns an instance of Time.
Instance Method Details
#format_date(dt, options = {}) ⇒ Object
31 32 33 |
# File 'lib/morpheus/formatters.rb', line 31 def format_date(dt, ={}) format_dt(dt, .merge({local: true})) end |
#format_dt(dt, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/morpheus/formatters.rb', line 18 def format_dt(dt, ={}) dt = parse_time(dt) if [:local] dt = dt.getlocal end format = [:format] || "%x %I:%M %p %Z" return dt.strftime(format) end |
#format_dt_as_param(dt) ⇒ Object
returns
40 41 42 43 |
# File 'lib/morpheus/formatters.rb', line 40 def format_dt_as_param(dt) dt = dt.getutc format_dt(dt, {format: "%Y-%m-%d %X"}) end |
#format_local_date(dt, options = {}) ⇒ Object
35 36 37 |
# File 'lib/morpheus/formatters.rb', line 35 def format_local_date(dt, ={}) format_dt(dt, {local: true, format: "%x"}.merge()) end |
#format_local_dt(dt, options = {}) ⇒ Object
27 28 29 |
# File 'lib/morpheus/formatters.rb', line 27 def format_local_dt(dt, ={}) format_dt(dt, {local: true}.merge()) end |
#parse_time(dt) ⇒ Object
returns an instance of Time
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/morpheus/formatters.rb', line 4 def parse_time(dt) if dt.nil? || dt == '' || dt.to_i == 0 return nil elsif dt.is_a?(Time) return dt elsif dt.is_a?(String) return Time.parse(dt) elsif dt.is_a?(Numeric) return Time.at(dt) else raise "bad argument type for parse_time() #{dt.class} #{dt.inspect}" end end |