Class: TimeScales::TimeStruct

Inherits:
Struct
  • Object
show all
Defined in:
lib/time_scales/time_struct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dayObject

Returns the value of attribute day

Returns:

  • (Object)

    the current value of day



3
4
5
# File 'lib/time_scales/time_struct.rb', line 3

def day
  @day
end

#hourObject

Returns the value of attribute hour

Returns:

  • (Object)

    the current value of hour



3
4
5
# File 'lib/time_scales/time_struct.rb', line 3

def hour
  @hour
end

#minuteObject

Returns the value of attribute minute

Returns:

  • (Object)

    the current value of minute



3
4
5
# File 'lib/time_scales/time_struct.rb', line 3

def minute
  @minute
end

#monthObject

Returns the value of attribute month

Returns:

  • (Object)

    the current value of month



3
4
5
# File 'lib/time_scales/time_struct.rb', line 3

def month
  @month
end

#yearObject

Returns the value of attribute year

Returns:

  • (Object)

    the current value of year



3
4
5
# File 'lib/time_scales/time_struct.rb', line 3

def year
  @year
end

Instance Method Details

#days_in_feb_of_yearObject



61
62
63
64
# File 'lib/time_scales/time_struct.rb', line 61

def days_in_feb_of_year
  t = Time.new(year, 3, 1)
  t.yday - 32
end

#normalizeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/time_scales/time_struct.rb', line 11

def normalize
  return unless year && day
  self.month ||= 1
  if month == 1 && day > 31
    self.month = 2
    self.day -= 31
  end
  feb_days = days_in_feb_of_year
  if month == 2 && day > feb_days
    self.month = 3
    self.day -= feb_days
  end
  if month == 3 && day > 31
    self.month  = 4
    self.day -= 31
  end
  if month == 4 && day > 30
    self.month = 5
    self.day -= 30
  end
  if month == 5 && day > 31
    self.month = 6
    self.day -= 31
  end
  if month == 6 && day > 30
    self.month = 7
    self.day -= 30
  end
  if month == 7 && day > 31
    self.month = 8
    self.day -= 31
  end
  if month == 8 && day > 31
    self.month = 9
    self.day -= 31
  end
  if month == 9 && day > 30
    self.month = 10
    self.day -= 30
  end
  if month == 10 && day > 31
    self.month = 11
    self.day -= 31
  end
  if month == 11 && day > 30
    self.month = 12
    self.day -= 30
  end
end