Module: Sekki24

Defined in:
lib/sekki24.rb,
lib/sekki24.rb,
lib/sekki24/kou.rb,
lib/sekki24/term.rb,
lib/sekki24/names.rb,
lib/sekki24/solar.rb,
lib/sekki24/finder.rb,
lib/sekki24/delta_t.rb,
lib/sekki24/version.rb,
lib/sekki24/nutation.rb,
lib/sekki24/zassetsu.rb,
lib/sekki24/kou_names.rb,
lib/sekki24/lunar/moon.rb,
lib/sekki24/solar/fast.rb,
lib/sekki24/time_scale.rb,
lib/sekki24/solar/precise.rb,
lib/sekki24/lunisolar/date.rb,
lib/sekki24/lunisolar/month.rb,
lib/sekki24/seventy_two_kou.rb,
lib/sekki24/zassetsu_calendar.rb,
lib/sekki24/lunar/phase_finder.rb,
lib/sekki24/lunisolar/calendar.rb,
lib/sekki24/solar/vsop87_earth.rb,
lib/sekki24/lunar/periodic_terms.rb,
lib/sekki24/lunisolar/month_builder.rb

Defined Under Namespace

Modules: DeltaT, Finder, KouNames, Lunar, Lunisolar, Names, Nutation, SeventyTwoKou, Solar, TimeScale, ZassetsuCalendar Classes: Error, Kou, Term, Zassetsu

Constant Summary collapse

MIN_YEAR =
1900
MAX_YEAR =
2100
DEFAULT_TIMEZONE =
"+00:00"
DEFAULT_PRECISION =
:precise
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.clear_cache!Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sekki24.rb', line 69

def clear_cache!
  @cache_mutex.synchronize do
    @year_cache.clear
    @candidate_cache.clear
  end
  SeventyTwoKou.clear_cache! if defined?(SeventyTwoKou)
  ZassetsuCalendar.clear_cache! if defined?(ZassetsuCalendar)
  Lunar::PhaseFinder.clear_cache! if defined?(Lunar::PhaseFinder)
  Lunisolar::Calendar.clear_cache! if defined?(Lunisolar::Calendar)
  nil
end

