date 2.0.2 → 3.0.0
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 +199 -354
- 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 -1
- metadata +4 -18
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
|
}
|
|
@@ -4292,40 +4321,12 @@ date_s_strptime(int argc, VALUE *argv, VALUE klass)
|
|
|
4292
4321
|
|
|
4293
4322
|
VALUE date__parse(VALUE str, VALUE comp);
|
|
4294
4323
|
|
|
4295
|
-
static size_t
|
|
4296
|
-
get_limit(VALUE opt)
|
|
4297
|
-
{
|
|
4298
|
-
if (!NIL_P(opt)) {
|
|
4299
|
-
VALUE limit = rb_hash_aref(opt, ID2SYM(rb_intern("limit")));
|
|
4300
|
-
if (NIL_P(limit)) return SIZE_MAX;
|
|
4301
|
-
return NUM2SIZET(limit);
|
|
4302
|
-
}
|
|
4303
|
-
return 128;
|
|
4304
|
-
}
|
|
4305
|
-
|
|
4306
|
-
static void
|
|
4307
|
-
check_limit(VALUE str, VALUE opt)
|
|
4308
|
-
{
|
|
4309
|
-
if (NIL_P(str)) return;
|
|
4310
|
-
if (SYMBOL_P(str)) str = rb_sym2str(str);
|
|
4311
|
-
|
|
4312
|
-
StringValue(str);
|
|
4313
|
-
size_t slen = RSTRING_LEN(str);
|
|
4314
|
-
size_t limit = get_limit(opt);
|
|
4315
|
-
if (slen > limit) {
|
|
4316
|
-
rb_raise(rb_eArgError,
|
|
4317
|
-
"string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit);
|
|
4318
|
-
}
|
|
4319
|
-
}
|
|
4320
|
-
|
|
4321
4324
|
static VALUE
|
|
4322
4325
|
date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
|
|
4323
4326
|
{
|
|
4324
|
-
VALUE vstr, vcomp, hash
|
|
4327
|
+
VALUE vstr, vcomp, hash;
|
|
4325
4328
|
|
|
4326
|
-
rb_scan_args(argc, argv, "11
|
|
4327
|
-
if (!NIL_P(opt)) argc--;
|
|
4328
|
-
check_limit(vstr, opt);
|
|
4329
|
+
rb_scan_args(argc, argv, "11", &vstr, &vcomp);
|
|
4329
4330
|
StringValue(vstr);
|
|
4330
4331
|
if (!rb_enc_str_asciicompat_p(vstr))
|
|
4331
4332
|
rb_raise(rb_eArgError,
|
|
@@ -4335,22 +4336,12 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
|
|
|
4335
4336
|
|
|
4336
4337
|
hash = date__parse(vstr, vcomp);
|
|
4337
4338
|
|
|
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
4339
|
return hash;
|
|
4349
4340
|
}
|
|
4350
4341
|
|
|
4351
4342
|
/*
|
|
4352
4343
|
* call-seq:
|
|
4353
|
-
* Date._parse(string[, comp=true]
|
|
4344
|
+
* Date._parse(string[, comp=true]) -> hash
|
|
4354
4345
|
*
|
|
4355
4346
|
* Parses the given representation of date and time, and returns a
|
|
4356
4347
|
* hash of parsed elements. This method does not function as a
|
|
@@ -4361,10 +4352,6 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
|
|
|
4361
4352
|
* it full.
|
|
4362
4353
|
*
|
|
4363
4354
|
* Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
|
|
4364
|
-
*
|
|
4365
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4366
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4367
|
-
* it may take a long time to parse.
|
|
4368
4355
|
*/
|
|
4369
4356
|
static VALUE
|
|
4370
4357
|
date_s__parse(int argc, VALUE *argv, VALUE klass)
|
|
@@ -4374,7 +4361,7 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
|
|
|
4374
4361
|
|
|
4375
4362
|
/*
|
|
4376
4363
|
* call-seq:
|
|
4377
|
-
* Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]]
|
|
4364
|
+
* Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]]) -> date
|
|
4378
4365
|
*
|
|
4379
4366
|
* Parses the given representation of date and time, and creates a
|
|
4380
4367
|
* date object. This method does not function as a validator.
|
|
@@ -4386,18 +4373,13 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
|
|
|
4386
4373
|
* Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
|
|
4387
4374
|
* Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
|
|
4388
4375
|
* Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
|
|
4389
|
-
*
|
|
4390
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4391
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4392
|
-
* it may take a long time to parse.
|
|
4393
4376
|
*/
|
|
4394
4377
|
static VALUE
|
|
4395
4378
|
date_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
4396
4379
|
{
|
|
4397
|
-
VALUE str, comp, sg
|
|
4380
|
+
VALUE str, comp, sg;
|
|
4398
4381
|
|
|
4399
|
-
rb_scan_args(argc, argv, "03
|
|
4400
|
-
if (!NIL_P(opt)) argc--;
|
|
4382
|
+
rb_scan_args(argc, argv, "03", &str, &comp, &sg);
|
|
4401
4383
|
|
|
4402
4384
|
switch (argc) {
|
|
4403
4385
|
case 0:
|
|
@@ -4409,12 +4391,11 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
|
4409
4391
|
}
|
|
4410
4392
|
|
|
4411
4393
|
{
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
VALUE hash = date_s__parse(argc2, argv2, klass);
|
|
4394
|
+
VALUE argv2[2], hash;
|
|
4395
|
+
|
|
4396
|
+
argv2[0] = str;
|
|
4397
|
+
argv2[1] = comp;
|
|
4398
|
+
hash = date_s__parse(2, argv2, klass);
|
|
4418
4399
|
return d_new_by_frags(klass, hash, sg);
|
|
4419
4400
|
}
|
|
4420
4401
|
}
|
|
@@ -4428,28 +4409,19 @@ VALUE date__jisx0301(VALUE);
|
|
|
4428
4409
|
|
|
4429
4410
|
/*
|
|
4430
4411
|
* call-seq:
|
|
4431
|
-
* Date._iso8601(string
|
|
4412
|
+
* Date._iso8601(string) -> hash
|
|
4432
4413
|
*
|
|
4433
4414
|
* Returns a hash of parsed elements.
|
|
4434
|
-
*
|
|
4435
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4436
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4437
|
-
* it may take a long time to parse.
|
|
4438
4415
|
*/
|
|
4439
4416
|
static VALUE
|
|
4440
|
-
date_s__iso8601(
|
|
4417
|
+
date_s__iso8601(VALUE klass, VALUE str)
|
|
4441
4418
|
{
|
|
4442
|
-
VALUE str, opt;
|
|
4443
|
-
|
|
4444
|
-
rb_scan_args(argc, argv, "1:", &str, &opt);
|
|
4445
|
-
check_limit(str, opt);
|
|
4446
|
-
|
|
4447
4419
|
return date__iso8601(str);
|
|
4448
4420
|
}
|
|
4449
4421
|
|
|
4450
4422
|
/*
|
|
4451
4423
|
* call-seq:
|
|
4452
|
-
* Date.iso8601(string='-4712-01-01'[, start=Date::ITALY]
|
|
4424
|
+
* Date.iso8601(string='-4712-01-01'[, start=Date::ITALY]) -> date
|
|
4453
4425
|
*
|
|
4454
4426
|
* Creates a new Date object by parsing from a string according to
|
|
4455
4427
|
* some typical ISO 8601 formats.
|
|
@@ -4457,18 +4429,13 @@ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
|
|
|
4457
4429
|
* Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
|
|
4458
4430
|
* Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
|
|
4459
4431
|
* Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
|
|
4460
|
-
*
|
|
4461
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4462
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4463
|
-
* it may take a long time to parse.
|
|
4464
4432
|
*/
|
|
4465
4433
|
static VALUE
|
|
4466
4434
|
date_s_iso8601(int argc, VALUE *argv, VALUE klass)
|
|
4467
4435
|
{
|
|
4468
|
-
VALUE str, sg
|
|
4436
|
+
VALUE str, sg;
|
|
4469
4437
|
|
|
4470
|
-
rb_scan_args(argc, argv, "02
|
|
4471
|
-
if (!NIL_P(opt)) argc--;
|
|
4438
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
4472
4439
|
|
|
4473
4440
|
switch (argc) {
|
|
4474
4441
|
case 0:
|
|
@@ -4478,56 +4445,38 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
|
|
|
4478
4445
|
}
|
|
4479
4446
|
|
|
4480
4447
|
{
|
|
4481
|
-
|
|
4482
|
-
VALUE argv2[2];
|
|
4483
|
-
argv2[0] = str;
|
|
4484
|
-
if (!NIL_P(opt)) argv2[argc2++] = opt;
|
|
4485
|
-
VALUE hash = date_s__iso8601(argc2, argv2, klass);
|
|
4448
|
+
VALUE hash = date_s__iso8601(klass, str);
|
|
4486
4449
|
return d_new_by_frags(klass, hash, sg);
|
|
4487
4450
|
}
|
|
4488
4451
|
}
|
|
4489
4452
|
|
|
4490
4453
|
/*
|
|
4491
4454
|
* call-seq:
|
|
4492
|
-
* Date._rfc3339(string
|
|
4455
|
+
* Date._rfc3339(string) -> hash
|
|
4493
4456
|
*
|
|
4494
4457
|
* Returns a hash of parsed elements.
|
|
4495
|
-
*
|
|
4496
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4497
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4498
|
-
* it may take a long time to parse.
|
|
4499
4458
|
*/
|
|
4500
4459
|
static VALUE
|
|
4501
|
-
date_s__rfc3339(
|
|
4460
|
+
date_s__rfc3339(VALUE klass, VALUE str)
|
|
4502
4461
|
{
|
|
4503
|
-
VALUE str, opt;
|
|
4504
|
-
|
|
4505
|
-
rb_scan_args(argc, argv, "1:", &str, &opt);
|
|
4506
|
-
check_limit(str, opt);
|
|
4507
|
-
|
|
4508
4462
|
return date__rfc3339(str);
|
|
4509
4463
|
}
|
|
4510
4464
|
|
|
4511
4465
|
/*
|
|
4512
4466
|
* call-seq:
|
|
4513
|
-
* Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]
|
|
4467
|
+
* Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> date
|
|
4514
4468
|
*
|
|
4515
4469
|
* Creates a new Date object by parsing from a string according to
|
|
4516
4470
|
* some typical RFC 3339 formats.
|
|
4517
4471
|
*
|
|
4518
4472
|
* Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
|
|
4519
|
-
*
|
|
4520
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4521
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4522
|
-
* it may take a long time to parse.
|
|
4523
4473
|
*/
|
|
4524
4474
|
static VALUE
|
|
4525
4475
|
date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
|
|
4526
4476
|
{
|
|
4527
|
-
VALUE str, sg
|
|
4477
|
+
VALUE str, sg;
|
|
4528
4478
|
|
|
4529
|
-
rb_scan_args(argc, argv, "02
|
|
4530
|
-
if (!NIL_P(opt)) argc--;
|
|
4479
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
4531
4480
|
|
|
4532
4481
|
switch (argc) {
|
|
4533
4482
|
case 0:
|
|
@@ -4537,56 +4486,38 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
|
|
|
4537
4486
|
}
|
|
4538
4487
|
|
|
4539
4488
|
{
|
|
4540
|
-
|
|
4541
|
-
VALUE argv2[2];
|
|
4542
|
-
argv2[0] = str;
|
|
4543
|
-
if (!NIL_P(opt)) argv2[argc2++] = opt;
|
|
4544
|
-
VALUE hash = date_s__rfc3339(argc2, argv2, klass);
|
|
4489
|
+
VALUE hash = date_s__rfc3339(klass, str);
|
|
4545
4490
|
return d_new_by_frags(klass, hash, sg);
|
|
4546
4491
|
}
|
|
4547
4492
|
}
|
|
4548
4493
|
|
|
4549
4494
|
/*
|
|
4550
4495
|
* call-seq:
|
|
4551
|
-
* Date._xmlschema(string
|
|
4496
|
+
* Date._xmlschema(string) -> hash
|
|
4552
4497
|
*
|
|
4553
4498
|
* Returns a hash of parsed elements.
|
|
4554
|
-
*
|
|
4555
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4556
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4557
|
-
* it may take a long time to parse.
|
|
4558
4499
|
*/
|
|
4559
4500
|
static VALUE
|
|
4560
|
-
date_s__xmlschema(
|
|
4501
|
+
date_s__xmlschema(VALUE klass, VALUE str)
|
|
4561
4502
|
{
|
|
4562
|
-
VALUE str, opt;
|
|
4563
|
-
|
|
4564
|
-
rb_scan_args(argc, argv, "1:", &str, &opt);
|
|
4565
|
-
check_limit(str, opt);
|
|
4566
|
-
|
|
4567
4503
|
return date__xmlschema(str);
|
|
4568
4504
|
}
|
|
4569
4505
|
|
|
4570
4506
|
/*
|
|
4571
4507
|
* call-seq:
|
|
4572
|
-
* Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY]
|
|
4508
|
+
* Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY]) -> date
|
|
4573
4509
|
*
|
|
4574
4510
|
* Creates a new Date object by parsing from a string according to
|
|
4575
4511
|
* some typical XML Schema formats.
|
|
4576
4512
|
*
|
|
4577
4513
|
* Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
|
|
4578
|
-
*
|
|
4579
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4580
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4581
|
-
* it may take a long time to parse.
|
|
4582
4514
|
*/
|
|
4583
4515
|
static VALUE
|
|
4584
4516
|
date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
|
|
4585
4517
|
{
|
|
4586
|
-
VALUE str, sg
|
|
4518
|
+
VALUE str, sg;
|
|
4587
4519
|
|
|
4588
|
-
rb_scan_args(argc, argv, "02
|
|
4589
|
-
if (!NIL_P(opt)) argc--;
|
|
4520
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
4590
4521
|
|
|
4591
4522
|
switch (argc) {
|
|
4592
4523
|
case 0:
|
|
@@ -4596,58 +4527,41 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
|
|
|
4596
4527
|
}
|
|
4597
4528
|
|
|
4598
4529
|
{
|
|
4599
|
-
|
|
4600
|
-
VALUE argv2[2];
|
|
4601
|
-
argv2[0] = str;
|
|
4602
|
-
if (!NIL_P(opt)) argv2[argc2++] = opt;
|
|
4603
|
-
VALUE hash = date_s__xmlschema(argc2, argv2, klass);
|
|
4530
|
+
VALUE hash = date_s__xmlschema(klass, str);
|
|
4604
4531
|
return d_new_by_frags(klass, hash, sg);
|
|
4605
4532
|
}
|
|
4606
4533
|
}
|
|
4607
4534
|
|
|
4608
4535
|
/*
|
|
4609
4536
|
* call-seq:
|
|
4610
|
-
* Date._rfc2822(string
|
|
4611
|
-
* Date._rfc822(string
|
|
4537
|
+
* Date._rfc2822(string) -> hash
|
|
4538
|
+
* Date._rfc822(string) -> hash
|
|
4612
4539
|
*
|
|
4613
4540
|
* Returns a hash of parsed elements.
|
|
4614
|
-
*
|
|
4615
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4616
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4617
|
-
* it may take a long time to parse.
|
|
4618
4541
|
*/
|
|
4619
4542
|
static VALUE
|
|
4620
|
-
date_s__rfc2822(
|
|
4543
|
+
date_s__rfc2822(VALUE klass, VALUE str)
|
|
4621
4544
|
{
|
|
4622
|
-
VALUE str, opt;
|
|
4623
|
-
|
|
4624
|
-
rb_scan_args(argc, argv, "1:", &str, &opt);
|
|
4625
|
-
check_limit(str, opt);
|
|
4626
|
-
|
|
4627
4545
|
return date__rfc2822(str);
|
|
4628
4546
|
}
|
|
4629
4547
|
|
|
4630
4548
|
/*
|
|
4631
4549
|
* call-seq:
|
|
4632
|
-
* Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]
|
|
4633
|
-
* Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]
|
|
4550
|
+
* Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
|
|
4551
|
+
* Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
|
|
4634
4552
|
*
|
|
4635
4553
|
* Creates a new Date object by parsing from a string according to
|
|
4636
4554
|
* some typical RFC 2822 formats.
|
|
4637
4555
|
*
|
|
4638
4556
|
* Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
|
|
4639
4557
|
* #=> #<Date: 2001-02-03 ...>
|
|
4640
|
-
*
|
|
4641
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4642
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4643
|
-
* it may take a long time to parse.
|
|
4644
4558
|
*/
|
|
4645
4559
|
static VALUE
|
|
4646
4560
|
date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
|
|
4647
4561
|
{
|
|
4648
|
-
VALUE str, sg
|
|
4562
|
+
VALUE str, sg;
|
|
4649
4563
|
|
|
4650
|
-
rb_scan_args(argc, argv, "02
|
|
4564
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
4651
4565
|
|
|
4652
4566
|
switch (argc) {
|
|
4653
4567
|
case 0:
|
|
@@ -4657,56 +4571,39 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
|
|
|
4657
4571
|
}
|
|
4658
4572
|
|
|
4659
4573
|
{
|
|
4660
|
-
|
|
4661
|
-
VALUE argv2[2];
|
|
4662
|
-
argv2[0] = str;
|
|
4663
|
-
if (!NIL_P(opt)) argv2[argc2++] = opt;
|
|
4664
|
-
VALUE hash = date_s__rfc2822(argc2, argv2, klass);
|
|
4574
|
+
VALUE hash = date_s__rfc2822(klass, str);
|
|
4665
4575
|
return d_new_by_frags(klass, hash, sg);
|
|
4666
4576
|
}
|
|
4667
4577
|
}
|
|
4668
4578
|
|
|
4669
4579
|
/*
|
|
4670
4580
|
* call-seq:
|
|
4671
|
-
* Date._httpdate(string
|
|
4581
|
+
* Date._httpdate(string) -> hash
|
|
4672
4582
|
*
|
|
4673
4583
|
* Returns a hash of parsed elements.
|
|
4674
|
-
*
|
|
4675
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4676
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4677
|
-
* it may take a long time to parse.
|
|
4678
4584
|
*/
|
|
4679
4585
|
static VALUE
|
|
4680
|
-
date_s__httpdate(
|
|
4586
|
+
date_s__httpdate(VALUE klass, VALUE str)
|
|
4681
4587
|
{
|
|
4682
|
-
VALUE str, opt;
|
|
4683
|
-
|
|
4684
|
-
rb_scan_args(argc, argv, "1:", &str, &opt);
|
|
4685
|
-
check_limit(str, opt);
|
|
4686
|
-
|
|
4687
4588
|
return date__httpdate(str);
|
|
4688
4589
|
}
|
|
4689
4590
|
|
|
4690
4591
|
/*
|
|
4691
4592
|
* call-seq:
|
|
4692
|
-
* Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]
|
|
4593
|
+
* Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]) -> date
|
|
4693
4594
|
*
|
|
4694
4595
|
* Creates a new Date object by parsing from a string according to
|
|
4695
4596
|
* some RFC 2616 format.
|
|
4696
4597
|
*
|
|
4697
4598
|
* Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
|
|
4698
4599
|
* #=> #<Date: 2001-02-03 ...>
|
|
4699
|
-
*
|
|
4700
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4701
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4702
|
-
* it may take a long time to parse.
|
|
4703
4600
|
*/
|
|
4704
4601
|
static VALUE
|
|
4705
4602
|
date_s_httpdate(int argc, VALUE *argv, VALUE klass)
|
|
4706
4603
|
{
|
|
4707
|
-
VALUE str, sg
|
|
4604
|
+
VALUE str, sg;
|
|
4708
4605
|
|
|
4709
|
-
rb_scan_args(argc, argv, "02
|
|
4606
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
4710
4607
|
|
|
4711
4608
|
switch (argc) {
|
|
4712
4609
|
case 0:
|
|
@@ -4716,56 +4613,42 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
|
|
|
4716
4613
|
}
|
|
4717
4614
|
|
|
4718
4615
|
{
|
|
4719
|
-
|
|
4720
|
-
VALUE argv2[2];
|
|
4721
|
-
argv2[0] = str;
|
|
4722
|
-
if (!NIL_P(opt)) argv2[argc2++] = opt;
|
|
4723
|
-
VALUE hash = date_s__httpdate(argc2, argv2, klass);
|
|
4616
|
+
VALUE hash = date_s__httpdate(klass, str);
|
|
4724
4617
|
return d_new_by_frags(klass, hash, sg);
|
|
4725
4618
|
}
|
|
4726
4619
|
}
|
|
4727
4620
|
|
|
4728
4621
|
/*
|
|
4729
4622
|
* call-seq:
|
|
4730
|
-
* Date._jisx0301(string
|
|
4623
|
+
* Date._jisx0301(string) -> hash
|
|
4731
4624
|
*
|
|
4732
4625
|
* Returns a hash of parsed elements.
|
|
4733
|
-
*
|
|
4734
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
4735
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
4736
|
-
* it may take a long time to parse.
|
|
4737
4626
|
*/
|
|
4738
4627
|
static VALUE
|
|
4739
|
-
date_s__jisx0301(
|
|
4628
|
+
date_s__jisx0301(VALUE klass, VALUE str)
|
|
4740
4629
|
{
|
|
4741
|
-
VALUE str, opt;
|
|
4742
|
-
|
|
4743
|
-
rb_scan_args(argc, argv, "1:", &str, &opt);
|
|
4744
|
-
check_limit(str, opt);
|
|
4745
|
-
|
|
4746
4630
|
return date__jisx0301(str);
|
|
4747
4631
|
}
|
|
4748
4632
|
|
|
4749
4633
|
/*
|
|
4750
4634
|
* call-seq:
|
|
4751
|
-
* Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY]
|
|
4635
|
+
* Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY]) -> date
|
|
4752
4636
|
*
|
|
4753
4637
|
* Creates a new Date object by parsing from a string according to
|
|
4754
4638
|
* some typical JIS X 0301 formats.
|
|
4755
4639
|
*
|
|
4756
4640
|
* Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
|
|
4757
4641
|
*
|
|
4758
|
-
*
|
|
4759
|
-
*
|
|
4760
|
-
*
|
|
4642
|
+
* For no-era year, legacy format, Heisei is assumed.
|
|
4643
|
+
*
|
|
4644
|
+
* Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
|
|
4761
4645
|
*/
|
|
4762
4646
|
static VALUE
|
|
4763
4647
|
date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
|
|
4764
4648
|
{
|
|
4765
|
-
VALUE str, sg
|
|
4649
|
+
VALUE str, sg;
|
|
4766
4650
|
|
|
4767
|
-
rb_scan_args(argc, argv, "02
|
|
4768
|
-
if (!NIL_P(opt)) argc--;
|
|
4651
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
4769
4652
|
|
|
4770
4653
|
switch (argc) {
|
|
4771
4654
|
case 0:
|
|
@@ -4775,11 +4658,7 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
|
|
|
4775
4658
|
}
|
|
4776
4659
|
|
|
4777
4660
|
{
|
|
4778
|
-
|
|
4779
|
-
VALUE argv2[2];
|
|
4780
|
-
argv2[0] = str;
|
|
4781
|
-
if (!NIL_P(opt)) argv2[argc2++] = opt;
|
|
4782
|
-
VALUE hash = date_s__jisx0301(argc2, argv2, klass);
|
|
4661
|
+
VALUE hash = date_s__jisx0301(klass, str);
|
|
4783
4662
|
return d_new_by_frags(klass, hash, sg);
|
|
4784
4663
|
}
|
|
4785
4664
|
}
|
|
@@ -4853,7 +4732,6 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
4853
4732
|
double sg;
|
|
4854
4733
|
|
|
4855
4734
|
rb_check_frozen(self);
|
|
4856
|
-
rb_check_trusted(self);
|
|
4857
4735
|
|
|
4858
4736
|
rb_scan_args(argc, argv, "05", &vjd, &vdf, &vsf, &vof, &vsg);
|
|
4859
4737
|
|
|
@@ -4872,11 +4750,11 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
4872
4750
|
sf = vsf;
|
|
4873
4751
|
if (f_lt_p(sf, INT2FIX(0)) ||
|
|
4874
4752
|
f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS)))
|
|
4875
|
-
rb_raise(
|
|
4753
|
+
rb_raise(eDateError, "invalid second fraction");
|
|
4876
4754
|
case 2:
|
|
4877
4755
|
df = NUM2INT(vdf);
|
|
4878
4756
|
if (df < 0 || df >= DAY_IN_SECONDS)
|
|
4879
|
-
rb_raise(
|
|
4757
|
+
rb_raise(eDateError, "invalid day fraction");
|
|
4880
4758
|
case 1:
|
|
4881
4759
|
jd = vjd;
|
|
4882
4760
|
}
|
|
@@ -4909,7 +4787,6 @@ static VALUE
|
|
|
4909
4787
|
d_lite_initialize_copy(VALUE copy, VALUE date)
|
|
4910
4788
|
{
|
|
4911
4789
|
rb_check_frozen(copy);
|
|
4912
|
-
rb_check_trusted(copy);
|
|
4913
4790
|
|
|
4914
4791
|
if (copy == date)
|
|
4915
4792
|
return copy;
|
|
@@ -6187,7 +6064,7 @@ d_lite_rshift(VALUE self, VALUE other)
|
|
|
6187
6064
|
&rm, &rd, &rjd, &ns))
|
|
6188
6065
|
break;
|
|
6189
6066
|
if (--d < 1)
|
|
6190
|
-
rb_raise(
|
|
6067
|
+
rb_raise(eDateError, "invalid date");
|
|
6191
6068
|
}
|
|
6192
6069
|
encode_jd(nth, rjd, &rjd2);
|
|
6193
6070
|
return d_lite_plus(self, f_sub(rjd2, m_real_local_jd(dat)));
|
|
@@ -6711,9 +6588,9 @@ mk_inspect(union DateData *x, VALUE klass, VALUE to_s)
|
|
|
6711
6588
|
* Returns the value as a string for inspection.
|
|
6712
6589
|
*
|
|
6713
6590
|
* Date.new(2001,2,3).inspect
|
|
6714
|
-
* #=> "#<Date: 2001-02-03
|
|
6591
|
+
* #=> "#<Date: 2001-02-03>"
|
|
6715
6592
|
* DateTime.new(2001,2,3,4,5,6,'-7').inspect
|
|
6716
|
-
* #=> "#<DateTime: 2001-02-03T04:05:06-07:00
|
|
6593
|
+
* #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
|
|
6717
6594
|
*/
|
|
6718
6595
|
static VALUE
|
|
6719
6596
|
d_lite_inspect(VALUE self)
|
|
@@ -6882,7 +6759,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
|
|
|
6882
6759
|
if (p > fmt) rb_str_cat(str, fmt, p - fmt);
|
|
6883
6760
|
}
|
|
6884
6761
|
rb_enc_copy(str, vfmt);
|
|
6885
|
-
OBJ_INFECT(str, vfmt);
|
|
6886
6762
|
return str;
|
|
6887
6763
|
}
|
|
6888
6764
|
else
|
|
@@ -6891,7 +6767,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
|
|
|
6891
6767
|
str = rb_str_new(buf, len);
|
|
6892
6768
|
if (buf != buffer) xfree(buf);
|
|
6893
6769
|
rb_enc_copy(str, vfmt);
|
|
6894
|
-
OBJ_INFECT(str, vfmt);
|
|
6895
6770
|
return str;
|
|
6896
6771
|
}
|
|
6897
6772
|
|
|
@@ -7190,10 +7065,14 @@ jisx0301_date_format(char *fmt, size_t size, VALUE jd, VALUE y)
|
|
|
7190
7065
|
c = 'S';
|
|
7191
7066
|
s = 1925;
|
|
7192
7067
|
}
|
|
7193
|
-
else {
|
|
7068
|
+
else if (d < 2458605) {
|
|
7194
7069
|
c = 'H';
|
|
7195
7070
|
s = 1988;
|
|
7196
7071
|
}
|
|
7072
|
+
else {
|
|
7073
|
+
c = 'R';
|
|
7074
|
+
s = 2018;
|
|
7075
|
+
}
|
|
7197
7076
|
snprintf(fmt, size, "%c%02ld" ".%%m.%%d", c, FIX2INT(y) - s);
|
|
7198
7077
|
return fmt;
|
|
7199
7078
|
}
|
|
@@ -7278,7 +7157,6 @@ d_lite_marshal_load(VALUE self, VALUE a)
|
|
|
7278
7157
|
get_d1(self);
|
|
7279
7158
|
|
|
7280
7159
|
rb_check_frozen(self);
|
|
7281
|
-
rb_check_trusted(self);
|
|
7282
7160
|
|
|
7283
7161
|
if (!RB_TYPE_P(a, T_ARRAY))
|
|
7284
7162
|
rb_raise(rb_eTypeError, "expected an array");
|
|
@@ -7388,12 +7266,16 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
|
7388
7266
|
case 5:
|
|
7389
7267
|
val2off(vof, rof);
|
|
7390
7268
|
case 4:
|
|
7269
|
+
check_numeric(vs, "second");
|
|
7391
7270
|
num2int_with_frac(s, positive_inf);
|
|
7392
7271
|
case 3:
|
|
7272
|
+
check_numeric(vmin, "minute");
|
|
7393
7273
|
num2int_with_frac(min, 3);
|
|
7394
7274
|
case 2:
|
|
7275
|
+
check_numeric(vh, "hour");
|
|
7395
7276
|
num2int_with_frac(h, 2);
|
|
7396
7277
|
case 1:
|
|
7278
|
+
check_numeric(vjd, "jd");
|
|
7397
7279
|
num2num_with_frac(jd, 1);
|
|
7398
7280
|
}
|
|
7399
7281
|
|
|
@@ -7402,7 +7284,7 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
|
|
|
7402
7284
|
int rh, rmin, rs, rjd, rjd2;
|
|
7403
7285
|
|
|
7404
7286
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
|
7405
|
-
rb_raise(
|
|
7287
|
+
rb_raise(eDateError, "invalid date");
|
|
7406
7288
|
canon24oc();
|
|
7407
7289
|
|
|
7408
7290
|
decode_jd(jd, &nth, &rjd);
|
|
@@ -7457,14 +7339,19 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
|
7457
7339
|
case 6:
|
|
7458
7340
|
val2off(vof, rof);
|
|
7459
7341
|
case 5:
|
|
7342
|
+
check_numeric(vs, "second");
|
|
7460
7343
|
num2int_with_frac(s, positive_inf);
|
|
7461
7344
|
case 4:
|
|
7345
|
+
check_numeric(vmin, "minute");
|
|
7462
7346
|
num2int_with_frac(min, 4);
|
|
7463
7347
|
case 3:
|
|
7348
|
+
check_numeric(vh, "hour");
|
|
7464
7349
|
num2int_with_frac(h, 3);
|
|
7465
7350
|
case 2:
|
|
7351
|
+
check_numeric(vd, "yday");
|
|
7466
7352
|
num2int_with_frac(d, 2);
|
|
7467
7353
|
case 1:
|
|
7354
|
+
check_numeric(vy, "year");
|
|
7468
7355
|
y = vy;
|
|
7469
7356
|
}
|
|
7470
7357
|
|
|
@@ -7476,9 +7363,9 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
|
|
|
7476
7363
|
&nth, &ry,
|
|
7477
7364
|
&rd, &rjd,
|
|
7478
7365
|
&ns))
|
|
7479
|
-
rb_raise(
|
|
7366
|
+
rb_raise(eDateError, "invalid date");
|
|
7480
7367
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
|
7481
|
-
rb_raise(
|
|
7368
|
+
rb_raise(eDateError, "invalid date");
|
|
7482
7369
|
canon24oc();
|
|
7483
7370
|
|
|
7484
7371
|
rjd2 = jd_local_to_utc(rjd,
|
|
@@ -7545,16 +7432,22 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
7545
7432
|
case 7:
|
|
7546
7433
|
val2off(vof, rof);
|
|
7547
7434
|
case 6:
|
|
7435
|
+
check_numeric(vs, "second");
|
|
7548
7436
|
num2int_with_frac(s, positive_inf);
|
|
7549
7437
|
case 5:
|
|
7438
|
+
check_numeric(vmin, "minute");
|
|
7550
7439
|
num2int_with_frac(min, 5);
|
|
7551
7440
|
case 4:
|
|
7441
|
+
check_numeric(vh, "hour");
|
|
7552
7442
|
num2int_with_frac(h, 4);
|
|
7553
7443
|
case 3:
|
|
7444
|
+
check_numeric(vd, "day");
|
|
7554
7445
|
num2int_with_frac(d, 3);
|
|
7555
7446
|
case 2:
|
|
7447
|
+
check_numeric(vm, "month");
|
|
7556
7448
|
m = NUM2INT(vm);
|
|
7557
7449
|
case 1:
|
|
7450
|
+
check_numeric(vy, "year");
|
|
7558
7451
|
y = vy;
|
|
7559
7452
|
}
|
|
7560
7453
|
|
|
@@ -7565,9 +7458,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
7565
7458
|
if (!valid_gregorian_p(y, m, d,
|
|
7566
7459
|
&nth, &ry,
|
|
7567
7460
|
&rm, &rd))
|
|
7568
|
-
rb_raise(
|
|
7461
|
+
rb_raise(eDateError, "invalid date");
|
|
7569
7462
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
|
7570
|
-
rb_raise(
|
|
7463
|
+
rb_raise(eDateError, "invalid date");
|
|
7571
7464
|
canon24oc();
|
|
7572
7465
|
|
|
7573
7466
|
set_to_complex(self, dat,
|
|
@@ -7586,9 +7479,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
7586
7479
|
&nth, &ry,
|
|
7587
7480
|
&rm, &rd, &rjd,
|
|
7588
7481
|
&ns))
|
|
7589
|
-
rb_raise(
|
|
7482
|
+
rb_raise(eDateError, "invalid date");
|
|
7590
7483
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
|
7591
|
-
rb_raise(
|
|
7484
|
+
rb_raise(eDateError, "invalid date");
|
|
7592
7485
|
canon24oc();
|
|
7593
7486
|
|
|
7594
7487
|
rjd2 = jd_local_to_utc(rjd,
|
|
@@ -7643,16 +7536,22 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
|
7643
7536
|
case 7:
|
|
7644
7537
|
val2off(vof, rof);
|
|
7645
7538
|
case 6:
|
|
7539
|
+
check_numeric(vs, "second");
|
|
7646
7540
|
num2int_with_frac(s, positive_inf);
|
|
7647
7541
|
case 5:
|
|
7542
|
+
check_numeric(vmin, "minute");
|
|
7648
7543
|
num2int_with_frac(min, 5);
|
|
7649
7544
|
case 4:
|
|
7545
|
+
check_numeric(vh, "hour");
|
|
7650
7546
|
num2int_with_frac(h, 4);
|
|
7651
7547
|
case 3:
|
|
7548
|
+
check_numeric(vd, "cwday");
|
|
7652
7549
|
num2int_with_frac(d, 3);
|
|
7653
7550
|
case 2:
|
|
7551
|
+
check_numeric(vw, "cweek");
|
|
7654
7552
|
w = NUM2INT(vw);
|
|
7655
7553
|
case 1:
|
|
7554
|
+
check_numeric(vy, "year");
|
|
7656
7555
|
y = vy;
|
|
7657
7556
|
}
|
|
7658
7557
|
|
|
@@ -7664,9 +7563,9 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
|
|
|
7664
7563
|
&nth, &ry,
|
|
7665
7564
|
&rw, &rd, &rjd,
|
|
7666
7565
|
&ns))
|
|
7667
|
-
rb_raise(
|
|
7566
|
+
rb_raise(eDateError, "invalid date");
|
|
7668
7567
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
|
7669
|
-
rb_raise(
|
|
7568
|
+
rb_raise(eDateError, "invalid date");
|
|
7670
7569
|
canon24oc();
|
|
7671
7570
|
|
|
7672
7571
|
rjd2 = jd_local_to_utc(rjd,
|
|
@@ -7735,9 +7634,9 @@ datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
|
|
|
7735
7634
|
&nth, &ry,
|
|
7736
7635
|
&rw, &rd, &rjd,
|
|
7737
7636
|
&ns))
|
|
7738
|
-
rb_raise(
|
|
7637
|
+
rb_raise(eDateError, "invalid date");
|
|
7739
7638
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
|
7740
|
-
rb_raise(
|
|
7639
|
+
rb_raise(eDateError, "invalid date");
|
|
7741
7640
|
canon24oc();
|
|
7742
7641
|
|
|
7743
7642
|
rjd2 = jd_local_to_utc(rjd,
|
|
@@ -7804,9 +7703,9 @@ datetime_s_nth_kday(int argc, VALUE *argv, VALUE klass)
|
|
|
7804
7703
|
&nth, &ry,
|
|
7805
7704
|
&rm, &rn, &rk, &rjd,
|
|
7806
7705
|
&ns))
|
|
7807
|
-
rb_raise(
|
|
7706
|
+
rb_raise(eDateError, "invalid date");
|
|
7808
7707
|
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
|
|
7809
|
-
rb_raise(
|
|
7708
|
+
rb_raise(eDateError, "invalid date");
|
|
7810
7709
|
canon24oc();
|
|
7811
7710
|
|
|
7812
7711
|
rjd2 = jd_local_to_utc(rjd,
|
|
@@ -7949,7 +7848,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
|
7949
7848
|
}
|
|
7950
7849
|
|
|
7951
7850
|
if (NIL_P(hash))
|
|
7952
|
-
rb_raise(
|
|
7851
|
+
rb_raise(eDateError, "invalid date");
|
|
7953
7852
|
|
|
7954
7853
|
if (NIL_P(ref_hash("jd")) &&
|
|
7955
7854
|
NIL_P(ref_hash("yday")) &&
|
|
@@ -7976,7 +7875,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
|
7976
7875
|
}
|
|
7977
7876
|
|
|
7978
7877
|
if (NIL_P(jd))
|
|
7979
|
-
rb_raise(
|
|
7878
|
+
rb_raise(eDateError, "invalid date");
|
|
7980
7879
|
|
|
7981
7880
|
{
|
|
7982
7881
|
int rh, rmin, rs;
|
|
@@ -7985,7 +7884,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
|
|
|
7985
7884
|
NUM2INT(ref_hash("min")),
|
|
7986
7885
|
NUM2INT(ref_hash("sec")),
|
|
7987
7886
|
&rh, &rmin, &rs))
|
|
7988
|
-
rb_raise(
|
|
7887
|
+
rb_raise(eDateError, "invalid date");
|
|
7989
7888
|
|
|
7990
7889
|
df = time_to_df(rh, rmin, rs);
|
|
7991
7890
|
}
|
|
@@ -8095,7 +7994,7 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
|
|
|
8095
7994
|
|
|
8096
7995
|
/*
|
|
8097
7996
|
* call-seq:
|
|
8098
|
-
* DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]
|
|
7997
|
+
* DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]) -> datetime
|
|
8099
7998
|
*
|
|
8100
7999
|
* Parses the given representation of date and time, and creates a
|
|
8101
8000
|
* DateTime object. This method does not function as a validator.
|
|
@@ -8109,18 +8008,13 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
|
|
|
8109
8008
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
|
8110
8009
|
* DateTime.parse('3rd Feb 2001 04:05:06 PM')
|
|
8111
8010
|
* #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
|
|
8112
|
-
*
|
|
8113
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
8114
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
8115
|
-
* it may take a long time to parse.
|
|
8116
8011
|
*/
|
|
8117
8012
|
static VALUE
|
|
8118
8013
|
datetime_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
8119
8014
|
{
|
|
8120
|
-
VALUE str, comp, sg
|
|
8015
|
+
VALUE str, comp, sg;
|
|
8121
8016
|
|
|
8122
|
-
rb_scan_args(argc, argv, "03
|
|
8123
|
-
if (!NIL_P(opt)) argc--;
|
|
8017
|
+
rb_scan_args(argc, argv, "03", &str, &comp, &sg);
|
|
8124
8018
|
|
|
8125
8019
|
switch (argc) {
|
|
8126
8020
|
case 0:
|
|
@@ -8132,20 +8026,18 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
|
8132
8026
|
}
|
|
8133
8027
|
|
|
8134
8028
|
{
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
if (!NIL_P(opt)) argc2++;
|
|
8141
|
-
VALUE hash = date_s__parse(argc2, argv2, klass);
|
|
8029
|
+
VALUE argv2[2], hash;
|
|
8030
|
+
|
|
8031
|
+
argv2[0] = str;
|
|
8032
|
+
argv2[1] = comp;
|
|
8033
|
+
hash = date_s__parse(2, argv2, klass);
|
|
8142
8034
|
return dt_new_by_frags(klass, hash, sg);
|
|
8143
8035
|
}
|
|
8144
8036
|
}
|
|
8145
8037
|
|
|
8146
8038
|
/*
|
|
8147
8039
|
* call-seq:
|
|
8148
|
-
* DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]
|
|
8040
|
+
* DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
|
|
8149
8041
|
*
|
|
8150
8042
|
* Creates a new DateTime object by parsing from a string according to
|
|
8151
8043
|
* some typical ISO 8601 formats.
|
|
@@ -8156,18 +8048,13 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
|
8156
8048
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
|
8157
8049
|
* DateTime.iso8601('2001-W05-6T04:05:06+07:00')
|
|
8158
8050
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
|
8159
|
-
*
|
|
8160
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
8161
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
8162
|
-
* it may take a long time to parse.
|
|
8163
8051
|
*/
|
|
8164
8052
|
static VALUE
|
|
8165
8053
|
datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
|
|
8166
8054
|
{
|
|
8167
|
-
VALUE str, sg
|
|
8055
|
+
VALUE str, sg;
|
|
8168
8056
|
|
|
8169
|
-
rb_scan_args(argc, argv, "02
|
|
8170
|
-
if (!NIL_P(opt)) argc--;
|
|
8057
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
8171
8058
|
|
|
8172
8059
|
switch (argc) {
|
|
8173
8060
|
case 0:
|
|
@@ -8177,37 +8064,27 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
|
|
|
8177
8064
|
}
|
|
8178
8065
|
|
|
8179
8066
|
{
|
|
8180
|
-
|
|
8181
|
-
VALUE argv2[2];
|
|
8182
|
-
argv2[0] = str;
|
|
8183
|
-
argv2[1] = opt;
|
|
8184
|
-
if (!NIL_P(opt)) argc2--;
|
|
8185
|
-
VALUE hash = date_s__iso8601(argc2, argv2, klass);
|
|
8067
|
+
VALUE hash = date_s__iso8601(klass, str);
|
|
8186
8068
|
return dt_new_by_frags(klass, hash, sg);
|
|
8187
8069
|
}
|
|
8188
8070
|
}
|
|
8189
8071
|
|
|
8190
8072
|
/*
|
|
8191
8073
|
* call-seq:
|
|
8192
|
-
* DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]
|
|
8074
|
+
* DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
|
|
8193
8075
|
*
|
|
8194
8076
|
* Creates a new DateTime object by parsing from a string according to
|
|
8195
8077
|
* some typical RFC 3339 formats.
|
|
8196
8078
|
*
|
|
8197
8079
|
* DateTime.rfc3339('2001-02-03T04:05:06+07:00')
|
|
8198
8080
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
|
8199
|
-
*
|
|
8200
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
8201
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
8202
|
-
* it may take a long time to parse.
|
|
8203
8081
|
*/
|
|
8204
8082
|
static VALUE
|
|
8205
8083
|
datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
|
|
8206
8084
|
{
|
|
8207
|
-
VALUE str, sg
|
|
8085
|
+
VALUE str, sg;
|
|
8208
8086
|
|
|
8209
|
-
rb_scan_args(argc, argv, "02
|
|
8210
|
-
if (!NIL_P(opt)) argc--;
|
|
8087
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
8211
8088
|
|
|
8212
8089
|
switch (argc) {
|
|
8213
8090
|
case 0:
|
|
@@ -8217,37 +8094,27 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
|
|
|
8217
8094
|
}
|
|
8218
8095
|
|
|
8219
8096
|
{
|
|
8220
|
-
|
|
8221
|
-
VALUE argv2[2];
|
|
8222
|
-
argv2[0] = str;
|
|
8223
|
-
argv2[1] = opt;
|
|
8224
|
-
if (!NIL_P(opt)) argc2++;
|
|
8225
|
-
VALUE hash = date_s__rfc3339(argc2, argv2, klass);
|
|
8097
|
+
VALUE hash = date_s__rfc3339(klass, str);
|
|
8226
8098
|
return dt_new_by_frags(klass, hash, sg);
|
|
8227
8099
|
}
|
|
8228
8100
|
}
|
|
8229
8101
|
|
|
8230
8102
|
/*
|
|
8231
8103
|
* call-seq:
|
|
8232
|
-
* DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]
|
|
8104
|
+
* DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
|
|
8233
8105
|
*
|
|
8234
8106
|
* Creates a new DateTime object by parsing from a string according to
|
|
8235
8107
|
* some typical XML Schema formats.
|
|
8236
8108
|
*
|
|
8237
8109
|
* DateTime.xmlschema('2001-02-03T04:05:06+07:00')
|
|
8238
8110
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
|
8239
|
-
*
|
|
8240
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
8241
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
8242
|
-
* it may take a long time to parse.
|
|
8243
8111
|
*/
|
|
8244
8112
|
static VALUE
|
|
8245
8113
|
datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
|
|
8246
8114
|
{
|
|
8247
|
-
VALUE str, sg
|
|
8115
|
+
VALUE str, sg;
|
|
8248
8116
|
|
|
8249
|
-
rb_scan_args(argc, argv, "02
|
|
8250
|
-
if (!NIL_P(opt)) argc--;
|
|
8117
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
8251
8118
|
|
|
8252
8119
|
switch (argc) {
|
|
8253
8120
|
case 0:
|
|
@@ -8257,38 +8124,28 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
|
|
|
8257
8124
|
}
|
|
8258
8125
|
|
|
8259
8126
|
{
|
|
8260
|
-
|
|
8261
|
-
VALUE argv2[2];
|
|
8262
|
-
argv2[0] = str;
|
|
8263
|
-
argv2[1] = opt;
|
|
8264
|
-
if (!NIL_P(opt)) argc2++;
|
|
8265
|
-
VALUE hash = date_s__xmlschema(argc2, argv2, klass);
|
|
8127
|
+
VALUE hash = date_s__xmlschema(klass, str);
|
|
8266
8128
|
return dt_new_by_frags(klass, hash, sg);
|
|
8267
8129
|
}
|
|
8268
8130
|
}
|
|
8269
8131
|
|
|
8270
8132
|
/*
|
|
8271
8133
|
* call-seq:
|
|
8272
|
-
* DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]
|
|
8273
|
-
* DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]
|
|
8134
|
+
* DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
|
|
8135
|
+
* DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
|
|
8274
8136
|
*
|
|
8275
8137
|
* Creates a new DateTime object by parsing from a string according to
|
|
8276
8138
|
* some typical RFC 2822 formats.
|
|
8277
8139
|
*
|
|
8278
8140
|
* DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700')
|
|
8279
8141
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
|
8280
|
-
*
|
|
8281
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
8282
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
8283
|
-
* it may take a long time to parse.
|
|
8284
8142
|
*/
|
|
8285
8143
|
static VALUE
|
|
8286
8144
|
datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
|
|
8287
8145
|
{
|
|
8288
|
-
VALUE str, sg
|
|
8146
|
+
VALUE str, sg;
|
|
8289
8147
|
|
|
8290
|
-
rb_scan_args(argc, argv, "02
|
|
8291
|
-
if (!NIL_P(opt)) argc--;
|
|
8148
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
8292
8149
|
|
|
8293
8150
|
switch (argc) {
|
|
8294
8151
|
case 0:
|
|
@@ -8298,12 +8155,7 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
|
|
|
8298
8155
|
}
|
|
8299
8156
|
|
|
8300
8157
|
{
|
|
8301
|
-
|
|
8302
|
-
VALUE argv2[2];
|
|
8303
|
-
argv2[0] = str;
|
|
8304
|
-
argv2[1] = opt;
|
|
8305
|
-
if (!NIL_P(opt)) argc2++;
|
|
8306
|
-
VALUE hash = date_s__rfc2822(argc2, argv2, klass);
|
|
8158
|
+
VALUE hash = date_s__rfc2822(klass, str);
|
|
8307
8159
|
return dt_new_by_frags(klass, hash, sg);
|
|
8308
8160
|
}
|
|
8309
8161
|
}
|
|
@@ -8317,18 +8169,13 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
|
|
|
8317
8169
|
*
|
|
8318
8170
|
* DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
|
|
8319
8171
|
* #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
|
|
8320
|
-
*
|
|
8321
|
-
* Raise an ArgumentError when the string length is longer than _limit_.
|
|
8322
|
-
* You can stop this check by passing `limit: nil`, but note that
|
|
8323
|
-
* it may take a long time to parse.
|
|
8324
8172
|
*/
|
|
8325
8173
|
static VALUE
|
|
8326
8174
|
datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
|
|
8327
8175
|
{
|
|
8328
|
-
VALUE str, sg
|
|
8176
|
+
VALUE str, sg;
|
|
8329
8177
|
|
|
8330
|
-
rb_scan_args(argc, argv, "02
|
|
8331
|
-
if (!NIL_P(opt)) argc--;
|
|
8178
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
8332
8179
|
|
|
8333
8180
|
switch (argc) {
|
|
8334
8181
|
case 0:
|
|
@@ -8338,19 +8185,14 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
|
|
|
8338
8185
|
}
|
|
8339
8186
|
|
|
8340
8187
|
{
|
|
8341
|
-
|
|
8342
|
-
VALUE argv2[2];
|
|
8343
|
-
argv2[0] = str;
|
|
8344
|
-
argv2[1] = opt;
|
|
8345
|
-
if (!NIL_P(opt)) argc2++;
|
|
8346
|
-
VALUE hash = date_s__httpdate(argc2, argv2, klass);
|
|
8188
|
+
VALUE hash = date_s__httpdate(klass, str);
|
|
8347
8189
|
return dt_new_by_frags(klass, hash, sg);
|
|
8348
8190
|
}
|
|
8349
8191
|
}
|
|
8350
8192
|
|
|
8351
8193
|
/*
|
|
8352
8194
|
* call-seq:
|
|
8353
|
-
* DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]
|
|
8195
|
+
* DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
|
|
8354
8196
|
*
|
|
8355
8197
|
* Creates a new DateTime object by parsing from a string according to
|
|
8356
8198
|
* some typical JIS X 0301 formats.
|
|
@@ -8358,17 +8200,17 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
|
|
|
8358
8200
|
* DateTime.jisx0301('H13.02.03T04:05:06+07:00')
|
|
8359
8201
|
* #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
|
|
8360
8202
|
*
|
|
8361
|
-
*
|
|
8362
|
-
*
|
|
8363
|
-
*
|
|
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 ...>
|
|
8364
8207
|
*/
|
|
8365
8208
|
static VALUE
|
|
8366
8209
|
datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
|
|
8367
8210
|
{
|
|
8368
|
-
VALUE str, sg
|
|
8211
|
+
VALUE str, sg;
|
|
8369
8212
|
|
|
8370
|
-
rb_scan_args(argc, argv, "02
|
|
8371
|
-
if (!NIL_P(opt)) argc--;
|
|
8213
|
+
rb_scan_args(argc, argv, "02", &str, &sg);
|
|
8372
8214
|
|
|
8373
8215
|
switch (argc) {
|
|
8374
8216
|
case 0:
|
|
@@ -8378,12 +8220,7 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
|
|
|
8378
8220
|
}
|
|
8379
8221
|
|
|
8380
8222
|
{
|
|
8381
|
-
|
|
8382
|
-
VALUE argv2[2];
|
|
8383
|
-
argv2[0] = str;
|
|
8384
|
-
argv2[1] = opt;
|
|
8385
|
-
if (!NIL_P(opt)) argc2++;
|
|
8386
|
-
VALUE hash = date_s__jisx0301(argc2, argv2, klass);
|
|
8223
|
+
VALUE hash = date_s__jisx0301(klass, str);
|
|
8387
8224
|
return dt_new_by_frags(klass, hash, sg);
|
|
8388
8225
|
}
|
|
8389
8226
|
}
|
|
@@ -8761,17 +8598,24 @@ time_to_datetime(VALUE self)
|
|
|
8761
8598
|
* call-seq:
|
|
8762
8599
|
* d.to_time -> time
|
|
8763
8600
|
*
|
|
8764
|
-
* 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.
|
|
8765
8603
|
*/
|
|
8766
8604
|
static VALUE
|
|
8767
8605
|
date_to_time(VALUE self)
|
|
8768
8606
|
{
|
|
8769
|
-
|
|
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
|
+
}
|
|
8770
8614
|
|
|
8771
8615
|
return f_local3(rb_cTime,
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8616
|
+
m_real_year(adat),
|
|
8617
|
+
INT2FIX(m_mon(adat)),
|
|
8618
|
+
INT2FIX(m_mday(adat)));
|
|
8775
8619
|
}
|
|
8776
8620
|
|
|
8777
8621
|
/*
|
|
@@ -9428,6 +9272,7 @@ Init_date_core(void)
|
|
|
9428
9272
|
*
|
|
9429
9273
|
*/
|
|
9430
9274
|
cDate = rb_define_class("Date", rb_cObject);
|
|
9275
|
+
eDateError = rb_define_class_under(cDate, "Error", rb_eArgError);
|
|
9431
9276
|
|
|
9432
9277
|
rb_include_module(cDate, rb_mComparable);
|
|
9433
9278
|
|
|
@@ -9534,19 +9379,19 @@ Init_date_core(void)
|
|
|
9534
9379
|
rb_define_singleton_method(cDate, "strptime", date_s_strptime, -1);
|
|
9535
9380
|
rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
|
|
9536
9381
|
rb_define_singleton_method(cDate, "parse", date_s_parse, -1);
|
|
9537
|
-
rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601,
|
|
9382
|
+
rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, 1);
|
|
9538
9383
|
rb_define_singleton_method(cDate, "iso8601", date_s_iso8601, -1);
|
|
9539
|
-
rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339,
|
|
9384
|
+
rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, 1);
|
|
9540
9385
|
rb_define_singleton_method(cDate, "rfc3339", date_s_rfc3339, -1);
|
|
9541
|
-
rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema,
|
|
9386
|
+
rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, 1);
|
|
9542
9387
|
rb_define_singleton_method(cDate, "xmlschema", date_s_xmlschema, -1);
|
|
9543
|
-
rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822,
|
|
9544
|
-
rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822,
|
|
9388
|
+
rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, 1);
|
|
9389
|
+
rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, 1);
|
|
9545
9390
|
rb_define_singleton_method(cDate, "rfc2822", date_s_rfc2822, -1);
|
|
9546
9391
|
rb_define_singleton_method(cDate, "rfc822", date_s_rfc2822, -1);
|
|
9547
|
-
rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate,
|
|
9392
|
+
rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, 1);
|
|
9548
9393
|
rb_define_singleton_method(cDate, "httpdate", date_s_httpdate, -1);
|
|
9549
|
-
rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301,
|
|
9394
|
+
rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
|
|
9550
9395
|
rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
|
|
9551
9396
|
|
|
9552
9397
|
rb_define_method(cDate, "initialize", date_initialize, -1);
|