APIdock / Ruby
/
method

ordinal

ruby latest stable - Class: Date
ordinal(p1 = v1, p2 = v2, p3 = v3)
public

Creates a date object denoting the given ordinal date.

The day of year should be a negative or a positive number (as a relative day from the end of year when negative). It should not be zero.

Date .ordinal (2001) #=> #<Date: 2001年01月01日 ...>
Date .ordinal (2001,34) #=> #<Date: 2001年02月03日 ...>
Date .ordinal (2001,-1) #=> #<Date: 2001年12月31日 ...>

See also ::jd and ::new.

static VALUE
date_s_ordinal(int argc, VALUE *argv, VALUE klass)
{
 VALUE vy, vd, vsg, y, fr, fr2, ret;
 int d;
 double sg;
 rb_scan_args(argc, argv, "03", &vy, &vd, &vsg);
 y = INT2FIX(-4712);
 d = 1;
 fr2 = INT2FIX(0);
 sg = DEFAULT_SG;
 switch (argc) {
 case 3:
 val2sg(vsg, sg);
 case 2:
 num2int_with_frac(d, positive_inf);
 case 1:
 y = vy;
 }
 {
 VALUE nth;
 int ry, rd, rjd, ns;
 if (!valid_ordinal_p(y, d, sg,
 &nth, &ry,
 &rd, &rjd,
 &ns))
 rb_raise(rb_eArgError, "invalid date");
 ret = d_simple_new_internal(klass,
 nth, rjd,
 sg,
 0, 0, 0,
 HAVE_JD);
 }
 add_frac();
 return ret;
}

AltStyle によって変換されたページ (->オリジナル) /