Module: Crunchyroll::Utils

Defined in:
lib/crunchyroll/utils.rb

Class Method Summary collapse

Class Method Details

.format_cr_date(date) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/crunchyroll/utils.rb', line 37

def format_cr_date(date)
  s = ''
  date.split('Simulcast on ')[1][0..-5].split.each { |d| s += d.end_with?(?s) ? d[0..-2] : d; s += ' ' }

  am_pm = s.strip[-2..-1]
  s     = s.strip[0..-3]

  day_time = s.split
  day      = day_time.shift
  time     = DateTime.parse(day_time.shift).strftime('%H:%M')
  "#{day} #{time}"
end

.time_left(start_time, end_time) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/crunchyroll/utils.rb', line 18

def time_left(start_time, end_time)
  diff  = TimeDifference.between(start_time, end_time).in_general

  secs  = diff[:seconds].to_i
  mins  = diff[:minutes].to_i
  hours = diff[:hours  ].to_i
  days  = diff[:days   ].to_i

  if days > 0
    "#{days} days, #{hours} hours, #{mins} minutes and #{secs} seconds"
  elsif hours >  0
    "#{hours} hours, #{mins} minutes and #{secs} seconds"
  elsif mins  >  0
    "#{mins} minutes and #{secs} seconds"
  elsif secs  >= 0
    "#{secs} seconds"
  end
end