Module: Zakuro::Tool::RemainderComparer

Defined in:
lib/zakuro/tool/remainder_comparer.rb

Overview

RemainderComparer 大余小余比較

Constant Summary collapse

LOGGER =

Returns ロガー.

Returns:

Output::Logger.new(location: 'RemainderComparer')

Class Method Summary collapse

Class Method Details

.in_limit?(target:, start:, limit:) ⇒ True, False

大余を基準に範囲チェックをする

Parameters:

  • target (Calcuration::Cycle::AbstractRemainder)

    対象日

  • start (Calcuration::Cycle::AbstractRemainder)

    範囲開始

  • limit (Integer)

    大余上限

Returns:

  • (True)

    対象日がある

  • (False)

    対象日がない



65
66
67
68
69
# File 'lib/zakuro/tool/remainder_comparer.rb', line 65

def in_limit?(target:, start:, limit:)
  last_day = start.add_day(limit).day

  in_range_day?(target: target.day, start: start.day, last: last_day)
end

.in_range?(target:, start:, last:) ⇒ True, False

大余を基準に範囲チェックをする

次のパターンで用いる

  1. 月内(当月朔日から当月末日(来月朔日の前日)の間)に二十四節気があるか

* target: 二十四節気
* start: 当月朔日
* last: 次月朔日
  1. ある二十四節気に対象の日があるか

* target: 対象の日
* start: 二十四節気
* last: 次の二十四節気

Parameters:

  • target (Calcuration::Cycle::AbstractRemainder)

    対象日

  • start (Calcuration::Cycle::AbstractRemainder)

    範囲開始

  • last (Calcuration::Cycle::AbstractRemainder)

    範囲終了

Returns:

  • (True)

    対象日がある

  • (False)

    対象日がない



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zakuro/tool/remainder_comparer.rb', line 41

def in_range?(target:, start:, last:)
  # 『日本暦日便覧』では下記5日を没日ありとしている
  #  これは二十四節気の小余と秒が0の場合に限って、範囲を翌日にずらすことを指している
  #
  # * 貞観12年7月18日
  # * 天喜5年3月11日
  # * 寛元1年11月4日
  # * 永享2年7月26日
  # * 元和3年3月19日
  #
  last_day = last.only_day? ? last.day + 1 : last.day
  in_range_day?(target: target.day, start: start.day, last: last_day)
end