date 2.0.3 → 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.
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(rb_eArgError, "invalid day fraction");
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(rb_eArgError, "invalid fraction");\
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(rb_eArgError, "invalid fraction");\
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(rb_eArgError, "invalid date");
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(rb_eArgError, "invalid date");
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(rb_eArgError, "invalid date");
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(rb_eArgError, "invalid date");
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(rb_eArgError, "invalid date");
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(rb_eArgError, "invalid date");
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 = ref_hash("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(rb_eArgError, "invalid date");
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(rb_eArgError, "invalid date");
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, opt;
4327
+ VALUE vstr, vcomp, hash;
4325
4328
 
4326
- rb_scan_args(argc, argv, "11:", &vstr, &vcomp, &opt);
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], limit: 128) -> hash
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]], limit: 128) -> date
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, opt;
4380
+ VALUE str, comp, sg;
4398
4381
 
4399
- rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
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
- int argc2 = 2;
4413
- VALUE argv2[3];
4414
- argv2[0] = str;
4415
- argv2[1] = comp;
4416
- if (!NIL_P(opt)) argv2[argc2++] = opt;
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, limit: 128) -> hash
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(int argc, VALUE *argv, VALUE klass)
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], limit: 128) -> date
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, opt;
4436
+ VALUE str, sg;
4469
4437
 
4470
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
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
- int argc2 = 1;
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, limit: 128) -> hash
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(int argc, VALUE *argv, VALUE klass)
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], limit: 128) -> date
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, opt;
4477
+ VALUE str, sg;
4528
4478
 
4529
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
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
- int argc2 = 1;
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, limit: 128) -> hash
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(int argc, VALUE *argv, VALUE klass)
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], limit: 128) -> date
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, opt;
4518
+ VALUE str, sg;
4587
4519
 
4588
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
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
- int argc2 = 1;
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, limit: 128) -> hash
4611
- * Date._rfc822(string, limit: 128) -> hash
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(int argc, VALUE *argv, VALUE klass)
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], limit: 128) -> date
4633
- * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
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, opt;
4562
+ VALUE str, sg;
4649
4563
 
4650
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
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
- int argc2 = 1;
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, limit: 128) -> hash
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(int argc, VALUE *argv, VALUE klass)
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], limit: 128) -> date
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, opt;
4604
+ VALUE str, sg;
4708
4605
 
4709
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4606
+ rb_scan_args(argc, argv, "02", &str, &sg);
4710
4607
 
4711
4608
  switch (argc) {
4712
4609
  case 0:
@@ -4716,39 +4613,26 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4716
4613
  }
4717
4614
 
4718
4615
  {
4719
- int argc2 = 1;
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, limit: 128) -> hash
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(int argc, VALUE *argv, VALUE klass)
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], limit: 128) -> date
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.
@@ -4758,18 +4642,13 @@ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4758
4642
  * For no-era year, legacy format, Heisei is assumed.
4759
4643
  *
4760
4644
  * Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
4761
- *
4762
- * Raise an ArgumentError when the string length is longer than _limit_.
4763
- * You can stop this check by passing `limit: nil`, but note that
4764
- * it may take a long time to parse.
4765
4645
  */
4766
4646
  static VALUE
4767
4647
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4768
4648
  {
4769
- VALUE str, sg, opt;
4649
+ VALUE str, sg;
4770
4650
 
4771
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4772
- if (!NIL_P(opt)) argc--;
4651
+ rb_scan_args(argc, argv, "02", &str, &sg);
4773
4652
 
4774
4653
  switch (argc) {
4775
4654
  case 0:
@@ -4779,11 +4658,7 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4779
4658
  }
4780
4659
 
4781
4660
  {
4782
- int argc2 = 1;
4783
- VALUE argv2[2];
4784
- argv2[0] = str;
4785
- if (!NIL_P(opt)) argv2[argc2++] = opt;
4786
- VALUE hash = date_s__jisx0301(argc2, argv2, klass);
4661
+ VALUE hash = date_s__jisx0301(klass, str);
4787
4662
  return d_new_by_frags(klass, hash, sg);
4788
4663
  }
4789
4664
  }
@@ -4857,7 +4732,6 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
4857
4732
  double sg;
4858
4733
 
4859
4734
  rb_check_frozen(self);
4860
- rb_check_trusted(self);
4861
4735
 
