require 'date/performance'

# Date_performance does not properly handle offsets and dies when
# the spreadsheet gem parses a date.
class Date
  def self.ajd_to_jd(ajd, of=0)
    (ajd + of + HALF_DAYS_IN_DAY).divmod(1)
  end
end

#/*
# * Date::ajd_to_jd(ajd, of=0)
# *
# * TODO: handle offsets properly.
# *
# * Ruby Implementation: (ajd + of + 1.to_r/2).divmod(1)
# */
#static VALUE
#rb_date_ajd_to_jd(int argc, VALUE * argv, VALUE self)
#{
#  VALUE ajd = argv[0];
#  VALUE of  = (argc == 2 ? argv[1] : INT2FIX(0));
#  long den = FIX2LONG(rb_funcall(ajd, id_denominator, 0));
#  long num = FIX2LONG(rb_funcall(ajd, id_numerator, 0));
#  if ( den == 2 && of == INT2FIX(0) ) {
#    /* fast path */
#    return rb_ary_new3(2, LONG2FIX((num + 1) / 2), ra_one_half);
#  }else{
#    VALUE result = rb_funcall(ajd, id_add, 1, of);
#    result = rb_funcall(result, id_add, 1, ra_one_half);
#    return rb_funcall(result, id_divmod, 1, LONG2FIX(1));
#  }
#}