Method: When::TM::CalDate#&

Defined in:
lib/when_exe/tmptypes.rb

#&(other) ⇒ When::TM::CalDate

ユリウス日または通年が指定の剰余となる日

Parameters:

Returns:

Raises:

  • (TypeError)


700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/when_exe/tmptypes.rb', line 700

def &(other)
  raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
  case other.event
  when 'day'
  # 指定の剰余となる日
    sdn      = other & to_i
    options  = {:date=>_date_with_era(@frame.to_cal_date(sdn)), :events=>nil, :query=>@query, :validate=>:done}
    options[:precision] = When::DAY if precision < When::DAY
    result   = self.dup._copy(options)
    result.send(:_force_euqal_day, sdn-result.to_i)

  when 'year'
  # 指定の剰余となる年
    date     = @frame.send(:_decode, _date_without_era)
    date[0]  = (other & (date[0] + @frame.diff_to_CE)) - @frame.diff_to_CE
    options  = {:date=>_date_with_era(@frame.send(:_encode, date)), :events=>nil, :query=>@query}
    options[:precision] = When::YEAR if precision < When::YEAR
    return self.dup._copy(options)

  else
    raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
  end
end