4862
4736
  rb_scan_args(argc, argv, "05", &vjd, &vdf, &vsf, &vof, &vsg);
4863
4737
 
@@ -4876,11 +4750,11 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
4876
4750
  sf = vsf;
4877
4751
  if (f_lt_p(sf, INT2FIX(0)) ||
4878
4752
  f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS)))
4879
- rb_raise(rb_eArgError, "invalid second fraction");
4753
+ rb_raise(eDateError, "invalid second fraction");
4880
4754
  case 2:
4881
4755
  df = NUM2INT(vdf);
4882
4756
  if (df < 0 || df >= DAY_IN_SECONDS)
4883
- rb_raise(rb_eArgError, "invalid day fraction");
4757
+ rb_raise(eDateError, "invalid day fraction");
4884
4758
  case 1:
4885
4759
  jd = vjd;
4886
4760
  }
@@ -4913,7 +4787,6 @@ static VALUE
4913
4787
  d_lite_initialize_copy(VALUE copy, VALUE date)
4914
4788
  {
4915
4789
  rb_check_frozen(copy);
4916
- rb_check_trusted(copy);
4917
4790
 
4918
4791
  if (copy == date)
4919
4792
  return copy;
@@ -6191,7 +6064,7 @@ d_lite_rshift(VALUE self, VALUE other)
6191
6064
  &rm, &rd, &rjd, &ns))
6192
6065
  break;
6193
6066
  if (--d < 1)
6194
- rb_raise(rb_eArgError, "invalid date");
6067
+ rb_raise(eDateError, "invalid date");
6195
6068
  }
6196
6069
  encode_jd(nth, rjd, &rjd2);
6197
6070
  return d_lite_plus(self, f_sub(rjd2, m_real_local_jd(dat)));
@@ -6715,9 +6588,9 @@ mk_inspect(union DateData *x, VALUE klass, VALUE to_s)
6715
6588
  * Returns the value as a string for inspection.
6716
6589
  *
6717
6590
  * Date.new(2001,2,3).inspect
6718
- * #=> "#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>"
6591
+ * #=> "#<Date: 2001-02-03>"
6719
6592
  * DateTime.new(2001,2,3,4,5,6,'-7').inspect
6720
- * #=> "#<DateTime: 2001-02-03T04:05:06-07:00 ((2451944j,39906s,0n),-25200s,2299161j)>"
6593
+ * #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
6721
6594
  */
6722
6595
  static VALUE
6723
6596
  d_lite_inspect(VALUE self)
@@ -6886,7 +6759,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
6886
6759
  if (p > fmt) rb_str_cat(str, fmt, p - fmt);
6887
6760
  }
6888
6761
  rb_enc_copy(str, vfmt);
6889
- OBJ_INFECT(str, vfmt);
6890
6762
  return str;
6891
6763
  }
6892
6764
  else
@@ -6895,7 +6767,6 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
6895
6767
  str = rb_str_new(buf, len);
6896
6768
  if (buf != buffer) xfree(buf);
6897
6769
  rb_enc_copy(str, vfmt);
6898
- OBJ_INFECT(str, vfmt);
6899
6770
  return str;
6900
6771
  }
6901
6772
 
@@ -7286,7 +7157,6 @@ d_lite_marshal_load(VALUE self, VALUE a)
7286
7157
  get_d1(self);
7287
7158
 
7288
7159
  rb_check_frozen(self);
7289
- rb_check_trusted(self);
7290
7160
 
7291
7161
  if (!RB_TYPE_P(a, T_ARRAY))
7292
7162
  rb_raise(rb_eTypeError, "expected an array");
@@ -7396,12 +7266,16 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
7396
7266
  case 5:
7397
7267
  val2off(vof, rof);
7398
7268
  case 4:
7269
+ check_numeric(vs, "second");
7399
7270
  num2int_with_frac(s, positive_inf);
7400
7271
  case 3:
7272
+ check_numeric(vmin, "minute");
7401
7273
  num2int_with_frac(min, 3);
7402
7274
  case 2:
7275
+ check_numeric(vh, "hour");
7403
7276
  num2int_with_frac(h, 2);
7404
7277
  case 1:
7278
+ check_numeric(vjd, "jd");
7405
7279
  num2num_with_frac(jd, 1);
7406
7280
  }
