Class: RubyChartEngine::Input::DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_chart_engine/input/datetime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#datetimeObject (readonly)

Returns the value of attribute datetime.



6
7
8
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6

def datetime
  @datetime
end

#dayObject (readonly)

Returns the value of attribute day.



6
7
8
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6

def day
  @day
end

#hourObject (readonly)

Returns the value of attribute hour.



6
7
8
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6

def hour
  @hour
end

#minuteObject (readonly)

Returns the value of attribute minute.



6
7
8
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6

def minute
  @minute
end

#monthObject (readonly)

Returns the value of attribute month.



6
7
8
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6

def month
  @month
end

#secondObject (readonly)

Returns the value of attribute second.



6
7
8
# File 'lib/ruby_chart_engine/input/datetime.rb', line 6

def second
  @second
end

#yearObject (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