static VALUE
datetime_s_civil(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vm, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
int m, d, h, min, s, rof;
double sg;
rb_scan_args(argc, argv, "08", &vy, &vm, &vd, &vh, &vmin, &vs, &vof, &vsg);
y = INT2FIX(-4712);
m = 1;
d = 1;
h = min = s = 0;
fr2 = INT2FIX(0);
rof = 0;
sg = DEFAULT_SG;
switch (argc) {
case 8:
val2sg(vsg, sg);
case 7:
val2off(vof, rof);
case 6:
num2int_with_frac(s, positive_inf);
case 5:
num2int_with_frac(min, 5);
case 4:
num2int_with_frac(h, 4);
case 3:
num2int_with_frac(d, 3);
case 2:
m = NUM2INT(vm);
case 1:
y = vy;
}
if (guess_style(y, sg) < 0) {
VALUE nth;
int ry, rm, rd, rh, rmin, rs;
if (!valid_gregorian_p(y, m, d,
&nth, &ry,
&rm, &rd))
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
ret = d_complex_new_internal(klass,
nth, 0,
0, INT2FIX(0),
rof, sg,
ry, rm, rd,
rh, rmin, rs,
HAVE_CIVIL | HAVE_TIME);
}
else {
VALUE nth;
int ry, rm, rd, rh, rmin, rs, rjd, rjd2, ns;
if (!valid_civil_p(y, m, d, sg,
&nth, &ry,
&rm, &rd, &rjd,
&ns))
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
rjd2 = jd_local_to_utc(rjd,
time_to_df(rh, rmin, rs),
rof);
ret = d_complex_new_internal(klass,
nth, rjd2,
0, INT2FIX(0),
rof, sg,
ry, rm, rd,
rh, rmin, rs,
HAVE_JD | HAVE_CIVIL | HAVE_TIME);
}
add_frac();
return ret;
}