7407
7281
 
@@ -7410,7 +7284,7 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
7410
7284
  int rh, rmin, rs, rjd, rjd2;
7411
7285
 
7412
7286
  if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
7413
- rb_raise(rb_eArgError, "invalid date");
7287
+ rb_raise(eDateError, "invalid date");
7414
7288
  canon24oc();
7415
7289
 
7416
7290
  decode_jd(jd, &nth, &rjd);
@@ -7465,14 +7339,19 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
7465
7339
  case 6:
7466
7340
  val2off(vof, rof);
7467
7341
  case 5:
7342
+ check_numeric(vs, "second");
7468
7343
  num2int_with_frac(s, positive_inf);
7469
7344
  case 4:
7345
+ check_numeric(vmin, "minute");
7470
7346
  num2int_with_frac(min, 4);
7471
7347
  case 3:
7348
+ check_numeric(vh, "hour");
7472
7349
  num2int_with_frac(h, 3);
7473
7350
  case 2:
7351
+ check_numeric(vd, "yday");
7474
7352
  num2int_with_frac(d, 2);
7475
7353
  case 1:
7354
+ check_numeric(vy, "year");
7476
7355
  y = vy;
7477
7356
  }
7478
7357
 
@@ -7484,9 +7363,9 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
7484
7363
  &nth, &ry,
7485
7364
  &rd, &rjd,
7486
7365
  &ns))
7487
- rb_raise(rb_eArgError, "invalid date");
7366
+ rb_raise(eDateError, "invalid date");
7488
7367
  if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
7489
- rb_raise(rb_eArgError, "invalid date");
7368
+ rb_raise(eDateError, "invalid date");
7490
7369
  canon24oc();
7491
7370
 
7492
7371
  rjd2 = jd_local_to_utc(rjd,
@@ -7553,16 +7432,22 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
7553
7432
  case 7:
7554
7433
  val2off(vof, rof);
7555
7434
  case 6:
7435
+ check_numeric(vs, "second");
7556
7436
  num2int_with_frac(s, positive_inf);
7557
7437
  case 5:
7438
+ check_numeric(vmin, "minute");
7558
7439
  num2int_with_frac(min, 5);
7559
7440
  case 4:
7441
+ check_numeric(vh, "hour");
7560
7442
  num2int_with_frac(h, 4);
7561
7443
  case 3:
7444
+ check_numeric(vd, "day");
7562
7445
  num2int_with_frac(d, 3);
7563
7446
  case 2:
7447
+ check_numeric(vm, "month");
7564
7448
  m = NUM2INT(vm);
7565
7449
  case 1:
7450
+ check_numeric(vy, "year");
7566
7451
  y = vy;
7567
7452
  }
7568
7453
 
@@ -7573,9 +7458,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
7573
7458
  if (!valid_gregorian_p(y, m, d,
7574
7459
  &nth, &ry,
7575
7460
  &rm, &rd))
7576
- rb_raise(rb_eArgError, "invalid date");
7461
+ rb_raise(eDateError, "invalid date");
7577
7462
  if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
7578
- rb_raise(rb_eArgError, "invalid date");
7463
+ rb_raise(eDateError, "invalid date");
7579
7464
  canon24oc();
7580
7465
 
7581
7466
  set_to_complex(self, dat,
@@ -7594,9 +7479,9 @@ datetime_initialize(int argc, VALUE *argv, VALUE self)
7594
7479
  &nth, &ry,
7595
7480
  &rm, &rd, &rjd,
7596
7481
  &ns))
7597
- rb_raise(rb_eArgError, "invalid date");
7482
+ rb_raise(eDateError, "invalid date");
7598
7483
  if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
7599
- rb_raise(rb_eArgError, "invalid date");
7484
+ rb_raise(eDateError, "invalid date");
7600
7485
  canon24oc();
7601
7486
 
