Class: Dateutil
- Inherits:
-
Object
- Object
- Dateutil
- Defined in:
- lib/utils/date/date.rb
Overview
Some basic utils for handling date / time
Instance Method Summary collapse
- #ask_date ⇒ Object
- #ask_end_date ⇒ Object
- #ask_start_date ⇒ Object
-
#initialize ⇒ Dateutil
constructor
A new instance of Dateutil.
- #seconds_to_str(seconds) ⇒ Object
Constructor Details
#initialize ⇒ Dateutil
Returns a new instance of Dateutil.
8 9 10 |
# File 'lib/utils/date/date.rb', line 8 def initialize @prompt = TTY::Prompt.new end |
Instance Method Details
#ask_date ⇒ Object
12 13 14 |
# File 'lib/utils/date/date.rb', line 12 def ask_date Time.parse(@prompt.ask('Enter a date (Y/M/D):')) end |
#ask_end_date ⇒ Object
20 21 22 |
# File 'lib/utils/date/date.rb', line 20 def ask_end_date Time.parse(@prompt.ask('Enter an end date (Y/M/D):')) end |
#ask_start_date ⇒ Object
16 17 18 |
# File 'lib/utils/date/date.rb', line 16 def ask_start_date Time.parse(@prompt.ask('Enter a start date (Y/M/D):')) end |
#seconds_to_str(seconds) ⇒ Object
24 25 26 27 |
# File 'lib/utils/date/date.rb', line 24 def seconds_to_str(seconds) ["#{seconds / 3600}h", "#{seconds / 60 % 60}m", "#{seconds % 60}s"] .select { |str| str =~ /[1-9]/ }.join(' ') end |