APIdock / Ruby
/
method

civil

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

Creates a date object denoting the given calendar date.

In this class, BCE years are counted astronomically. Thus, the year before the year 1 is the year zero, and the year preceding the year zero is the year -1. The month and the day of month should be a negative or a positive number (as a relative month/day from the end of year/month when negative). They should not be zero.

The last argument should be a Julian day number which denotes the day of calendar reform. Date::ITALY (2299161=1582年10月15日), Date::ENGLAND (2361222=1752年09月14日), Date::GREGORIAN (the proleptic Gregorian calendar) and Date::JULIAN (the proleptic Julian calendar) can be specified as a day of calendar reform.

Date .new (2001) #=> #<Date: 2001年01月01日 ...>
Date .new (2001,2,3) #=> #<Date: 2001年02月03日 ...>
Date .new (2001,2,-1) #=> #<Date: 2001年02月28日 ...>

See also ::jd.

static VALUE
date_s_civil(int argc, VALUE *argv, VALUE klass)
{
 VALUE vy, vm, vd, vsg, y, fr, fr2, ret;
 int m, d;
 double sg;
 rb_scan_args(argc, argv, "04", &vy, &vm, &vd, &vsg);
 y = INT2FIX(-4712);
 m = 1;
 d = 1;
 fr2 = INT2FIX(0);
 sg = DEFAULT_SG;
 switch (argc) {
 case 4:
 val2sg(vsg, sg);
 case 3:
 num2int_with_frac(d, positive_inf);
 case 2:
 m = NUM2INT(vm);
 case 1:
 y = vy;
 }
 if (guess_style(y, sg) < 0) {
 VALUE nth;
 int ry, rm, rd;
 if (!valid_gregorian_p(y, m, d,
 &nth, &ry,
 &rm, &rd))
 rb_raise(rb_eArgError, "invalid date");
 ret = d_simple_new_internal(klass,
 nth, 0,
 sg,
 ry, rm, rd,
 HAVE_CIVIL);
 }
 else {
 VALUE nth;
 int ry, rm, rd, rjd, ns;
 if (!valid_civil_p(y, m, d, sg,
 &nth, &ry,
 &rm, &rd, &rjd,
 &ns))
 rb_raise(rb_eArgError, "invalid date");
 ret = d_simple_new_internal(klass,
 nth, rjd,
 sg,
 ry, rm, rd,
 HAVE_JD | HAVE_CIVIL);
 }
 add_frac();
 return ret;
}

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