7602
7487
  rjd2 = jd_local_to_utc(rjd,
@@ -7651,16 +7536,22 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
7651
7536
  case 7:
7652
7537
  val2off(vof, rof);
7653
7538
  case 6:
7539
+ check_numeric(vs, "second");
7654
7540
  num2int_with_frac(s, positive_inf);
7655
7541
  case 5:
7542
+ check_numeric(vmin, "minute");
7656
7543
  num2int_with_frac(min, 5);
7657
7544
  case 4:
7545
+ check_numeric(vh, "hour");
7658
7546
  num2int_with_frac(h, 4);
7659
7547
  case 3:
7548
+ check_numeric(vd, "cwday");
7660
7549
  num2int_with_frac(d, 3);
7661
7550
  case 2:
7551
+ check_numeric(vw, "cweek");
7662
7552
  w = NUM2INT(vw);
7663
7553
  case 1:
7554
+ check_numeric(vy, "year");
7664
7555
  y = vy;
7665
7556
  }
7666
7557
 
@@ -7672,9 +7563,9 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
7672
7563
  &nth, &ry,
7673
7564
  &rw, &rd, &rjd,
7674
7565
  &ns))
7675
- rb_raise(rb_eArgError, "invalid date");
7566
+ rb_raise(eDateError, "invalid date");
7676
7567
  if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
7677
- rb_raise(rb_eArgError, "invalid date");
7568
+ rb_raise(eDateError, "invalid date");
7678
7569
  canon24oc();
7679
7570
 
7680
7571
  rjd2 = jd_local_to_utc(rjd,
@@ -7743,9 +7634,9 @@ datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
7743
7634
  &nth, &ry,
7744
7635
  &rw, &rd, &rjd,
7745
7636
  &ns))
7746
- rb_raise(rb_eArgError, "invalid date");
7637
+ rb_raise(eDateError, "invalid date");
7747
7638
  if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
7748
- rb_raise(rb_eArgError, "invalid date");
7639
+ rb_raise(eDateError, "invalid date");
7749
7640
  canon24oc();
7750
7641
 
7751
7642
  rjd2 = jd_local_to_utc(rjd,
@@ -7812,9 +7703,9 @@ datetime_s_nth_kday(int argc, VALUE *argv, VALUE klass)
7812
7703
  &nth, &ry,
7813
7704
  &rm, &rn, &rk, &rjd,
7814
7705
  &ns))
7815
- rb_raise(rb_eArgError, "invalid date");
7706
+ rb_raise(eDateError, "invalid date");
7816
7707
  if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
7817
- rb_raise(rb_eArgError, "invalid date");
7708
+ rb_raise(eDateError, "invalid date");
7818
7709
  canon24oc();
7819
7710
 
7820
7711
  rjd2 = jd_local_to_utc(rjd,
@@ -7957,7 +7848,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
7957
7848
  }
7958
7849
 
7959
7850
  if (NIL_P(hash))
7960
- rb_raise(rb_eArgError, "invalid date");
7851
+ rb_raise(eDateError, "invalid date");
7961
7852
 
7962
7853
  if (NIL_P(ref_hash("jd")) &&
7963
7854
  NIL_P(ref_hash("yday")) &&
@@ -7984,7 +7875,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
7984
7875
  }
7985
7876
 
7986
7877
  if (NIL_P(jd))
7987
- rb_raise(rb_eArgError, "invalid date");
7878
+ rb_raise(eDateError, "invalid date");
7988
7879
 
7989
7880
  {
7990
7881
  int rh, rmin, rs;
@@ -7993,7 +7884,7 @@ dt_new_by_frags(VALUE klass, VALUE hash, VALUE sg)
7993
7884
  NUM2INT(ref_hash("min")),
7994
7885
  NUM2INT(ref_hash("sec")),
7995
7886
  &rh, &rmin, &rs))
7996
- rb_raise(rb_eArgError, "invalid date");
7887
+ rb_raise(eDateError, "invalid date");
7997
7888
 
7998
7889
  df = time_to_df(rh, rmin, rs);
7999
7890
  }
@@ -8103,7 +7994,7 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8103
7994
 
8104
7995
  /*
8105
7996
  * call-seq:
8106
- * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]], limit: 128) -> datetime
7997
+ * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]) -> datetime
8107
7998
  *
8108
7999
  * Parses the given representation of date and time, and creates a
8109
8000
  * DateTime object. This method does not function as a validator.
@@ -8117,18 +8008,13 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8117
8008
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8118
8009
  * DateTime.parse('3rd Feb 2001 04:05:06 PM')
8119
8010
  * #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
8120
- *
8121
- * Raise an ArgumentError when the string length is longer than _limit_.
8122
- * You can stop this check by passing `limit: nil`, but note that
8123
- * it may take a long time to parse.
8124
8011
  */