.current(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



43
44
45
46
47
# File 'lib/sekki24.rb', line 43

def current(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  instant = ensure_time(time)
  navigation_terms(instant, tz, precision).select { |entry| entry.time <= instant }.max ||
    raise(RangeError, "no current solar term in the supported range")
end

.current_kou(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



117
118
119
# File 'lib/sekki24/seventy_two_kou.rb', line 117

def current_kou(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  SeventyTwoKou.current(time, tz: tz, precision: precision)
end

.current_zassetsu(date = Date.today, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



172
173
174
# File 'lib/sekki24/zassetsu_calendar.rb', line 172

def current_zassetsu(date = Date.today, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  ZassetsuCalendar.active(date, tz: tz, precision: precision)
end

.gregorian(lunar_year, month, day, leap: false, tz: DEFAULT_TIMEZONE) ⇒ Object



125
126
127
# File 'lib/sekki24/lunisolar/calendar.rb', line 125

def gregorian(lunar_year, month, day, leap: false, tz: DEFAULT_TIMEZONE)
  Lunisolar::Calendar.to_gregorian(lunar_year, month, day, leap: leap, tz: tz)
end

.kou(year, ordinal, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



113
114
115
# File 'lib/sekki24/seventy_two_kou.rb', line 113

def kou(year, ordinal, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  SeventyTwoKou.fetch(year, ordinal, tz: tz, precision: precision)
end

.kou_year(year, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



109
110
111
# File 'lib/sekki24/seventy_two_kou.rb', line 109

def kou_year(year, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  SeventyTwoKou.year(year, tz: tz, precision: precision)
end

.lunisolar(value, tz: DEFAULT_TIMEZONE) ⇒ Object



117
118
119
# File 'lib/sekki24/lunisolar/calendar.rb', line 117

def lunisolar(value, tz: DEFAULT_TIMEZONE)
  Lunisolar::Calendar.convert(value, tz: tz)
end

.lunisolar_year(year, tz: DEFAULT_TIMEZONE) ⇒ Object



121
122
123
# File 'lib/sekki24/lunisolar/calendar.rb', line 121

def lunisolar_year(year, tz: DEFAULT_TIMEZONE)
  Lunisolar::Calendar.year(year, tz: tz)
end

.moon_longitude(time) ⇒ Object



153
154
155
# File 'lib/sekki24/lunar/phase_finder.rb', line 153

def moon_longitude(time)
  Lunar::Moon.longitude(TimeScale.utc_to_jde(time))
end

.new_moon_after(time = Time.now) ⇒ Object



149
150
151
# File 'lib/sekki24/lunar/phase_finder.rb', line 149

def new_moon_after(time = Time.now)
  Lunar::PhaseFinder.new_moon_after(time)
end

.new_moon_before(time = Time.now) ⇒ Object



145
146
147
# File 'lib/sekki24/lunar/phase_finder.rb', line 145

def new_moon_before(time = Time.now)
  Lunar::PhaseFinder.new_moon_before(time)
end

.new_moons(year, tz: DEFAULT_TIMEZONE) ⇒ Object



141
142
143
# File 'lib/sekki24/lunar/phase_finder.rb', line 141

def new_moons(year, tz: DEFAULT_TIMEZONE)
  Lunar::PhaseFinder.new_moons(year, tz: tz)
end

.next_kou(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



121
122
123
# File 'lib/sekki24/seventy_two_kou.rb', line 121

def next_kou(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  SeventyTwoKou.next_kou(time, tz: tz, precision: precision)
end

.next_term(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



49
50
51
52
53
# File 'lib/sekki24.rb', line 49

def next_term(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  instant = ensure_time(time)
  navigation_terms(instant, tz, precision).select { |entry| entry.time > instant }.min ||
    raise(RangeError, "no next solar term in the supported range")
end

.on(date, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/sekki24.rb', line 61

def on(date, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  unless date.is_a?(Date)
    raise TypeError, "expected Date, got #{date.class}"
  end

  year(date.year, tz: tz, precision: precision).find { |entry| entry.to_date == date }
end

.prev_kou(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



125
126
127
# File 'lib/sekki24/seventy_two_kou.rb', line 125

def prev_kou(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  SeventyTwoKou.previous(time, tz: tz, precision: precision)
end

.prev_term(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



55
56
57
58
59
# File 'lib/sekki24.rb', line 55

def prev_term(time = Time.now, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  instant = ensure_time(time)
  navigation_terms(instant, tz, precision).select { |entry| entry.time < instant }.max ||
    raise(RangeError, "no previous solar term in the supported range")
end

.term(year, key, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



38
39
40
41
# File 'lib/sekki24.rb', line 38

def term(year, key, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  definition = Names.fetch(key)
  self.year(year, tz: tz, precision: precision).find { |entry| entry.key == definition.key }
end

.year(year, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/sekki24.rb', line 27

def year(year, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  calendar_year = validate_year(year)
  mode, solar = resolve_precision(precision)
  cache_key = [calendar_year, TimeScale.timezone_key(tz), mode].freeze
  cached = @cache_mutex.synchronize { @year_cache[cache_key] }
  return cached if cached

  calculated = calculate_year(calendar_year, tz, mode, solar)
  @cache_mutex.synchronize { @year_cache[cache_key] ||= calculated }
end

.zassetsu(year, key, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



164
165
166
# File 'lib/sekki24/zassetsu_calendar.rb', line 164

def zassetsu(year, key, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  ZassetsuCalendar.fetch(year, key, tz: tz, precision: precision)
end

.zassetsu_on(date, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



168
169
170
# File 'lib/sekki24/zassetsu_calendar.rb', line 168

def zassetsu_on(date, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  ZassetsuCalendar.on(date, tz: tz, precision: precision)
end

.zassetsu_year(year, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION) ⇒ Object



160
161
162
# File 'lib/sekki24/zassetsu_calendar.rb', line 160

def zassetsu_year(year, tz: DEFAULT_TIMEZONE, precision: DEFAULT_PRECISION)
  ZassetsuCalendar.year(year, tz: tz, precision: precision)
end