Class: Dateutil

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/date/date.rb

Overview

Some basic utils for handling date / time

Instance Method Summary collapse

Constructor Details

#initializeDateutil

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_dateObject



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_dateObject



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_dateObject



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