8125
8012
  static VALUE
8126
8013
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8127
8014
  {
8128
- VALUE str, comp, sg, opt;
8015
+ VALUE str, comp, sg;
8129
8016
 
8130
- rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
8131
- if (!NIL_P(opt)) argc--;
8017
+ rb_scan_args(argc, argv, "03", &str, &comp, &sg);
8132
8018
 
8133
8019
  switch (argc) {
8134
8020
  case 0:
@@ -8140,20 +8026,18 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8140
8026
  }
8141
8027
 
8142
8028
  {
8143
- int argc2 = 2;
8144
- VALUE argv2[3];
8145
- argv2[0] = str;
8146
- argv2[1] = comp;
8147
- argv2[2] = opt;
8148
- if (!NIL_P(opt)) argc2++;
8149
- 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);
8150
8034
  return dt_new_by_frags(klass, hash, sg);
8151
8035
  }
8152
8036
  }
8153
8037
 
8154
8038
  /*
8155
8039
  * call-seq:
8156
- * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8040
+ * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8157
8041
  *
8158
8042
  * Creates a new DateTime object by parsing from a string according to
8159
8043
  * some typical ISO 8601 formats.
@@ -8164,18 +8048,13 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8164
8048
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8165
8049
  * DateTime.iso8601('2001-W05-6T04:05:06+07:00')
8166
8050
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8167
- *
8168
- * Raise an ArgumentError when the string length is longer than _limit_.
8169
- * You can stop this check by passing `limit: nil`, but note that
8170
- * it may take a long time to parse.
8171
8051
  */
8172
8052
  static VALUE
8173
8053
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8174
8054
  {
8175
- VALUE str, sg, opt;
8055
+ VALUE str, sg;
8176
8056
 
8177
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8178
- if (!NIL_P(opt)) argc--;
8057
+ rb_scan_args(argc, argv, "02", &str, &sg);
8179
8058
 
8180
8059
  switch (argc) {
8181
8060
  case 0:
@@ -8185,37 +8064,27 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8185
8064
  }
8186
8065
 
8187
8066
  {
8188
- int argc2 = 1;
8189
- VALUE argv2[2];
8190
- argv2[0] = str;
8191
- argv2[1] = opt;
8192
- if (!NIL_P(opt)) argc2--;
8193
- VALUE hash = date_s__iso8601(argc2, argv2, klass);
8067
+ VALUE hash = date_s__iso8601(klass, str);
8194
8068
  return dt_new_by_frags(klass, hash, sg);
8195
8069
  }
8196
8070
  }
8197
8071
 
8198
8072
  /*
8199
8073
  * call-seq:
8200
- * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8074
+ * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8201
8075
  *
8202
8076
  * Creates a new DateTime object by parsing from a string according to
8203
8077
  * some typical RFC 3339 formats.
8204
8078
  *
8205
8079
  * DateTime.rfc3339('2001-02-03T04:05:06+07:00')
8206
8080
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8207
- *
8208
- * Raise an ArgumentError when the string length is longer than _limit_.
8209
- * You can stop this check by passing `limit: nil`, but note that
8210
- * it may take a long time to parse.
8211
8081
  */
8212
8082
  static VALUE
8213
8083
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8214
8084
  {
8215
- VALUE str, sg, opt;
8085
+ VALUE str, sg;
8216
8086
 
8217
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8218
- if (!NIL_P(opt)) argc--;
8087
+ rb_scan_args(argc, argv, "02", &str, &sg);
8219
8088
 
8220
8089
  switch (argc) {
8221
8090
  case 0:
@@ -8225,37 +8094,27 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8225
8094
  }
8226
8095
 
8227
8096
  {
8228
- int argc2 = 1;
8229
- VALUE argv2[2];
8230
- argv2[0] = str;
8231
- argv2[1] = opt;
8232
- if (!NIL_P(opt)) argc2++;
8233
- VALUE hash = date_s__rfc3339(argc2, argv2, klass);
8097
+ VALUE hash = date_s__rfc3339(klass, str);
8234
8098
  return dt_new_by_frags(klass, hash, sg);
8235
8099
  }
8236
8100
  }
8237
8101
 
