date 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of date might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/date/date_core.c +113 -57
- data/ext/date/date_parse.c +96 -75
- data/ext/date/date_strptime.c +2 -4
- data/ext/date/prereq.mk +5 -1
- data/ext/date/zonetab.h +1364 -697
- data/ext/date/zonetab.list +146 -0
- data/lib/date.rb +4 -0
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eab8784935560e8ccb987a8c6349a055e6a81a9d0350f3c6bd3bc82457132483
|
4
|
+
data.tar.gz: 37963d8ab0021e73ed0afe0c4f53146f95e341f6afce255e0394747888e54cb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 056c3e48e40d7e4f07bae0f4db9ce1b3216aa4850e06461880209d5fbbadb1e81a57e4990920bf331d95fe85bb5212210dc296a7f2fac4d142e193753af1e9e7
|
7
|
+
data.tar.gz: e9304903feae90afd9109a48fc5fab1eee21346c99822aa52318414860d8e9763a96978d64ba11f0ab9ea39bb4922250174f6d712e11086e2bdd5d18928fbbcf
|
data/ext/date/date_core.c
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
static ID id_cmp, id_le_p, id_ge_p, id_eqeq_p;
|
24
24
|
static VALUE cDate, cDateTime;
|
25
|
+
static VALUE eDateError;
|
25
26
|
static VALUE half_days_in_day, day_in_nanoseconds;
|
26
27
|
static double positive_inf, negative_inf;
|
27
28
|
|
@@ -54,6 +55,14 @@ static double positive_inf, negative_inf;
|
|
54
55
|
static VALUE date_initialize(int argc, VALUE *argv, VALUE self);
|
55
56
|
static VALUE datetime_initialize(int argc, VALUE *argv, VALUE self);
|
56
57
|
|
58
|
+
#define RETURN_FALSE_UNLESS_NUMERIC(obj) if(!RTEST(rb_obj_is_kind_of((obj), rb_cNumeric))) return Qfalse
|
59
|
+
inline static void
|
60
|
+
check_numeric(VALUE obj, const char* field) {
|
61
|
+
if(!RTEST(rb_obj_is_kind_of(obj, rb_cNumeric))) {
|
62
|
+
rb_raise(rb_eTypeError, "invalid %s (not numeric)", field);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
57
66
|
inline static int
|
58
67
|
f_cmp(VALUE x, VALUE y)
|
59
68
|
{
|
@@ -2470,6 +2479,7 @@ date_s_valid_jd_p(int argc, VALUE *argv, VALUE klass)
|
|
2470
2479
|
|
2471
2480
|
rb_scan_args(argc, argv, "11", &vjd, &vsg);
|
2472
2481
|
|
2482
|
+
RETURN_FALSE_UNLESS_NUMERIC(vjd);
|
2473
2483
|
argv2[0] = vjd;
|
2474
2484
|
if (argc < 2)
|
2475
2485
|
argv2[1] = INT2FIX(DEFAULT_SG);
|
@@ -2545,9 +2555,12 @@ date_s__valid_civil_p(int argc, VALUE *argv, VALUE klass)
|
|
2545
2555
|
* Date.valid_date?(year, month, mday[, start=Date::ITALY]) -> bool
|
2546
2556
|
*
|
2547
2557
|
* Returns true if the given calendar date is valid, and false if not.
|
2558
|
+
* Valid in this context is whether the arguments passed to this
|
2559
|
+
* method would be accepted by ::new.
|
2548
2560
|
*
|
2549
2561
|
* Date.valid_date?(2001,2,3) #=> true
|
2550
2562
|
* Date.valid_date?(2001,2,29) #=> false
|
2563
|
+
* Date.valid_date?(2001,2,-1) #=> true
|
2551
2564
|
*
|
2552
2565
|
* See also ::jd and ::civil.
|
2553
2566
|
*/
|
@@ -2559,6 +2572,9 @@ date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
|
|
2559
2572
|
|
2560
2573
|
rb_scan_args(argc, argv, "31", &vy, &vm, &vd, &vsg);
|
2561
2574
|
|
2575
|
+
RETURN_FALSE_UNLESS_NUMERIC(vy);
|
2576
|
+
RETURN_FALSE_UNLESS_NUMERIC(vm);
|
2577
|
+
RETURN_FALSE_UNLESS_NUMERIC(vd);
|
2562
2578
|
argv2[0] = vy;
|
2563
2579
|
argv2[1] = vm;
|
2564
2580
|
argv2[2] = vd;
|
@@ -2640,6 +2656,8 @@ date_s_valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
|
|
2640
2656
|
|
2641
2657
|
rb_scan_args(argc, argv, "21", &vy, &vd, &vsg);
|
2642
2658
|
|
2659
|
+
RETURN_FALSE_UNLESS_NUMERIC(vy);
|
2660
|
+
RETURN_FALSE_UNLESS_NUMERIC(vd);
|
2643
2661
|
argv2[0] = vy;
|
2644
2662
|
argv2[1] = vd;
|
2645
2663
|
if (argc < 3)
|
@@ -2722,6 +2740,9 @@ date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
|
|
2722
2740
|
|
2723
2741
|
rb_scan_args(argc, argv, "31", &vy, &vw, &vd, &vsg);
|
2724
2742
|
|
2743
|
+
RETURN_FALSE_UNLESS_NUMERIC(vy);
|
2744
|
+
RETURN_FALSE_UNLESS_NUMERIC(vw);
|
2745
|
+
RETURN_FALSE_UNLESS_NUMERIC(vd);
|
2725
2746
|
argv2[0] = vy;
|
2726
2747
|
argv2[1] = vw;
|
2727
2748
|
argv2[2] = vd;
|
@@ -2903,6 +2924,7 @@ date_s_julian_leap_p(VALUE klass, VALUE y)
|
|
2903
2924
|
VALUE nth;
|
2904
2925
|
int ry;
|
2905
2926
|
|
2927
|
+
check_numeric(y, "year");
|
2906
2928
|
decode_year(y, +1, &nth, &ry);
|
2907
2929
|
return f_boolcast(c_julian_leap_p(ry));
|
2908
2930
|
}
|
@@ -2924,6 +2946,7 @@ date_s_gregorian_leap_p(VALUE klass, VALUE y)
|
|
2924
2946
|
VALUE nth;
|
2925
2947
|
int ry;
|
2926
2948
|
|
2949
|
+
check_numeric(y, "year");
|
2927
2950
|
decode_year(y, -1, &nth, &ry);
|
2928
2951
|
return f_boolcast(c_gregorian_leap_p(ry));
|
2929
2952
|
}
|
@@ -3047,7 +3070,7 @@ old_to_new(VALUE ajd, VALUE of, VALUE sg,
|
|
3047
3070
|
*rsg = NUM2DBL(sg);
|
3048
3071
|
|
3049
3072
|
if (*rdf < 0 || *rdf >= DAY_IN_SECONDS)
|
3050
|
-
rb_raise(
|
3073
|
+
rb_raise(eDateError, "invalid day fraction");
|
3051
3074
|
|
3052
3075
|
if (f_lt_p(*rsf, INT2FIX(0)) ||
|
3053
3076
|
f_ge_p(*rsf, INT2FIX(SECOND_IN_NANOSECONDS)))
|
@@ -3209,7 +3232,7 @@ do {\
|
|
3209
3232
|
s = s##_trunc(v##s, &fr);\
|
3210
3233
|
if (f_nonzero_p(fr)) {\
|
3211
3234
|
if (argc > n)\
|
3212
|
-
rb_raise(
|
3235
|
+
rb_raise(eDateError, "invalid fraction");\
|
3213
3236
|
fr2 = fr;\
|
3214
3237
|
}\
|
3215
3238
|
} while (0)
|
@@ -3219,7 +3242,7 @@ do {\
|
|
3219
3242
|
s = NUM2INT(s##_trunc(v##s, &fr));\
|
3220
3243
|
if (f_nonzero_p(fr)) {\
|
3221
3244
|
if (argc > n)\
|
3222
|
-
rb_raise(
|
3245
|
+
rb_raise(eDateError, "invalid fraction");\
|
3223
3246
|
fr2 = fr;\
|
3224
3247
|
}\
|
3225
3248
|
} while (0)
|
@@ -3278,6 +3301,7 @@ date_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
3278
3301
|
case 2:
|
3279
3302
|
val2sg(vsg, sg);
|
3280
3303
|
case 1:
|
3304
|
+
check_numeric(vjd, "jd");
|
3281
3305
|
num2num_with_frac(jd, positive_inf);
|
3282
3306
|
}
|
3283
3307
|
|
@@ -3330,8 +3354,10 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
3330
3354
|
case 3:
|
3331
3355
|
val2sg(vsg, sg);
|
3332
3356
|
case 2:
|
3357
|
+
check_numeric(vd, "yday");
|
3333
3358
|
num2int_with_frac(d, positive_inf);
|
3334
3359
|
case 1:
|
3360
|
+
check_numeric(vy, "year");
|
3335
3361
|
y = vy;
|
3336
3362
|
}
|
3337
3363
|
|
@@ -3343,7 +3369,7 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
3343
3369
|
&nth, &ry,
|
3344
3370
|
&rd, &rjd,
|
3345
3371
|
&ns))
|
3346
|
-
rb_raise(
|
3372
|
+
rb_raise(eDateError, "invalid date");
|
3347
3373
|
|
3348
3374
|
ret = d_simple_new_internal(klass,
|
3349
3375
|
nth, rjd,
|
@@ -3410,10 +3436,13 @@ date_initialize(int argc, VALUE *argv, VALUE self)
|
|
3410
3436
|
case 4:
|
3411
3437
|
val2sg(vsg, sg);
|
3412
3438
|
case 3:
|
3439
|
+
check_numeric(vd, "day");
|
3413
3440
|
num2int_with_frac(d, positive_inf);
|
3414
3441
|
case 2:
|
3442
|
+
check_numeric(vm, "month");
|
3415
3443
|
m = NUM2INT(vm);
|
3416
3444
|
case 1:
|
3445
|
+
check_numeric(vy, "year");
|
3417
3446
|
y = vy;
|
3418
3447
|
}
|
3419
3448
|
|
@@ -3424,7 +3453,7 @@ date_initialize(int argc, VALUE *argv, VALUE self)
|
|
3424
3453
|
if (!valid_gregorian_p(y, m, d,
|
3425
3454
|
&nth, &ry,
|
3426
3455
|
&rm, &rd))
|
3427
|
-
rb_raise(
|
3456
|
+
rb_raise(eDateError, "invalid date");
|
3428
3457
|
|
3429
3458
|
set_to_simple(self, dat, nth, 0, sg, ry, rm, rd, HAVE_CIVIL);
|
3430
3459
|
}
|
@@ -3436,7 +3465,7 @@ date_initialize(int argc, VALUE *argv, VALUE self)
|
|
3436
3465
|
&nth, &ry,
|
3437
3466
|
&rm, &rd, &rjd,
|
3438
3467
|
&ns))
|
3439
|
-
rb_raise(
|
3468
|
+
rb_raise(eDateError, "invalid date");
|
3440
3469
|
|
3441
3470
|
set_to_simple(self, dat, nth, rjd, sg, ry, rm, rd, HAVE_JD | HAVE_CIVIL);
|
3442
3471
|
}
|
@@ -3480,10 +3509,13 @@ date_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
3480
3509
|
case 4:
|
3481
3510
|
val2sg(vsg, sg);
|
3482
3511
|
case 3:
|
3512
|
+
check_numeric(vd, "cwday");
|
3483
3513
|
num2int_with_frac(d, positive_inf);
|
3484
3514
|
case 2:
|
3515
|
+
check_numeric(vw, "cweek");
|
3485
3516
|
w = NUM2INT(vw);
|
3486
3517
|
case 1:
|
3518
|
+
check_numeric(vy, "year");
|
3487
3519
|
y = vy;
|
3488
3520
|
}
|
3489
3521
|
|
@@ -3495,7 +3527,7 @@ date_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
3495
3527
|
&nth, &ry,
|
3496
3528
|
&rw, &rd, &rjd,
|
3497
3529
|
&ns))
|
3498
|
-
rb_raise(
|
3530
|
+
rb_raise(eDateError, "invalid date");
|
3499
3531
|
|
3500
3532
|
ret = d_simple_new_internal(klass,
|
3501
3533
|
nth, rjd,
|
@@ -3545,7 +3577,7 @@ date_s_weeknum(int argc, VALUE *argv, VALUE klass)
|
|
3545
3577
|
&nth, &ry,
|
3546
3578
|
&rw, &rd, &rjd,
|
3547
3579
|
&ns))
|
3548
|
-
rb_raise(
|
3580
|
+
rb_raise(eDateError, "invalid date");
|
3549
3581
|
|
3550
3582
|
ret = d_simple_new_internal(klass,
|
3551
3583
|
nth, rjd,
|
@@ -3594,7 +3626,7 @@ date_s_nth_kday(int argc, VALUE *argv, VALUE klass)
|
|
3594
3626
|
&nth, &ry,
|
3595
3627
|
&rm, &rn, &rk, &rjd,
|
3596
3628
|
&ns))
|
3597
|
-
rb_raise(
|
3629
|
+
rb_raise(eDateError, "invalid date");
|
3598
3630
|
|
3599
3631
|
ret = d_simple_new_internal(klass,
|
3600
3632
|
nth, rjd,
|
@@ -3692,7 +3724,7 @@ rt_rewrite_frags(VALUE hash)
|
|
3692
3724
|
{
|
3693
3725
|
VALUE seconds;
|
3694
3726
|
|
3695
|
-
seconds =
|
3727
|
+
seconds = del_hash("seconds");
|
3696
3728
|
if (!NIL_P(seconds)) {
|
3697
3729
|
VALUE offset, d, h, min, s, fr;
|
3698
3730
|
|
@@ -3717,7 +3749,6 @@ rt_rewrite_frags(VALUE hash)
|
|
3717
3749
|
set_hash("min", min);
|
3718
3750
|
set_hash("sec", s);
|
3719
3751
|
set_hash("sec_fraction", fr);
|
3720
|
-
del_hash("seconds");
|
3721
3752
|
}
|
3722
3753
|
return hash;
|
3723
3754
|
}
|
@@ -4142,7 +4173,7 @@ d_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
4142
4173
|
}
|
4143
4174
|
|
4144
4175
|
if (NIL_P(hash))
|
4145
|
-
rb_raise(
|
4176
|
+
rb_raise(eDateError, "invalid date");
|
4146
4177
|
|
4147
4178
|
if (NIL_P(ref_hash("jd")) &&
|
4148
4179
|
NIL_P(ref_hash("yday")) &&
|
@@ -4159,7 +4190,7 @@ d_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
4159
4190
|
}
|
4160
4191
|
|
4161
4192
|
if (NIL_P(jd))
|
4162
|
-
rb_raise(
|
4193
|
+
rb_raise(eDateError, "invalid date");
|
4163
4194
|
{
|
4164
4195
|
VALUE nth;
|
4165
4196
|
int rjd;
|
@@ -4214,12 +4245,10 @@ date_s__strptime_internal(int argc, VALUE *argv, VALUE klass,
|
|
4214
4245
|
|
4215
4246
|
if (!NIL_P(zone)) {
|
4216
4247
|
rb_enc_copy(zone, vstr);
|
4217
|
-
OBJ_INFECT(zone, vstr);
|
4218
4248
|
set_hash("zone", zone);
|
4219
4249
|
}
|
4220
4250
|
if (!NIL_P(left)) {
|
4221
4251
|
rb_enc_copy(left, vstr);
|
4222
|
-
OBJ_INFECT(left, vstr);
|
4223
4252
|
set_hash("leftover", left);
|
4224
4253
|
}
|
4225
4254
|
}
|
@@ -4307,16 +4336,6 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
|
|
4307
4336
|
|
4308
4337
|
hash = date__parse(vstr, vcomp);
|
4309
4338
|
|
4310
|
-
{
|
4311
|
-
VALUE zone = ref_hash("zone");
|
4312
|
-
|
4313
|
-
if (!NIL_P(zone)) {
|
4314
|
-
rb_enc_copy(zone, vstr);
|
4315
|
-
OBJ_INFECT(zone, vstr);
|
4316
|
-
set_hash("zone", zone);
|
4317
|
-
}
|
4318
|
-
}
|
4319
|
-
|
4320
4339
|
return hash;
|
4321
4340
|
}
|
4322
4341
|
|
@@ -4619,6 +4638,10 @@ date_s__jisx0301(VALUE klass, VALUE str)
|
|
4619
4638
|
* some typical JIS X 0301 formats.
|
4620
4639
|
*
|
4621
4640
|
* Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
|
4641
|
+
*
|
4642
|
+
* For no-era year, legacy format, Heisei is assumed.
|
4643
|
+
*
|
4644
|
+
* Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
|
4622
4645
|
*/
|
4623
4646
|
static VALUE
|
4624
4647
|
date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
|
@@ -4709,7 +4732,6 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
|
|
4709
4732
|
double sg;
|
4710
4733
|
|
4711
4734
|
rb_check_frozen(self);
|
4712
|
-
rb_check_trusted(self);
|
4713
4735
|
|
4714
4736
|
rb_scan_args(argc, argv, "05", &vjd, &vdf, &vsf, &vof, &vsg);
|
4715
4737
|
|
@@ -4728,11 +4750,11 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
|
|
4728
4750
|
sf = vsf;
|
4729
4751
|
if (f_lt_p(sf, INT2FIX(0)) ||
|
4730
4752
|
f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS)))
|
4731
|
-
rb_raise(
|
4753
|
+
rb_raise(eDateError, "invalid second fraction");
|
4732
4754
|
case 2:
|
4733
4755
|
df = NUM2INT(vdf);
|
4734
4756
|
if (df < 0 || df >= DAY_IN_SECONDS)
|
4735
|
-
rb_raise(
|
4757
|
+
rb_raise(eDateError, "invalid day fraction");
|
4736
4758
|
case 1:
|
4737
4759
|
jd = vjd;
|
4738
4760
|
}
|
@@ -4765,7 +4787,6 @@ static VALUE
|
|
4765
4787
|
d_lite_initialize_copy(VALUE copy, VALUE date)
|
4766
4788
|
{
|
4767
4789
|
rb_check_frozen(copy);
|
4768
|
-
rb_check_trusted(copy);
|
4769
4790
|
|
4770
4791
|
if (copy == date)
|
4771
4792
|
return copy;
|
@@ -6043,7 +6064,7 @@ d_lite_rshift(VALUE self, VALUE other)
|
|
6043
6064
|
&rm, &rd, &rjd, &ns))
|
6044
6065
|
break;
|
6045
6066
|
if (--d < 1)
|
6046
|
-
rb_raise(
|
6067
|
+
rb_raise(eDateError, "invalid date");
|
6047
6068
|
}
|
6048
6069
|
encode_jd(nth, rjd, &rjd2);
|
6049
6070
|
return d_lite_plus(self, f_sub(rjd2, m_real_local_jd(dat)));
|
@@ -6567,9 +6588,9 @@ mk_inspect(union DateData *x, VALUE klass, VALUE to_s)
|
|
6567
6588
|
* Returns the value as a string for inspection.
|
6568
6589
|
*
|
6569
6590
|
* Date.new(2001,2,3).inspect
|
6570
|
-
* #=> "#<Date: 2001-02-03
|
6591
|
+
* #=> "#<Date: 2001-02-03>"
|
6571
6592
|
* DateTime.new(2001,2,3,4,5,6,'-7').inspect
|
6572
|
-
* #=> "#<DateTime: 2001-02-03T04:05:06-07:00
|
6593
|
+
* #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
|
6573
6594
|
*/
|
6574
6595
|
static VALUE
|
6575
6596
|
d_lite_inspect(VALUE self)
|
@@ -6738,7 +6759,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
|
|
6738
6759
|
if (p > fmt) rb_str_cat(str, fmt, p - fmt);
|
6739
6760
|
}
|
6740
6761
|
rb_enc_copy(str, vfmt);
|
6741
|
-
OBJ_INFECT(str, vfmt);
|
6742
6762
|
return str;
|
6743
6763
|
}
|
6744
6764
|
else
|
@@ -6747,7 +6767,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
|
|
6747
6767
|
str = rb_str_new(buf, len);
|
6748
6768
|
if (buf != buffer) xfree(buf);
|
6749
6769
|
rb_enc_copy(str, vfmt);
|
6750
|
-
OBJ_INFECT(str, vfmt);
|
6751
6770
|
return str;
|
6752
6771
|
}
|
6753
6772
|
|
@@ -7046,10 +7065,14 @@ jisx0301_date_format(char *fmt, size_t size, VALUE jd, VALUE y)
|
|
7046
7065
|
c = 'S';
|
7047
7066
|
s = 1925;
|
7048
7067
|
}
|
7049
|
-
else {
|
7068
|
+
else if (d < 2458605) {
|
7050
7069
|
c = 'H';
|
7051
7070
|
s = 1988;
|
7052
7071
|
}
|
7072
|
+
else {
|
7073
|
+
c = 'R';
|
7074
|
+
s = 2018;
|
7075
|
+
}
|
7053
7076
|
snprintf(fmt, size, "%c%02ld" ".%%m.%%d", c, FIX2INT(y) - s);
|
7054
7077
|
return fmt;
|
7055
7078
|
}
|
@@ -7134,7 +7157,6 @@ d_lite_marshal_load(VALUE self, VALUE a)
|
|
7134
7157
|
get_d1(self);
|
7135
7158
|
|
7136
7159
|
rb_check_frozen(self);
|
7137
|
-
rb_check_trusted(self);
|
7138
7160
|
|
7139
7161
|
if (!RB_TYPE_P(a, T_ARRAY))
|
7140
7162
|
rb_raise(rb_eTypeError, "expected an array");
|
@@ -7244,12 +7266,16 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
7244
7266
|
case 5:
|
7245
7267
|
val2off(vof, rof);
|
7246
7268
|
case 4:
|
7269
|
+
check_numeric(vs, "second");
|
7247
7270
|
num2int_with_frac(s, positive_inf);
|
7248
7271
|
case 3:
|
7272
|
+
check_numeric(vmin, "minute");
|
7249
7273
|
num2int_with_frac(min, 3);
|
7250
7274
|
case 2:
|
7275
|
+
check_numeric(vh, "hour");
|
7251
7276
|
num2int_with_frac(h, 2);
|
7252
7277
|
case 1:
|
7278
|
+
check_numeric(vjd, "jd");
|
7253
7279
|
num2num_with_frac(jd, 1);
|
7254
7280
|
}
|
7255
7281
|
|
@@ -7258,7 +7284,7 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
7258
7284
|
int rh, rmin, rs, rjd, rjd2;
|
7259
7285
|
|
7260
7286
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7261
|
-
rb_raise(
|
7287
|
+
rb_raise(eDateError, "invalid date");
|
7262
7288
|
canon24oc();
|
7263
7289
|
|
7264
7290
|
decode_jd(jd, &nth, &rjd);
|
@@ -7313,14 +7339,19 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
7313
7339
|
case 6:
|
7314
7340
|
val2off(vof, rof);
|
7315
7341
|
case 5:
|
7342
|
+
check_numeric(vs, "second");
|
7316
7343
|
num2int_with_frac(s, positive_inf);
|
7317
7344
|
case 4:
|
7345
|
+
check_numeric(vmin, "minute");
|
7318
7346
|
num2int_with_frac(min, 4);
|
7319
7347
|
case 3:
|
7348
|
+
check_numeric(vh, "hour");
|
7320
7349
|
num2int_with_frac(h, 3);
|
7321
7350
|
case 2:
|
7351
|
+
check_numeric(vd, "yday");
|
7322
7352
|
num2int_with_frac(d, 2);
|
7323
7353
|
case 1:
|
7354
|
+
check_numeric(vy, "year");
|
7324
7355
|
y = vy;
|
7325
7356
|
}
|
7326
7357
|
|
@@ -7332,9 +7363,9 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
7332
7363
|
&nth, &ry,
|
7333
7364
|
&rd, &rjd,
|
7334
7365
|
&ns))
|
7335
|
-
rb_raise(
|
7366
|
+
rb_raise(eDateError, "invalid date");
|
7336
7367
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7337
|
-
rb_raise(
|
7368
|
+
rb_raise(eDateError, "invalid date");
|
7338
7369
|
canon24oc();
|
7339
7370
|
|
7340
7371
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7401,16 +7432,22 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
7401
7432
|
case 7:
|
7402
7433
|
val2off(vof, rof);
|
7403
7434
|
case 6:
|
7435
|
+
check_numeric(vs, "second");
|
7404
7436
|
num2int_with_frac(s, positive_inf);
|
7405
7437
|
case 5:
|
7438
|
+
check_numeric(vmin, "minute");
|
7406
7439
|
num2int_with_frac(min, 5);
|
7407
7440
|
case 4:
|
7441
|
+
check_numeric(vh, "hour");
|
7408
7442
|
num2int_with_frac(h, 4);
|
7409
7443
|
case 3:
|
7444
|
+
check_numeric(vd, "day");
|
7410
7445
|
num2int_with_frac(d, 3);
|
7411
7446
|
case 2:
|
7447
|
+
check_numeric(vm, "month");
|
7412
7448
|
m = NUM2INT(vm);
|
7413
7449
|
case 1:
|
7450
|
+
check_numeric(vy, "year");
|
7414
7451
|
y = vy;
|
7415
7452
|
}
|
7416
7453
|
|
@@ -7421,9 +7458,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
7421
7458
|
if (!valid_gregorian_p(y, m, d,
|
7422
7459
|
&nth, &ry,
|
7423
7460
|
&rm, &rd))
|
7424
|
-
rb_raise(
|
7461
|
+
rb_raise(eDateError, "invalid date");
|
7425
7462
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7426
|
-
rb_raise(
|
7463
|
+
rb_raise(eDateError, "invalid date");
|
7427
7464
|
canon24oc();
|
7428
7465
|
|
7429
7466
|
set_to_complex(self, dat,
|
@@ -7442,9 +7479,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
7442
7479
|
&nth, &ry,
|
7443
7480
|
&rm, &rd, &rjd,
|
7444
7481
|
&ns))
|
7445
|
-
rb_raise(
|
7482
|
+
rb_raise(eDateError, "invalid date");
|
7446
7483
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7447
|
-
rb_raise(
|
7484
|
+
rb_raise(eDateError, "invalid date");
|
7448
7485
|
canon24oc();
|
7449
7486
|
|
7450
7487
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7499,16 +7536,22 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
7499
7536
|
case 7:
|
7500
7537
|
val2off(vof, rof);
|
7501
7538
|
case 6:
|
7539
|
+
check_numeric(vs, "second");
|
7502
7540
|
num2int_with_frac(s, positive_inf);
|
7503
7541
|
case 5:
|
7542
|
+
check_numeric(vmin, "minute");
|
7504
7543
|
num2int_with_frac(min, 5);
|
7505
7544
|
case 4:
|
7545
|
+
check_numeric(vh, "hour");
|
7506
7546
|
num2int_with_frac(h, 4);
|
7507
7547
|
case 3:
|
7548
|
+
check_numeric(vd, "cwday");
|
7508
7549
|
num2int_with_frac(d, 3);
|
7509
7550
|
case 2:
|
7551
|
+
check_numeric(vw, "cweek");
|
7510
7552
|
w = NUM2INT(vw);
|
7511
7553
|
case 1:
|
7554
|
+
check_numeric(vy, "year");
|
7512
7555
|
y = vy;
|
7513
7556
|
}
|
7514
7557
|
|
@@ -7520,9 +7563,9 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
7520
7563
|
&nth, &ry,
|
7521
7564
|
&rw, &rd, &rjd,
|
7522
7565
|
&ns))
|
7523
|
-
rb_raise(
|
7566
|
+
rb_raise(eDateError, "invalid date");
|
7524
7567
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7525
|
-
rb_raise(
|
7568
|
+
rb_raise(eDateError, "invalid date");
|
7526
7569
|
canon24oc();
|
7527
7570
|
|
7528
7571
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7591,9 +7634,9 @@ datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
|
|
7591
7634
|
&nth, &ry,
|
7592
7635
|
&rw, &rd, &rjd,
|
7593
7636
|
&ns))
|
7594
|
-
rb_raise(
|
7637
|
+
rb_raise(eDateError, "invalid date");
|
7595
7638
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7596
|
-
rb_raise(
|
7639
|
+
rb_raise(eDateError, "invalid date");
|
7597
7640
|
canon24oc();
|
7598
7641
|
|
7599
7642
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7660,9 +7703,9 @@ datetime_s_nth_kday(int argc, VALUE *argv, VALUE klass)
|
|
7660
7703
|
&nth, &ry,
|
7661
7704
|
&rm, &rn, &rk, &rjd,
|
7662
7705
|
&ns))
|
7663
|
-
rb_raise(
|
7706
|
+
rb_raise(eDateError, "invalid date");
|
7664
7707
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7665
|
-
rb_raise(
|
7708
|
+
rb_raise(eDateError, "invalid date");
|
7666
7709
|
canon24oc();
|
7667
7710
|
|
7668
7711
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7805,7 +7848,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
7805
7848
|
}
|
7806
7849
|
|
7807
7850
|
if (NIL_P(hash))
|
7808
|
-
rb_raise(
|
7851
|
+
rb_raise(eDateError, "invalid date");
|
7809
7852
|
|
7810
7853
|
if (NIL_P(ref_hash("jd")) &&
|
7811
7854
|
NIL_P(ref_hash("yday")) &&
|
@@ -7832,7 +7875,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
7832
7875
|
}
|
7833
7876
|
|
7834
7877
|
if (NIL_P(jd))
|
7835
|
-
rb_raise(
|
7878
|
+
rb_raise(eDateError, "invalid date");
|
7836
7879
|
|
7837
7880
|
{
|
7838
7881
|
int rh, rmin, rs;
|
@@ -7841,7 +7884,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
7841
7884
|
NUM2INT(ref_hash("min")),
|
7842
7885
|
NUM2INT(ref_hash("sec")),
|
7843
7886
|
&rh, &rmin, &rs))
|
7844
|
-
rb_raise(
|
7887
|
+
rb_raise(eDateError, "invalid date");
|
7845
7888
|
|
7846
7889
|
df = time_to_df(rh, rmin, rs);
|
7847
7890
|
}
|
@@ -8156,6 +8199,11 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
|
|
8156
8199
|
*
|
8157
8200
|
* DateTime.jisx0301('H13.02.03T04:05:06+07:00')
|
8158
8201
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
8202
|
+
*
|
8203
|
+
* For no-era year, legacy format, Heisei is assumed.
|
8204
|
+
*
|
8205
|
+
* DateTime.jisx0301('13.02.03T04:05:06+07:00')
|
8206
|
+
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
8159
8207
|
*/
|
8160
8208
|
static VALUE
|
8161
8209
|
datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
|
@@ -8550,17 +8598,24 @@ time_to_datetime(VALUE self)
|
|
8550
8598
|
* call-seq:
|
8551
8599
|
* d.to_time -> time
|
8552
8600
|
*
|
8553
|
-
* Returns a Time object which denotes self.
|
8601
|
+
* Returns a Time object which denotes self. If self is a julian date,
|
8602
|
+
* convert it to a gregorian date before converting it to Time.
|
8554
8603
|
*/
|
8555
8604
|
static VALUE
|
8556
8605
|
date_to_time(VALUE self)
|
8557
8606
|
{
|
8558
|
-
|
8607
|
+
get_d1a(self);
|
8608
|
+
|
8609
|
+
if (m_julian_p(adat)) {
|
8610
|
+
VALUE tmp = d_lite_gregorian(self);
|
8611
|
+
get_d1b(tmp);
|
8612
|
+
adat = bdat;
|
8613
|
+
}
|
8559
8614
|
|
8560
8615
|
return f_local3(rb_cTime,
|
8561
|
-
|
8562
|
-
|
8563
|
-
|
8616
|
+
m_real_year(adat),
|
8617
|
+
INT2FIX(m_mon(adat)),
|
8618
|
+
INT2FIX(m_mday(adat)));
|
8564
8619
|
}
|
8565
8620
|
|
8566
8621
|
/*
|
@@ -9217,6 +9272,7 @@ Init_date_core(void)
|
|
9217
9272
|
*
|
9218
9273
|
*/
|
9219
9274
|
cDate = rb_define_class("Date", rb_cObject);
|
9275
|
+
eDateError = rb_define_class_under(cDate, "Error", rb_eArgError);
|
9220
9276
|
|
9221
9277
|
rb_include_module(cDate, rb_mComparable);
|
9222
9278
|
|