Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Date.jd
(::Integer jd, ?::Integer start) -> ::Date
Date.jd(jd = 0, start = Date::ITALY) → date
ext/date/date_core.c
View on GitHub ↗
static VALUE
date_s_jd(int argc, VALUE *argv, VALUE klass)
{
VALUE vjd, vsg, jd, fr, fr2, ret;
double sg;
rb_scan_args(argc, argv, "02", &vjd, &vsg);
jd = INT2FIX(0);
fr2 = INT2FIX(0);
sg = DEFAULT_SG;
switch (argc) {
case 2:
val2sg(vsg, sg);
case 1:
check_numeric(vjd, "jd");
num2num_with_frac(jd, positive_inf);
}
{
VALUE nth;
int rjd;
decode_jd(jd, &nth, &rjd);
ret = d_simple_new_internal(klass,
nth, rjd,
sg,
0, 0, 0,
HAVE_JD);
}
add_frac();
return ret;
}
Returns a new Date object formed from the arguments:
Example
Date.jd(2451944).to_s # => "2001-02-03" Date.jd(2451945).to_s # => "2001-02-04" Date.jd(0).to_s # => "-4712-01-01"
The returned date is:
-
Gregorian, if the argument is greater than or equal to
start:ExampleDate::ITALY # => 2299161 Date.jd(Date::ITALY).gregorian? # => true Date.jd(Date::ITALY + 1).gregorian? # => true
-
Julian, otherwise
ExampleDate.jd(Date::ITALY - 1).julian? # => true
See argument start.
Related: Date.new.