date 2.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/date/date_core.c +119 -59
- data/ext/date/date_parse.c +103 -82
- 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 +5 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 458212a8cf5ab21beadd0ddd281f41a7f3fa9dfe50fcb7f52a2594941b11477f
|
4
|
+
data.tar.gz: 0a100c588376c5e886558cf9d2cc131d643e5387a483378b99d9ff371aad593c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7a13a9872d1c4b5b4f6495bdf3cb903b2d274dc06b3bd3d3b5a99f0be765e01bf449ae57bafb221fbf70dd3958ffbde9c76103c10971234a0724179c558b1f
|
7
|
+
data.tar.gz: 63aacb8fc345a4dab53217a46f70a4dcdf7a0e7ace8d1450a36ef3b37e236f33d116a5228c44eefe45590f5bf8b608f0fe51d9d28c0f1f06915af113aaba7990
|
data/ext/date/date_core.c
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
#include <sys/time.h>
|
12
12
|
#endif
|
13
13
|
|
14
|
+
#undef NDEBUG
|
14
15
|
#define NDEBUG
|
15
16
|
#include <assert.h>
|
16
17
|
|
@@ -22,6 +23,7 @@
|
|
22
23
|
|
23
24
|
static ID id_cmp, id_le_p, id_ge_p, id_eqeq_p;
|
24
25
|
static VALUE cDate, cDateTime;
|
26
|
+
static VALUE eDateError;
|
25
27
|
static VALUE half_days_in_day, day_in_nanoseconds;
|
26
28
|
static double positive_inf, negative_inf;
|
27
29
|
|
@@ -54,6 +56,14 @@ static double positive_inf, negative_inf;
|
|
54
56
|
static VALUE date_initialize(int argc, VALUE *argv, VALUE self);
|
55
57
|
static VALUE datetime_initialize(int argc, VALUE *argv, VALUE self);
|
56
58
|
|
59
|
+
#define RETURN_FALSE_UNLESS_NUMERIC(obj) if(!RTEST(rb_obj_is_kind_of((obj), rb_cNumeric))) return Qfalse
|
60
|
+
inline static void
|
61
|
+
check_numeric(VALUE obj, const char* field) {
|
62
|
+
if(!RTEST(rb_obj_is_kind_of(obj, rb_cNumeric))) {
|
63
|
+
rb_raise(rb_eTypeError, "invalid %s (not numeric)", field);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
57
67
|
inline static int
|
58
68
|
f_cmp(VALUE x, VALUE y)
|
59
69
|
{
|
@@ -2470,6 +2480,7 @@ date_s_valid_jd_p(int argc, VALUE *argv, VALUE klass)
|
|
2470
2480
|
|
2471
2481
|
rb_scan_args(argc, argv, "11", &vjd, &vsg);
|
2472
2482
|
|
2483
|
+
RETURN_FALSE_UNLESS_NUMERIC(vjd);
|
2473
2484
|
argv2[0] = vjd;
|
2474
2485
|
if (argc < 2)
|
2475
2486
|
argv2[1] = INT2FIX(DEFAULT_SG);
|
@@ -2545,9 +2556,12 @@ date_s__valid_civil_p(int argc, VALUE *argv, VALUE klass)
|
|
2545
2556
|
* Date.valid_date?(year, month, mday[, start=Date::ITALY]) -> bool
|
2546
2557
|
*
|
2547
2558
|
* Returns true if the given calendar date is valid, and false if not.
|
2559
|
+
* Valid in this context is whether the arguments passed to this
|
2560
|
+
* method would be accepted by ::new.
|
2548
2561
|
*
|
2549
2562
|
* Date.valid_date?(2001,2,3) #=> true
|
2550
2563
|
* Date.valid_date?(2001,2,29) #=> false
|
2564
|
+
* Date.valid_date?(2001,2,-1) #=> true
|
2551
2565
|
*
|
2552
2566
|
* See also ::jd and ::civil.
|
2553
2567
|
*/
|
@@ -2559,6 +2573,9 @@ date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
|
|
2559
2573
|
|
2560
2574
|
rb_scan_args(argc, argv, "31", &vy, &vm, &vd, &vsg);
|
2561
2575
|
|
2576
|
+
RETURN_FALSE_UNLESS_NUMERIC(vy);
|
2577
|
+
RETURN_FALSE_UNLESS_NUMERIC(vm);
|
2578
|
+
RETURN_FALSE_UNLESS_NUMERIC(vd);
|
2562
2579
|
argv2[0] = vy;
|
2563
2580
|
argv2[1] = vm;
|
2564
2581
|
argv2[2] = vd;
|
@@ -2640,6 +2657,8 @@ date_s_valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
|
|
2640
2657
|
|
2641
2658
|
rb_scan_args(argc, argv, "21", &vy, &vd, &vsg);
|
2642
2659
|
|
2660
|
+
RETURN_FALSE_UNLESS_NUMERIC(vy);
|
2661
|
+
RETURN_FALSE_UNLESS_NUMERIC(vd);
|
2643
2662
|
argv2[0] = vy;
|
2644
2663
|
argv2[1] = vd;
|
2645
2664
|
if (argc < 3)
|
@@ -2722,6 +2741,9 @@ date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
|
|
2722
2741
|
|
2723
2742
|
rb_scan_args(argc, argv, "31", &vy, &vw, &vd, &vsg);
|
2724
2743
|
|
2744
|
+
RETURN_FALSE_UNLESS_NUMERIC(vy);
|
2745
|
+
RETURN_FALSE_UNLESS_NUMERIC(vw);
|
2746
|
+
RETURN_FALSE_UNLESS_NUMERIC(vd);
|
2725
2747
|
argv2[0] = vy;
|
2726
2748
|
argv2[1] = vw;
|
2727
2749
|
argv2[2] = vd;
|
@@ -2903,6 +2925,7 @@ date_s_julian_leap_p(VALUE klass, VALUE y)
|
|
2903
2925
|
VALUE nth;
|
2904
2926
|
int ry;
|
2905
2927
|
|
2928
|
+
check_numeric(y, "year");
|
2906
2929
|
decode_year(y, +1, &nth, &ry);
|
2907
2930
|
return f_boolcast(c_julian_leap_p(ry));
|
2908
2931
|
}
|
@@ -2924,6 +2947,7 @@ date_s_gregorian_leap_p(VALUE klass, VALUE y)
|
|
2924
2947
|
VALUE nth;
|
2925
2948
|
int ry;
|
2926
2949
|
|
2950
|
+
check_numeric(y, "year");
|
2927
2951
|
decode_year(y, -1, &nth, &ry);
|
2928
2952
|
return f_boolcast(c_gregorian_leap_p(ry));
|
2929
2953
|
}
|
@@ -3047,7 +3071,7 @@ old_to_new(VALUE ajd, VALUE of, VALUE sg,
|
|
3047
3071
|
*rsg = NUM2DBL(sg);
|
3048
3072
|
|
3049
3073
|
if (*rdf < 0 || *rdf >= DAY_IN_SECONDS)
|
3050
|
-
rb_raise(
|
3074
|
+
rb_raise(eDateError, "invalid day fraction");
|
3051
3075
|
|
3052
3076
|
if (f_lt_p(*rsf, INT2FIX(0)) ||
|
3053
3077
|
f_ge_p(*rsf, INT2FIX(SECOND_IN_NANOSECONDS)))
|
@@ -3209,7 +3233,7 @@ do {\
|
|
3209
3233
|
s = s##_trunc(v##s, &fr);\
|
3210
3234
|
if (f_nonzero_p(fr)) {\
|
3211
3235
|
if (argc > n)\
|
3212
|
-
rb_raise(
|
3236
|
+
rb_raise(eDateError, "invalid fraction");\
|
3213
3237
|
fr2 = fr;\
|
3214
3238
|
}\
|
3215
3239
|
} while (0)
|
@@ -3219,7 +3243,7 @@ do {\
|
|
3219
3243
|
s = NUM2INT(s##_trunc(v##s, &fr));\
|
3220
3244
|
if (f_nonzero_p(fr)) {\
|
3221
3245
|
if (argc > n)\
|
3222
|
-
rb_raise(
|
3246
|
+
rb_raise(eDateError, "invalid fraction");\
|
3223
3247
|
fr2 = fr;\
|
3224
3248
|
}\
|
3225
3249
|
} while (0)
|
@@ -3278,6 +3302,7 @@ date_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
3278
3302
|
case 2:
|
3279
3303
|
val2sg(vsg, sg);
|
3280
3304
|
case 1:
|
3305
|
+
check_numeric(vjd, "jd");
|
3281
3306
|
num2num_with_frac(jd, positive_inf);
|
3282
3307
|
}
|
3283
3308
|
|
@@ -3330,8 +3355,10 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
3330
3355
|
case 3:
|
3331
3356
|
val2sg(vsg, sg);
|
3332
3357
|
case 2:
|
3358
|
+
check_numeric(vd, "yday");
|
3333
3359
|
num2int_with_frac(d, positive_inf);
|
3334
3360
|
case 1:
|
3361
|
+
check_numeric(vy, "year");
|
3335
3362
|
y = vy;
|
3336
3363
|
}
|
3337
3364
|
|
@@ -3343,7 +3370,7 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
3343
3370
|
&nth, &ry,
|
3344
3371
|
&rd, &rjd,
|
3345
3372
|
&ns))
|
3346
|
-
rb_raise(
|
3373
|
+
rb_raise(eDateError, "invalid date");
|
3347
3374
|
|
3348
3375
|
ret = d_simple_new_internal(klass,
|
3349
3376
|
nth, rjd,
|
@@ -3410,10 +3437,13 @@ date_initialize(int argc, VALUE *argv, VALUE self)
|
|
3410
3437
|
case 4:
|
3411
3438
|
val2sg(vsg, sg);
|
3412
3439
|
case 3:
|
3440
|
+
check_numeric(vd, "day");
|
3413
3441
|
num2int_with_frac(d, positive_inf);
|
3414
3442
|
case 2:
|
3443
|
+
check_numeric(vm, "month");
|
3415
3444
|
m = NUM2INT(vm);
|
3416
3445
|
case 1:
|
3446
|
+
check_numeric(vy, "year");
|
3417
3447
|
y = vy;
|
3418
3448
|
}
|
3419
3449
|
|
@@ -3424,7 +3454,7 @@ date_initialize(int argc, VALUE *argv, VALUE self)
|
|
3424
3454
|
if (!valid_gregorian_p(y, m, d,
|
3425
3455
|
&nth, &ry,
|
3426
3456
|
&rm, &rd))
|
3427
|
-
rb_raise(
|
3457
|
+
rb_raise(eDateError, "invalid date");
|
3428
3458
|
|
3429
3459
|
set_to_simple(self, dat, nth, 0, sg, ry, rm, rd, HAVE_CIVIL);
|
3430
3460
|
}
|
@@ -3436,7 +3466,7 @@ date_initialize(int argc, VALUE *argv, VALUE self)
|
|
3436
3466
|
&nth, &ry,
|
3437
3467
|
&rm, &rd, &rjd,
|
3438
3468
|
&ns))
|
3439
|
-
rb_raise(
|
3469
|
+
rb_raise(eDateError, "invalid date");
|
3440
3470
|
|
3441
3471
|
set_to_simple(self, dat, nth, rjd, sg, ry, rm, rd, HAVE_JD | HAVE_CIVIL);
|
3442
3472
|
}
|
@@ -3480,10 +3510,13 @@ date_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
3480
3510
|
case 4:
|
3481
3511
|
val2sg(vsg, sg);
|
3482
3512
|
case 3:
|
3513
|
+
check_numeric(vd, "cwday");
|
3483
3514
|
num2int_with_frac(d, positive_inf);
|
3484
3515
|
case 2:
|
3516
|
+
check_numeric(vw, "cweek");
|
3485
3517
|
w = NUM2INT(vw);
|
3486
3518
|
case 1:
|
3519
|
+
check_numeric(vy, "year");
|
3487
3520
|
y = vy;
|
3488
3521
|
}
|
3489
3522
|
|
@@ -3495,7 +3528,7 @@ date_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
3495
3528
|
&nth, &ry,
|
3496
3529
|
&rw, &rd, &rjd,
|
3497
3530
|
&ns))
|
3498
|
-
rb_raise(
|
3531
|
+
rb_raise(eDateError, "invalid date");
|
3499
3532
|
|
3500
3533
|
ret = d_simple_new_internal(klass,
|
3501
3534
|
nth, rjd,
|
@@ -3545,7 +3578,7 @@ date_s_weeknum(int argc, VALUE *argv, VALUE klass)
|
|
3545
3578
|
&nth, &ry,
|
3546
3579
|
&rw, &rd, &rjd,
|
3547
3580
|
&ns))
|
3548
|
-
rb_raise(
|
3581
|
+
rb_raise(eDateError, "invalid date");
|
3549
3582
|
|
3550
3583
|
ret = d_simple_new_internal(klass,
|
3551
3584
|
nth, rjd,
|
@@ -3594,7 +3627,7 @@ date_s_nth_kday(int argc, VALUE *argv, VALUE klass)
|
|
3594
3627
|
&nth, &ry,
|
3595
3628
|
&rm, &rn, &rk, &rjd,
|
3596
3629
|
&ns))
|
3597
|
-
rb_raise(
|
3630
|
+
rb_raise(eDateError, "invalid date");
|
3598
3631
|
|
3599
3632
|
ret = d_simple_new_internal(klass,
|
3600
3633
|
nth, rjd,
|
@@ -3692,7 +3725,7 @@ rt_rewrite_frags(VALUE hash)
|
|
3692
3725
|
{
|
3693
3726
|
VALUE seconds;
|
3694
3727
|
|
3695
|
-
seconds =
|
3728
|
+
seconds = del_hash("seconds");
|
3696
3729
|
if (!NIL_P(seconds)) {
|
3697
3730
|
VALUE offset, d, h, min, s, fr;
|
3698
3731
|
|
@@ -3717,7 +3750,6 @@ rt_rewrite_frags(VALUE hash)
|
|
3717
3750
|
set_hash("min", min);
|
3718
3751
|
set_hash("sec", s);
|
3719
3752
|
set_hash("sec_fraction", fr);
|
3720
|
-
del_hash("seconds");
|
3721
3753
|
}
|
3722
3754
|
return hash;
|
3723
3755
|
}
|
@@ -4142,7 +4174,7 @@ d_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
4142
4174
|
}
|
4143
4175
|
|
4144
4176
|
if (NIL_P(hash))
|
4145
|
-
rb_raise(
|
4177
|
+
rb_raise(eDateError, "invalid date");
|
4146
4178
|
|
4147
4179
|
if (NIL_P(ref_hash("jd")) &&
|
4148
4180
|
NIL_P(ref_hash("yday")) &&
|
@@ -4159,7 +4191,7 @@ d_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
4159
4191
|
}
|
4160
4192
|
|
4161
4193
|
if (NIL_P(jd))
|
4162
|
-
rb_raise(
|
4194
|
+
rb_raise(eDateError, "invalid date");
|
4163
4195
|
{
|
4164
4196
|
VALUE nth;
|
4165
4197
|
int rjd;
|
@@ -4214,12 +4246,10 @@ date_s__strptime_internal(int argc, VALUE *argv, VALUE klass,
|
|
4214
4246
|
|
4215
4247
|
if (!NIL_P(zone)) {
|
4216
4248
|
rb_enc_copy(zone, vstr);
|
4217
|
-
OBJ_INFECT(zone, vstr);
|
4218
4249
|
set_hash("zone", zone);
|
4219
4250
|
}
|
4220
4251
|
if (!NIL_P(left)) {
|
4221
4252
|
rb_enc_copy(left, vstr);
|
4222
|
-
OBJ_INFECT(left, vstr);
|
4223
4253
|
set_hash("leftover", left);
|
4224
4254
|
}
|
4225
4255
|
}
|
@@ -4335,16 +4365,6 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
|
|
4335
4365
|
|
4336
4366
|
hash = date__parse(vstr, vcomp);
|
4337
4367
|
|
4338
|
-
{
|
4339
|
-
VALUE zone = ref_hash("zone");
|
4340
|
-
|
4341
|
-
if (!NIL_P(zone)) {
|
4342
|
-
rb_enc_copy(zone, vstr);
|
4343
|
-
OBJ_INFECT(zone, vstr);
|
4344
|
-
set_hash("zone", zone);
|
4345
|
-
}
|
4346
|
-
}
|
4347
|
-
|
4348
4368
|
return hash;
|
4349
4369
|
}
|
4350
4370
|
|
@@ -4755,6 +4775,10 @@ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
|
|
4755
4775
|
*
|
4756
4776
|
* Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
|
4757
4777
|
*
|
4778
|
+
* For no-era year, legacy format, Heisei is assumed.
|
4779
|
+
*
|
4780
|
+
* Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
|
4781
|
+
*
|
4758
4782
|
* Raise an ArgumentError when the string length is longer than _limit_.
|
4759
4783
|
* You can stop this check by passing `limit: nil`, but note that
|
4760
4784
|
* it may take a long time to parse.
|
@@ -4853,7 +4877,6 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
|
|
4853
4877
|
double sg;
|
4854
4878
|
|
4855
4879
|
rb_check_frozen(self);
|
4856
|
-
rb_check_trusted(self);
|
4857
4880
|
|
4858
4881
|
rb_scan_args(argc, argv, "05", &vjd, &vdf, &vsf, &vof, &vsg);
|
4859
4882
|
|
@@ -4872,11 +4895,11 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
|
|
4872
4895
|
sf = vsf;
|
4873
4896
|
if (f_lt_p(sf, INT2FIX(0)) ||
|
4874
4897
|
f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS)))
|
4875
|
-
rb_raise(
|
4898
|
+
rb_raise(eDateError, "invalid second fraction");
|
4876
4899
|
case 2:
|
4877
4900
|
df = NUM2INT(vdf);
|
4878
4901
|
if (df < 0 || df >= DAY_IN_SECONDS)
|
4879
|
-
rb_raise(
|
4902
|
+
rb_raise(eDateError, "invalid day fraction");
|
4880
4903
|
case 1:
|
4881
4904
|
jd = vjd;
|
4882
4905
|
}
|
@@ -4909,7 +4932,6 @@ static VALUE
|
|
4909
4932
|
d_lite_initialize_copy(VALUE copy, VALUE date)
|
4910
4933
|
{
|
4911
4934
|
rb_check_frozen(copy);
|
4912
|
-
rb_check_trusted(copy);
|
4913
4935
|
|
4914
4936
|
if (copy == date)
|
4915
4937
|
return copy;
|
@@ -6187,7 +6209,7 @@ d_lite_rshift(VALUE self, VALUE other)
|
|
6187
6209
|
&rm, &rd, &rjd, &ns))
|
6188
6210
|
break;
|
6189
6211
|
if (--d < 1)
|
6190
|
-
rb_raise(
|
6212
|
+
rb_raise(eDateError, "invalid date");
|
6191
6213
|
}
|
6192
6214
|
encode_jd(nth, rjd, &rjd2);
|
6193
6215
|
return d_lite_plus(self, f_sub(rjd2, m_real_local_jd(dat)));
|
@@ -6711,9 +6733,9 @@ mk_inspect(union DateData *x, VALUE klass, VALUE to_s)
|
|
6711
6733
|
* Returns the value as a string for inspection.
|
6712
6734
|
*
|
6713
6735
|
* Date.new(2001,2,3).inspect
|
6714
|
-
* #=> "#<Date: 2001-02-03
|
6736
|
+
* #=> "#<Date: 2001-02-03>"
|
6715
6737
|
* DateTime.new(2001,2,3,4,5,6,'-7').inspect
|
6716
|
-
* #=> "#<DateTime: 2001-02-03T04:05:06-07:00
|
6738
|
+
* #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
|
6717
6739
|
*/
|
6718
6740
|
static VALUE
|
6719
6741
|
d_lite_inspect(VALUE self)
|
@@ -6882,7 +6904,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
|
|
6882
6904
|
if (p > fmt) rb_str_cat(str, fmt, p - fmt);
|
6883
6905
|
}
|
6884
6906
|
rb_enc_copy(str, vfmt);
|
6885
|
-
OBJ_INFECT(str, vfmt);
|
6886
6907
|
return str;
|
6887
6908
|
}
|
6888
6909
|
else
|
@@ -6891,7 +6912,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
|
|
6891
6912
|
str = rb_str_new(buf, len);
|
6892
6913
|
if (buf != buffer) xfree(buf);
|
6893
6914
|
rb_enc_copy(str, vfmt);
|
6894
|
-
OBJ_INFECT(str, vfmt);
|
6895
6915
|
return str;
|
6896
6916
|
}
|
6897
6917
|
|
@@ -7190,10 +7210,14 @@ jisx0301_date_format(char *fmt, size_t size, VALUE jd, VALUE y)
|
|
7190
7210
|
c = 'S';
|
7191
7211
|
s = 1925;
|
7192
7212
|
}
|
7193
|
-
else {
|
7213
|
+
else if (d < 2458605) {
|
7194
7214
|
c = 'H';
|
7195
7215
|
s = 1988;
|
7196
7216
|
}
|
7217
|
+
else {
|
7218
|
+
c = 'R';
|
7219
|
+
s = 2018;
|
7220
|
+
}
|
7197
7221
|
snprintf(fmt, size, "%c%02ld" ".%%m.%%d", c, FIX2INT(y) - s);
|
7198
7222
|
return fmt;
|
7199
7223
|
}
|
@@ -7278,7 +7302,6 @@ d_lite_marshal_load(VALUE self, VALUE a)
|
|
7278
7302
|
get_d1(self);
|
7279
7303
|
|
7280
7304
|
rb_check_frozen(self);
|
7281
|
-
rb_check_trusted(self);
|
7282
7305
|
|
7283
7306
|
if (!RB_TYPE_P(a, T_ARRAY))
|
7284
7307
|
rb_raise(rb_eTypeError, "expected an array");
|
@@ -7323,11 +7346,14 @@ d_lite_marshal_load(VALUE self, VALUE a)
|
|
7323
7346
|
|
7324
7347
|
if (simple_dat_p(dat)) {
|
7325
7348
|
if (df || !f_zero_p(sf) || of) {
|
7326
|
-
|
7327
|
-
|
7349
|
+
/* loading a fractional date; promote to complex */
|
7350
|
+
dat = ruby_xrealloc(dat, sizeof(struct ComplexDateData));
|
7351
|
+
RTYPEDDATA(self)->data = dat;
|
7352
|
+
goto complex_data;
|
7328
7353
|
}
|
7329
7354
|
set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
|
7330
7355
|
} else {
|
7356
|
+
complex_data:
|
7331
7357
|
set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
|
7332
7358
|
0, 0, 0, 0, 0, 0,
|
7333
7359
|
HAVE_JD | HAVE_DF);
|
@@ -7388,12 +7414,16 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
7388
7414
|
case 5:
|
7389
7415
|
val2off(vof, rof);
|
7390
7416
|
case 4:
|
7417
|
+
check_numeric(vs, "second");
|
7391
7418
|
num2int_with_frac(s, positive_inf);
|
7392
7419
|
case 3:
|
7420
|
+
check_numeric(vmin, "minute");
|
7393
7421
|
num2int_with_frac(min, 3);
|
7394
7422
|
case 2:
|
7423
|
+
check_numeric(vh, "hour");
|
7395
7424
|
num2int_with_frac(h, 2);
|
7396
7425
|
case 1:
|
7426
|
+
check_numeric(vjd, "jd");
|
7397
7427
|
num2num_with_frac(jd, 1);
|
7398
7428
|
}
|
7399
7429
|
|
@@ -7402,7 +7432,7 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
7402
7432
|
int rh, rmin, rs, rjd, rjd2;
|
7403
7433
|
|
7404
7434
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7405
|
-
rb_raise(
|
7435
|
+
rb_raise(eDateError, "invalid date");
|
7406
7436
|
canon24oc();
|
7407
7437
|
|
7408
7438
|
decode_jd(jd, &nth, &rjd);
|
@@ -7457,14 +7487,19 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
7457
7487
|
case 6:
|
7458
7488
|
val2off(vof, rof);
|
7459
7489
|
case 5:
|
7490
|
+
check_numeric(vs, "second");
|
7460
7491
|
num2int_with_frac(s, positive_inf);
|
7461
7492
|
case 4:
|
7493
|
+
check_numeric(vmin, "minute");
|
7462
7494
|
num2int_with_frac(min, 4);
|
7463
7495
|
case 3:
|
7496
|
+
check_numeric(vh, "hour");
|
7464
7497
|
num2int_with_frac(h, 3);
|
7465
7498
|
case 2:
|
7499
|
+
check_numeric(vd, "yday");
|
7466
7500
|
num2int_with_frac(d, 2);
|
7467
7501
|
case 1:
|
7502
|
+
check_numeric(vy, "year");
|
7468
7503
|
y = vy;
|
7469
7504
|
}
|
7470
7505
|
|
@@ -7476,9 +7511,9 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
7476
7511
|
&nth, &ry,
|
7477
7512
|
&rd, &rjd,
|
7478
7513
|
&ns))
|
7479
|
-
rb_raise(
|
7514
|
+
rb_raise(eDateError, "invalid date");
|
7480
7515
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7481
|
-
rb_raise(
|
7516
|
+
rb_raise(eDateError, "invalid date");
|
7482
7517
|
canon24oc();
|
7483
7518
|
|
7484
7519
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7545,16 +7580,22 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
7545
7580
|
case 7:
|
7546
7581
|
val2off(vof, rof);
|
7547
7582
|
case 6:
|
7583
|
+
check_numeric(vs, "second");
|
7548
7584
|
num2int_with_frac(s, positive_inf);
|
7549
7585
|
case 5:
|
7586
|
+
check_numeric(vmin, "minute");
|
7550
7587
|
num2int_with_frac(min, 5);
|
7551
7588
|
case 4:
|
7589
|
+
check_numeric(vh, "hour");
|
7552
7590
|
num2int_with_frac(h, 4);
|
7553
7591
|
case 3:
|
7592
|
+
check_numeric(vd, "day");
|
7554
7593
|
num2int_with_frac(d, 3);
|
7555
7594
|
case 2:
|
7595
|
+
check_numeric(vm, "month");
|
7556
7596
|
m = NUM2INT(vm);
|
7557
7597
|
case 1:
|
7598
|
+
check_numeric(vy, "year");
|
7558
7599
|
y = vy;
|
7559
7600
|
}
|
7560
7601
|
|
@@ -7565,9 +7606,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
7565
7606
|
if (!valid_gregorian_p(y, m, d,
|
7566
7607
|
&nth, &ry,
|
7567
7608
|
&rm, &rd))
|
7568
|
-
rb_raise(
|
7609
|
+
rb_raise(eDateError, "invalid date");
|
7569
7610
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7570
|
-
rb_raise(
|
7611
|
+
rb_raise(eDateError, "invalid date");
|
7571
7612
|
canon24oc();
|
7572
7613
|
|
7573
7614
|
set_to_complex(self, dat,
|
@@ -7586,9 +7627,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
7586
7627
|
&nth, &ry,
|
7587
7628
|
&rm, &rd, &rjd,
|
7588
7629
|
&ns))
|
7589
|
-
rb_raise(
|
7630
|
+
rb_raise(eDateError, "invalid date");
|
7590
7631
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7591
|
-
rb_raise(
|
7632
|
+
rb_raise(eDateError, "invalid date");
|
7592
7633
|
canon24oc();
|
7593
7634
|
|
7594
7635
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7643,16 +7684,22 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
7643
7684
|
case 7:
|
7644
7685
|
val2off(vof, rof);
|
7645
7686
|
case 6:
|
7687
|
+
check_numeric(vs, "second");
|
7646
7688
|
num2int_with_frac(s, positive_inf);
|
7647
7689
|
case 5:
|
7690
|
+
check_numeric(vmin, "minute");
|
7648
7691
|
num2int_with_frac(min, 5);
|
7649
7692
|
case 4:
|
7693
|
+
check_numeric(vh, "hour");
|
7650
7694
|
num2int_with_frac(h, 4);
|
7651
7695
|
case 3:
|
7696
|
+
check_numeric(vd, "cwday");
|
7652
7697
|
num2int_with_frac(d, 3);
|
7653
7698
|
case 2:
|
7699
|
+
check_numeric(vw, "cweek");
|
7654
7700
|
w = NUM2INT(vw);
|
7655
7701
|
case 1:
|
7702
|
+
check_numeric(vy, "year");
|
7656
7703
|
y = vy;
|
7657
7704
|
}
|
7658
7705
|
|
@@ -7664,9 +7711,9 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
7664
7711
|
&nth, &ry,
|
7665
7712
|
&rw, &rd, &rjd,
|
7666
7713
|
&ns))
|
7667
|
-
rb_raise(
|
7714
|
+
rb_raise(eDateError, "invalid date");
|
7668
7715
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7669
|
-
rb_raise(
|
7716
|
+
rb_raise(eDateError, "invalid date");
|
7670
7717
|
canon24oc();
|
7671
7718
|
|
7672
7719
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7735,9 +7782,9 @@ datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
|
|
7735
7782
|
&nth, &ry,
|
7736
7783
|
&rw, &rd, &rjd,
|
7737
7784
|
&ns))
|
7738
|
-
rb_raise(
|
7785
|
+
rb_raise(eDateError, "invalid date");
|
7739
7786
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7740
|
-
rb_raise(
|
7787
|
+
rb_raise(eDateError, "invalid date");
|
7741
7788
|
canon24oc();
|
7742
7789
|
|
7743
7790
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7804,9 +7851,9 @@ datetime_s_nth_kday(int argc, VALUE *argv, VALUE klass)
|
|
7804
7851
|
&nth, &ry,
|
7805
7852
|
&rm, &rn, &rk, &rjd,
|
7806
7853
|
&ns))
|
7807
|
-
rb_raise(
|
7854
|
+
rb_raise(eDateError, "invalid date");
|
7808
7855
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
7809
|
-
rb_raise(
|
7856
|
+
rb_raise(eDateError, "invalid date");
|
7810
7857
|
canon24oc();
|
7811
7858
|
|
7812
7859
|
rjd2 = jd_local_to_utc(rjd,
|
@@ -7949,7 +7996,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
7949
7996
|
}
|
7950
7997
|
|
7951
7998
|
if (NIL_P(hash))
|
7952
|
-
rb_raise(
|
7999
|
+
rb_raise(eDateError, "invalid date");
|
7953
8000
|
|
7954
8001
|
if (NIL_P(ref_hash("jd")) &&
|
7955
8002
|
NIL_P(ref_hash("yday")) &&
|
@@ -7976,7 +8023,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
7976
8023
|
}
|
7977
8024
|
|
7978
8025
|
if (NIL_P(jd))
|
7979
|
-
rb_raise(
|
8026
|
+
rb_raise(eDateError, "invalid date");
|
7980
8027
|
|
7981
8028
|
{
|
7982
8029
|
int rh, rmin, rs;
|
@@ -7985,7 +8032,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
7985
8032
|
NUM2INT(ref_hash("min")),
|
7986
8033
|
NUM2INT(ref_hash("sec")),
|
7987
8034
|
&rh, &rmin, &rs))
|
7988
|
-
rb_raise(
|
8035
|
+
rb_raise(eDateError, "invalid date");
|
7989
8036
|
|
7990
8037
|
df = time_to_df(rh, rmin, rs);
|
7991
8038
|
}
|
@@ -8358,6 +8405,11 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
|
|
8358
8405
|
* DateTime.jisx0301('H13.02.03T04:05:06+07:00')
|
8359
8406
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
8360
8407
|
*
|
8408
|
+
* For no-era year, legacy format, Heisei is assumed.
|
8409
|
+
*
|
8410
|
+
* DateTime.jisx0301('13.02.03T04:05:06+07:00')
|
8411
|
+
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
8412
|
+
*
|
8361
8413
|
* Raise an ArgumentError when the string length is longer than _limit_.
|
8362
8414
|
* You can stop this check by passing `limit: nil`, but note that
|
8363
8415
|
* it may take a long time to parse.
|
@@ -8761,17 +8813,24 @@ time_to_datetime(VALUE self)
|
|
8761
8813
|
* call-seq:
|
8762
8814
|
* d.to_time -> time
|
8763
8815
|
*
|
8764
|
-
* Returns a Time object which denotes self.
|
8816
|
+
* Returns a Time object which denotes self. If self is a julian date,
|
8817
|
+
* convert it to a gregorian date before converting it to Time.
|
8765
8818
|
*/
|
8766
8819
|
static VALUE
|
8767
8820
|
date_to_time(VALUE self)
|
8768
8821
|
{
|
8769
|
-
|
8822
|
+
get_d1a(self);
|
8823
|
+
|
8824
|
+
if (m_julian_p(adat)) {
|
8825
|
+
VALUE tmp = d_lite_gregorian(self);
|
8826
|
+
get_d1b(tmp);
|
8827
|
+
adat = bdat;
|
8828
|
+
}
|
8770
8829
|
|
8771
8830
|
return f_local3(rb_cTime,
|
8772
|
-
|
8773
|
-
|
8774
|
-
|
8831
|
+
m_real_year(adat),
|
8832
|
+
INT2FIX(m_mon(adat)),
|
8833
|
+
INT2FIX(m_mday(adat)));
|
8775
8834
|
}
|
8776
8835
|
|
8777
8836
|
/*
|
@@ -9428,6 +9487,7 @@ Init_date_core(void)
|
|
9428
9487
|
*
|
9429
9488
|
*/
|
9430
9489
|
cDate = rb_define_class("Date", rb_cObject);
|
9490
|
+
eDateError = rb_define_class_under(cDate, "Error", rb_eArgError);
|
9431
9491
|
|
9432
9492
|
rb_include_module(cDate, rb_mComparable);
|
9433
9493
|
|