Class: TimeScales::TimeStruct
- Inherits:
-
Struct
- Object
- Struct
- TimeScales::TimeStruct
- Defined in:
- lib/time_scales/time_struct.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#minute ⇒ Object
Returns the value of attribute minute.
-
#month ⇒ Object
Returns the value of attribute month.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day
3 4 5 |
# File 'lib/time_scales/time_struct.rb', line 3 def day @day end |
#hour ⇒ Object
Returns the value of attribute hour
3 4 5 |
# File 'lib/time_scales/time_struct.rb', line 3 def hour @hour end |
#minute ⇒ Object
Returns the value of attribute minute
3 4 5 |
# File 'lib/time_scales/time_struct.rb', line 3 def minute @minute end |
#month ⇒ Object
Returns the value of attribute month
3 4 5 |
# File 'lib/time_scales/time_struct.rb', line 3 def month @month end |
#year ⇒ Object
Returns the value of attribute year
3 4 5 |
# File 'lib/time_scales/time_struct.rb', line 3 def year @year end |
Instance Method Details
#days_in_feb_of_year ⇒ Object
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 |
#normalize ⇒ Object
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 |