8238
8102
  /*
8239
8103
  * call-seq:
8240
- * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8104
+ * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8241
8105
  *
8242
8106
  * Creates a new DateTime object by parsing from a string according to
8243
8107
  * some typical XML Schema formats.
8244
8108
  *
8245
8109
  * DateTime.xmlschema('2001-02-03T04:05:06+07:00')
8246
8110
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8247
- *
8248
- * Raise an ArgumentError when the string length is longer than _limit_.
8249
- * You can stop this check by passing `limit: nil`, but note that
8250
- * it may take a long time to parse.
8251
8111
  */
8252
8112
  static VALUE
8253
8113
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8254
8114
  {
8255
- VALUE str, sg, opt;
8115
+ VALUE str, sg;
8256
8116
 
8257
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8258
- if (!NIL_P(opt)) argc--;
8117
+ rb_scan_args(argc, argv, "02", &str, &sg);
8259
8118
 
8260
8119
  switch (argc) {
8261
8120
  case 0:
@@ -8265,38 +8124,28 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8265
8124
  }
8266
8125
 
8267
8126
  {
8268
- int argc2 = 1;
8269
- VALUE argv2[2];
8270
- argv2[0] = str;
8271
- argv2[1] = opt;
8272
- if (!NIL_P(opt)) argc2++;
8273
- VALUE hash = date_s__xmlschema(argc2, argv2, klass);
8127
+ VALUE hash = date_s__xmlschema(klass, str);
8274
8128
  return dt_new_by_frags(klass, hash, sg);
8275
8129
  }
8276
8130
  }
8277
8131
 
8278
8132
  /*
8279
8133
  * call-seq:
8280
- * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8281
- * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
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
8282
8136
  *
8283
8137
  * Creates a new DateTime object by parsing from a string according to
8284
8138
  * some typical RFC 2822 formats.
8285
8139
  *
8286
8140
  * DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700')
8287
8141
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8288
- *
8289
- * Raise an ArgumentError when the string length is longer than _limit_.
8290
- * You can stop this check by passing `limit: nil`, but note that
8291
- * it may take a long time to parse.
8292
8142
  */
8293
8143
  static VALUE
8294
8144
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8295
8145
  {
8296
- VALUE str, sg, opt;
8146
+ VALUE str, sg;
8297
8147
 
8298
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8299
- if (!NIL_P(opt)) argc--;
8148
+ rb_scan_args(argc, argv, "02", &str, &sg);
8300
8149
 
8301
8150
  switch (argc) {
8302
8151
  case 0:
@@ -8306,12 +8155,7 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8306
8155
  }
8307
8156
 
8308
8157
  {
8309
- int argc2 = 1;
8310
- VALUE argv2[2];
8311
- argv2[0] = str;
8312
- argv2[1] = opt;
8313
- if (!NIL_P(opt)) argc2++;
8314
- VALUE hash = date_s__rfc2822(argc2, argv2, klass);
8158
+ VALUE hash = date_s__rfc2822(klass, str);
8315
8159
  return dt_new_by_frags(klass, hash, sg);
8316
8160
  }
8317
8161
  }
@@ -8325,18 +8169,13 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8325
8169
  *
8326
8170
  * DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
8327
8171
  * #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
8328
- *
8329
- * Raise an ArgumentError when the string length is longer than _limit_.
8330
- * You can stop this check by passing `limit: nil`, but note that
8331
- * it may take a long time to parse.
8332
8172
  */
8333
8173
  static VALUE
8334
8174
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8335
8175
  {
8336
- VALUE str, sg, opt;
8176
+ VALUE str, sg;
8337
8177
 
8338
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8339
- if (!NIL_P(opt)) argc--;
8178
+ rb_scan_args(argc, argv, "02", &str, &sg);
8340
8179
 
8341
8180
  switch (argc) {
8342
8181
  case 0:
@@ -8346,19 +8185,14 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8346
8185
  }
8347
8186
 
8348
8187
  {
8349
- int argc2 = 1;
8350
- VALUE argv2[2];
8351
- argv2[0] = str;
8352
- argv2[1] = opt;
8353
- if (!NIL_P(opt)) argc2++;
8354
- VALUE hash = date_s__httpdate(argc2, argv2, klass);
8188
+ VALUE hash = date_s__httpdate(klass, str);
8355
8189
  return dt_new_by_frags(klass, hash, sg);
8356
8190
  }
8357
8191
  }
