Class: RubyChartEngine::Input::DateTime
- Inherits:
-
Object
- Object
- RubyChartEngine::Input::DateTime
- Defined in:
- lib/ruby_chart_engine/input/datetime.rb
Instance Attribute Summary collapse
-
#datetime ⇒ Object
readonly
Returns the value of attribute datetime.
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#hour ⇒ Object
readonly
Returns the value of attribute hour.
-
#minute ⇒ Object
readonly
Returns the value of attribute minute.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#second ⇒ Object
readonly
Returns the value of attribute second.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
-
#initialize(datetime) ⇒ DateTime
constructor
Parse datetime from various formats: - Ruby DateTime/Time object - ISO 8601 string: “2024-03-15T14:30:00” - Hash: { year: 2024, month: 3, day: 15, hour: 14, minute: 30 }.
-
#to_julian_day(timezone_offset = 0) ⇒ Object
Convert to Julian Day Number for Swiss Ephemeris.
Constructor Details
#initialize(datetime) ⇒ DateTime
Parse datetime from various formats:
-
Ruby DateTime/Time object
-
ISO 8601 string: “2024-03-15T14:30:00”
-
Hash: { year: 2024, month: 3, day: 15, hour: 14, minute: 30 }
12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 12 def initialize(datetime) @datetime = parse_datetime(datetime) @year = @datetime.year @month = @datetime.month @day = @datetime.day @hour = @datetime.hour @minute = @datetime.min @second = @datetime.sec end |
Instance Attribute Details
#datetime ⇒ Object (readonly)
Returns the value of attribute datetime.
6 7 8 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6 def datetime @datetime end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
6 7 8 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6 def day @day end |
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
6 7 8 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6 def hour @hour end |
#minute ⇒ Object (readonly)
Returns the value of attribute minute.
6 7 8 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6 def minute @minute end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
6 7 8 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6 def month @month end |
#second ⇒ Object (readonly)
Returns the value of attribute second.
6 7 8 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6 def second @second end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
6 7 8 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6 def year @year end |
Instance Method Details
#to_julian_day(timezone_offset = 0) ⇒ Object
Convert to Julian Day Number for Swiss Ephemeris
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_chart_engine/input/datetime.rb', line 23 def to_julian_day(timezone_offset = 0) # Adjust for timezone offset (in hours) adjusted_time = @datetime - (timezone_offset * 3600) # Use Swiss Ephemeris to calculate Julian Day # swe_julday takes 4 arguments: year, month, day, hour (as decimal) Swe4r.swe_julday( adjusted_time.year, adjusted_time.month, adjusted_time.day, adjusted_time.hour + (adjusted_time.min / 60.0) + (adjusted_time.sec / 3600.0) ) end |