Class: NavigationLight::Time

Inherits:
ApplicationRecord show all
Defined in:
app/models/navigation_light/time.rb

Constant Summary collapse

ABOUT_TIME_COLUMNS =
[:minute, :hour, :day, :week, :month, :quarter, :year]

Class Method Summary collapse

Methods inherited from ApplicationRecord

#ejection

Class Method Details

.index_day(time: ::Time.now) ⇒ Object



32
33
34
# File 'app/models/navigation_light/time.rb', line 32

def index_day(time: ::Time.now)
  time.strftime('%Y%m%d').to_i
end

.index_hour(time: ::Time.now) ⇒ Object



28
29
30
# File 'app/models/navigation_light/time.rb', line 28

def index_hour(time: ::Time.now)
  time.strftime('%H').to_i
end

.index_minute(time: ::Time.now) ⇒ Object



24
25
26
# File 'app/models/navigation_light/time.rb', line 24

def index_minute(time: ::Time.now)
  time.strftime('%M').to_i
end

.index_month(time: ::Time.now) ⇒ Object



36
37
38
# File 'app/models/navigation_light/time.rb', line 36

def index_month(time: ::Time.now)
  time.strftime('%Y%m').to_i
end

.index_quarter(time: ::Time.now) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'app/models/navigation_light/time.rb', line 61

def index_quarter(time: ::Time.now)
  quarter = case time.strftime('%m').to_i
    when 1,2,3 then 1
    when 4,5,6 then 2
    when 7,8,9 then 3
    when 10,11,12 then 4
  end
  return (time.strftime('%Y') << "0" << quarter.to_s).to_i
end

.index_week(time: ::Time.now) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/navigation_light/time.rb', line 40

def index_week(time: ::Time.now)
  year = time.strftime('%Y').to_i
  week = time.strftime('%W').to_i
  num = Date.commercial( year.to_i, 52, 1 ).strftime('%W')
  if num.to_i == 52
    if week == 0
      return ((year-1).to_s << "52").to_i
    elsif week == 53
      return ((year+1).to_s << "01").to_i
    else
      return time.strftime('%Y%W').to_i
    end
  else
    if week + 1 == 53
      return ((year+1).to_s << "01").to_i
    else
      return time.strftime('%Y%W').to_i + 1
    end
  end
end

.index_year(time: ::Time.now) ⇒ Object



71
72
73
# File 'app/models/navigation_light/time.rb', line 71

def index_year(time: ::Time.now)
  time.strftime('%Y').to_i
end