Module: BBNW::DateTimeUtils
- Included in:
- CsvFile, InvoiceDisplayUtils, TimeSink
- Defined in:
- lib/utils/date_time_utils.rb
Instance Method Summary collapse
- #is_number?(v) ⇒ Boolean
- #long_date(time) ⇒ Object
- #long_date_time(time) ⇒ Object
- #long_time(time) ⇒ Object
- #parse_time(s) ⇒ Object
- #short_date(time) ⇒ Object
- #short_time(time) ⇒ Object
- #time_description(time) ⇒ Object
Instance Method Details
#is_number?(v) ⇒ Boolean
23 24 25 |
# File 'lib/utils/date_time_utils.rb', line 23 def is_number?(v) true if Float(v) rescue false end |
#long_date(time) ⇒ Object
7 8 9 |
# File 'lib/utils/date_time_utils.rb', line 7 def long_date(time) "#{Date::DAYNAMES[time.wday]}, #{Date::ABBR_MONTHNAMES[time.month]} #{time.mday}, #{time.year}" end |
#long_date_time(time) ⇒ Object
19 20 21 |
# File 'lib/utils/date_time_utils.rb', line 19 def long_date_time(time) "#{long_date(time)} #{long_time(time)}" end |
#long_time(time) ⇒ Object
15 16 17 |
# File 'lib/utils/date_time_utils.rb', line 15 def long_time(time) time.strftime("%I:%M.%S %P") end |
#parse_time(s) ⇒ Object
27 28 29 30 |
# File 'lib/utils/date_time_utils.rb', line 27 def parse_time(s) # If it's a number, it's probably a UNIX style timestamp, otherwise parse the string is_number?(s) ? Time.at(s.to_f) : Time.parse(s) end |
#short_date(time) ⇒ Object
3 4 5 |
# File 'lib/utils/date_time_utils.rb', line 3 def short_date(time) "#{Date::DAYNAMES[time.wday]}, #{Date::ABBR_MONTHNAMES[time.month]} #{time.mday}" end |
#short_time(time) ⇒ Object
11 12 13 |
# File 'lib/utils/date_time_utils.rb', line 11 def short_time(time) time.strftime("%I:%M %P") end |
#time_description(time) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/utils/date_time_utils.rb', line 32 def time_description(time) hours = (time / 3600).to_i minutes = (time / 60 - hours * 60).to_i seconds = (time - (minutes * 60 + hours * 3600)) display = "#{minutes} minutes" display = "#{hours} hours, #{display}" if hours > 0 return display, minutes, hours end |