8358
8192
 
8359
8193
  /*
8360
8194
  * call-seq:
8361
- * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8195
+ * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8362
8196
  *
8363
8197
  * Creates a new DateTime object by parsing from a string according to
8364
8198
  * some typical JIS X 0301 formats.
@@ -8370,18 +8204,13 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8370
8204
  *
8371
8205
  * DateTime.jisx0301('13.02.03T04:05:06+07:00')
8372
8206
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8373
- *
8374
- * Raise an ArgumentError when the string length is longer than _limit_.
8375
- * You can stop this check by passing `limit: nil`, but note that
8376
- * it may take a long time to parse.
8377
8207
  */
8378
8208
  static VALUE
8379
8209
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8380
8210
  {
8381
- VALUE str, sg, opt;
8211
+ VALUE str, sg;
8382
8212
 
8383
- rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8384
- if (!NIL_P(opt)) argc--;
8213
+ rb_scan_args(argc, argv, "02", &str, &sg);
8385
8214
 
8386
8215
  switch (argc) {
8387
8216
  case 0:
@@ -8391,12 +8220,7 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8391
8220
  }
8392
8221
 
8393
8222
  {
8394
- int argc2 = 1;
8395
- VALUE argv2[2];
8396
- argv2[0] = str;
8397
- argv2[1] = opt;
8398
- if (!NIL_P(opt)) argc2++;
8399
- VALUE hash = date_s__jisx0301(argc2, argv2, klass);
8223
+ VALUE hash = date_s__jisx0301(klass, str);
8400
8224
  return dt_new_by_frags(klass, hash, sg);
8401
8225
  }
8402
8226
  }
@@ -8774,17 +8598,24 @@ time_to_datetime(VALUE self)
8774
8598
  * call-seq:
8775
8599
  * d.to_time -> time
8776
8600
  *
8777
- * 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.
8778
8603
  */
8779
8604
  static VALUE
8780
8605
  date_to_time(VALUE self)
8781
8606
  {
8782
- get_d1(self);
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
+ }
8783
8614
 
8784
8615
  return f_local3(rb_cTime,
8785
- m_real_year(dat),
8786
- INT2FIX(m_mon(dat)),
8787
- INT2FIX(m_mday(dat)));
8616
+ m_real_year(adat),
8617
+ INT2FIX(m_mon(adat)),
8618
+ INT2FIX(m_mday(adat)));
8788
8619
  }
8789
8620
 
8790
8621
  /*
@@ -9441,6 +9272,7 @@ Init_date_core(void)
9441
9272
  *
9442
9273
  */
9443
9274
  cDate = rb_define_class("Date", rb_cObject);
9275
+ eDateError = rb_define_class_under(cDate, "Error", rb_eArgError);
9444
9276
 
9445
9277
  rb_include_module(cDate, rb_mComparable);
9446
9278
 
@@ -9547,19 +9379,19 @@ Init_date_core(void)
9547
9379
  rb_define_singleton_method(cDate, "strptime", date_s_strptime, -1);
9548
9380
  rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
9549
9381
  rb_define_singleton_method(cDate, "parse", date_s_parse, -1);
9550
- rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, -1);
9382
+ rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, 1);
9551
9383
  rb_define_singleton_method(cDate, "iso8601", date_s_iso8601, -1);
9552
- rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, -1);
9384
+ rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, 1);
9553
9385
  rb_define_singleton_method(cDate, "rfc3339", date_s_rfc3339, -1);
9554
- rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, -1);
9386
+ rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, 1);
9555
9387
  rb_define_singleton_method(cDate, "xmlschema", date_s_xmlschema, -1);
9556
- rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, -1);
9557
- rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, -1);
9388
+ rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, 1);
9389
+ rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, 1);
9558
9390
  rb_define_singleton_method(cDate, "rfc2822", date_s_rfc2822, -1);
9559
9391
  rb_define_singleton_method(cDate, "rfc822", date_s_rfc2822, -1);
9560
- rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, -1);
9392
+ rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, 1);
9561
9393
  rb_define_singleton_method(cDate, "httpdate", date_s_httpdate, -1);
9562
- rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, -1);
9394
+ rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
9563
9395
  rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
9564
9396
 
9565
9397
  rb_define_method(cDate, "initialize", date_initialize, -1);