date 2.0.0 → 2.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/date/date_core.c +299 -88
  3. data/lib/date.rb +1 -0
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bc19b4489b002663b78093d39f13ac29000d0457dd9e4c7d0a1c1c77fe623bf
4
- data.tar.gz: ae8933e1cd0ecb6b2d9219e24ca857ec648eadf2e1b2893367cf1fb0d8ca7763
3
+ metadata.gz: 8481a68fbde6bd3bfd0451519276e4dc0b97a5ef9821795e02ccf44f6e6a2657
4
+ data.tar.gz: c3406be1405e4d5d428ca8235108b9f510f79cf9e576f00df5e41fa01d841cce
5
5
  SHA512:
6
- metadata.gz: 51f50fb953dbf4aa82c35e3e6145e0ce10c8696ec17f9577339297ee0cfc6b4fb8f0bfa05d353e2571f5963ef8f1a53dfe351b69b9acf756212b1283629f2b9d
7
- data.tar.gz: ddc9ed30e31c2dc6bb29af2c25457338d46c73ca81d73cc6fb90312d5b837b8bd1784fc3e8236f36f7f4e74a2590e36637b3b4acfffa4119119f562ef3da7c30
6
+ metadata.gz: dd3b5df79114ab296e7ab12be8c1e455f608269a91c73531b5f42ce645487f2692016d1526cc914f9bd6661cbeb1f8bd5425cf3a16f3abcbc4cb864a260afdae
7
+ data.tar.gz: ce1323207b6e3cbc3b09aff4a660b9f0de2a37367a186f6bde2af92ad9e048e63843abaadcccd97c4e0a3fa1609572aa804502690c5444a22a85af2903a4db37
data/ext/date/date_core.c CHANGED
@@ -4292,12 +4292,40 @@ date_s_strptime(int argc, VALUE *argv, VALUE klass)
4292
4292
 
4293
4293
  VALUE date__parse(VALUE str, VALUE comp);
4294
4294
 
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
+
4295
4321
  static VALUE
4296
4322
  date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4297
4323
  {
4298
- VALUE vstr, vcomp, hash;
4324
+ VALUE vstr, vcomp, hash, opt;
4299
4325
 
4300
- rb_scan_args(argc, argv, "11", &vstr, &vcomp);
4326
+ rb_scan_args(argc, argv, "11:", &vstr, &vcomp, &opt);
4327
+ if (!NIL_P(opt)) argc--;
4328
+ check_limit(vstr, opt);
4301
4329
  StringValue(vstr);
4302
4330
  if (!rb_enc_str_asciicompat_p(vstr))
4303
4331
  rb_raise(rb_eArgError,
@@ -4322,7 +4350,7 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4322
4350
 
4323
4351
  /*
4324
4352
  * call-seq:
4325
- * Date._parse(string[, comp=true]) -> hash
4353
+ * Date._parse(string[, comp=true], limit: 128) -> hash
4326
4354
  *
4327
4355
  * Parses the given representation of date and time, and returns a
4328
4356
  * hash of parsed elements. This method does not function as a
@@ -4333,6 +4361,10 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4333
4361
  * it full.
4334
4362
  *
4335
4363
  * 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.
4336
4368
  */
4337
4369
  static VALUE
4338
4370
  date_s__parse(int argc, VALUE *argv, VALUE klass)
@@ -4342,7 +4374,7 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4342
4374
 
4343
4375
  /*
4344
4376
  * call-seq:
4345
- * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]]) -> date
4377
+ * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
4346
4378
  *
4347
4379
  * Parses the given representation of date and time, and creates a
4348
4380
  * date object. This method does not function as a validator.
@@ -4354,13 +4386,18 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4354
4386
  * Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
4355
4387
  * Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
4356
4388
  * 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.
4357
4393
  */
4358
4394
  static VALUE
4359
4395
  date_s_parse(int argc, VALUE *argv, VALUE klass)
4360
4396
  {
4361
- VALUE str, comp, sg;
4397
+ VALUE str, comp, sg, opt;
4362
4398
 
4363
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
4399
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
4400
+ if (!NIL_P(opt)) argc--;
4364
4401
 
4365
4402
  switch (argc) {
4366
4403
  case 0:
@@ -4372,11 +4409,12 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
4372
4409
  }
4373
4410
 
4374
4411
  {
4375
- VALUE argv2[2], hash;
4376
-
4377
- argv2[0] = str;
4378
- argv2[1] = comp;
4379
- hash = date_s__parse(2, argv2, klass);
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);
4380
4418
  return d_new_by_frags(klass, hash, sg);
4381
4419
  }
4382
4420
  }
@@ -4390,19 +4428,28 @@ VALUE date__jisx0301(VALUE);
4390
4428
 
4391
4429
  /*
4392
4430
  * call-seq:
4393
- * Date._iso8601(string) -> hash
4431
+ * Date._iso8601(string, limit: 128) -> hash
4394
4432
  *
4395
4433
  * 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.
4396
4438
  */
4397
4439
  static VALUE
4398
- date_s__iso8601(VALUE klass, VALUE str)
4440
+ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
4399
4441
  {
4442
+ VALUE str, opt;
4443
+
4444
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4445
+ check_limit(str, opt);
4446
+
4400
4447
  return date__iso8601(str);
4401
4448
  }
4402
4449
 
4403
4450
  /*
4404
4451
  * call-seq:
4405
- * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY]) -> date
4452
+ * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4406
4453
  *
4407
4454
  * Creates a new Date object by parsing from a string according to
4408
4455
  * some typical ISO 8601 formats.
@@ -4410,13 +4457,18 @@ date_s__iso8601(VALUE klass, VALUE str)
4410
4457
  * Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
4411
4458
  * Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
4412
4459
  * 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.
4413
4464
  */
4414
4465
  static VALUE
4415
4466
  date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4416
4467
  {
4417
- VALUE str, sg;
4468
+ VALUE str, sg, opt;
4418
4469
 
4419
- rb_scan_args(argc, argv, "02", &str, &sg);
4470
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4471
+ if (!NIL_P(opt)) argc--;
4420
4472
 
4421
4473
  switch (argc) {
4422
4474
  case 0:
@@ -4426,38 +4478,56 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4426
4478
  }
4427
4479
 
4428
4480
  {
4429
- VALUE hash = date_s__iso8601(klass, str);
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);
4430
4486
  return d_new_by_frags(klass, hash, sg);
4431
4487
  }
4432
4488
  }
4433
4489
 
4434
4490
  /*
4435
4491
  * call-seq:
4436
- * Date._rfc3339(string) -> hash
4492
+ * Date._rfc3339(string, limit: 128) -> hash
4437
4493
  *
4438
4494
  * 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.
4439
4499
  */
4440
4500
  static VALUE
4441
- date_s__rfc3339(VALUE klass, VALUE str)
4501
+ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
4442
4502
  {
4503
+ VALUE str, opt;
4504
+
4505
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4506
+ check_limit(str, opt);
4507
+
4443
4508
  return date__rfc3339(str);
4444
4509
  }
4445
4510
 
4446
4511
  /*
4447
4512
  * call-seq:
4448
- * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> date
4513
+ * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
4449
4514
  *
4450
4515
  * Creates a new Date object by parsing from a string according to
4451
4516
  * some typical RFC 3339 formats.
4452
4517
  *
4453
4518
  * 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.
4454
4523
  */
4455
4524
  static VALUE
4456
4525
  date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4457
4526
  {
4458
- VALUE str, sg;
4527
+ VALUE str, sg, opt;
4459
4528
 
4460
- rb_scan_args(argc, argv, "02", &str, &sg);
4529
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4530
+ if (!NIL_P(opt)) argc--;
4461
4531
 
4462
4532
  switch (argc) {
4463
4533
  case 0:
@@ -4467,38 +4537,56 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4467
4537
  }
4468
4538
 
4469
4539
  {
4470
- VALUE hash = date_s__rfc3339(klass, str);
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);
4471
4545
  return d_new_by_frags(klass, hash, sg);
4472
4546
  }
4473
4547
  }
4474
4548
 
4475
4549
  /*
4476
4550
  * call-seq:
4477
- * Date._xmlschema(string) -> hash
4551
+ * Date._xmlschema(string, limit: 128) -> hash
4478
4552
  *
4479
4553
  * 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.
4480
4558
  */
4481
4559
  static VALUE
4482
- date_s__xmlschema(VALUE klass, VALUE str)
4560
+ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
4483
4561
  {
4562
+ VALUE str, opt;
4563
+
4564
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4565
+ check_limit(str, opt);
4566
+
4484
4567
  return date__xmlschema(str);
4485
4568
  }
4486
4569
 
4487
4570
  /*
4488
4571
  * call-seq:
4489
- * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY]) -> date
4572
+ * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4490
4573
  *
4491
4574
  * Creates a new Date object by parsing from a string according to
4492
4575
  * some typical XML Schema formats.
4493
4576
  *
4494
4577
  * 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.
4495
4582
  */
4496
4583
  static VALUE
4497
4584
  date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4498
4585
  {
4499
- VALUE str, sg;
4586
+ VALUE str, sg, opt;
4500
4587
 
4501
- rb_scan_args(argc, argv, "02", &str, &sg);
4588
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4589
+ if (!NIL_P(opt)) argc--;
4502
4590
 
4503
4591
  switch (argc) {
4504
4592
  case 0:
@@ -4508,41 +4596,58 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4508
4596
  }
4509
4597
 
4510
4598
  {
4511
- VALUE hash = date_s__xmlschema(klass, str);
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);
4512
4604
  return d_new_by_frags(klass, hash, sg);
4513
4605
  }
4514
4606
  }
4515
4607
 
4516
4608
  /*
4517
4609
  * call-seq:
4518
- * Date._rfc2822(string) -> hash
4519
- * Date._rfc822(string) -> hash
4610
+ * Date._rfc2822(string, limit: 128) -> hash
4611
+ * Date._rfc822(string, limit: 128) -> hash
4520
4612
  *
4521
4613
  * 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.
4522
4618
  */
4523
4619
  static VALUE
4524
- date_s__rfc2822(VALUE klass, VALUE str)
4620
+ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
4525
4621
  {
4622
+ VALUE str, opt;
4623
+
4624
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4625
+ check_limit(str, opt);
4626
+
4526
4627
  return date__rfc2822(str);
4527
4628
  }
4528
4629
 
4529
4630
  /*
4530
4631
  * call-seq:
4531
- * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
4532
- * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
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
4533
4634
  *
4534
4635
  * Creates a new Date object by parsing from a string according to
4535
4636
  * some typical RFC 2822 formats.
4536
4637
  *
4537
4638
  * Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
4538
4639
  * #=> #<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.
4539
4644
  */
4540
4645
  static VALUE
4541
4646
  date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4542
4647
  {
4543
- VALUE str, sg;
4648
+ VALUE str, sg, opt;
4544
4649
 
4545
- rb_scan_args(argc, argv, "02", &str, &sg);
4650
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4546
4651
 
4547
4652
  switch (argc) {
4548
4653
  case 0:
@@ -4552,39 +4657,56 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4552
4657
  }
4553
4658
 
4554
4659
  {
4555
- VALUE hash = date_s__rfc2822(klass, str);
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);
4556
4665
  return d_new_by_frags(klass, hash, sg);
4557
4666
  }
4558
4667
  }
4559
4668
 
4560
4669
  /*
4561
4670
  * call-seq:
4562
- * Date._httpdate(string) -> hash
4671
+ * Date._httpdate(string, limit: 128) -> hash
4563
4672
  *
4564
4673
  * 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.
4565
4678
  */
4566
4679
  static VALUE
4567
- date_s__httpdate(VALUE klass, VALUE str)
4680
+ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
4568
4681
  {
4682
+ VALUE str, opt;
4683
+
4684
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4685
+ check_limit(str, opt);
4686
+
4569
4687
  return date__httpdate(str);
4570
4688
  }
4571
4689
 
4572
4690
  /*
4573
4691
  * call-seq:
4574
- * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]) -> date
4692
+ * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
4575
4693
  *
4576
4694
  * Creates a new Date object by parsing from a string according to
4577
4695
  * some RFC 2616 format.
4578
4696
  *
4579
4697
  * Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
4580
4698
  * #=> #<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.
4581
4703
  */
4582
4704
  static VALUE
4583
4705
  date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4584
4706
  {
4585
- VALUE str, sg;
4707
+ VALUE str, sg, opt;
4586
4708
 
4587
- rb_scan_args(argc, argv, "02", &str, &sg);
4709
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4588
4710
 
4589
4711
  switch (argc) {
4590
4712
  case 0:
@@ -4594,38 +4716,56 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4594
4716
  }
4595
4717
 
4596
4718
  {
4597
- VALUE hash = date_s__httpdate(klass, str);
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);
4598
4724
  return d_new_by_frags(klass, hash, sg);
4599
4725
  }
4600
4726
  }
4601
4727
 
4602
4728
  /*
4603
4729
  * call-seq:
4604
- * Date._jisx0301(string) -> hash
4730
+ * Date._jisx0301(string, limit: 128) -> hash
4605
4731
  *
4606
4732
  * 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.
4607
4737
  */
4608
4738
  static VALUE
4609
- date_s__jisx0301(VALUE klass, VALUE str)
4739
+ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4610
4740
  {
4741
+ VALUE str, opt;
4742
+
4743
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4744
+ check_limit(str, opt);
4745
+
4611
4746
  return date__jisx0301(str);
4612
4747
  }
4613
4748
 
4614
4749
  /*
4615
4750
  * call-seq:
4616
- * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY]) -> date
4751
+ * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4617
4752
  *
4618
4753
  * Creates a new Date object by parsing from a string according to
4619
4754
  * some typical JIS X 0301 formats.
4620
4755
  *
4621
4756
  * Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
4757
+ *
4758
+ * Raise an ArgumentError when the string length is longer than _limit_.
4759
+ * You can stop this check by passing `limit: nil`, but note that
4760
+ * it may take a long time to parse.
4622
4761
  */
4623
4762
  static VALUE
4624
4763
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4625
4764
  {
4626
- VALUE str, sg;
4765
+ VALUE str, sg, opt;
4627
4766
 
4628
- rb_scan_args(argc, argv, "02", &str, &sg);
4767
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4768
+ if (!NIL_P(opt)) argc--;
4629
4769
 
4630
4770
  switch (argc) {
4631
4771
  case 0:
@@ -4635,7 +4775,11 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4635
4775
  }
4636
4776
 
4637
4777
  {
4638
- VALUE hash = date_s__jisx0301(klass, str);
4778
+ int argc2 = 1;
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);
4639
4783
  return d_new_by_frags(klass, hash, sg);
4640
4784
  }
4641
4785
  }
@@ -7951,7 +8095,7 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
7951
8095
 
7952
8096
  /*
7953
8097
  * call-seq:
7954
- * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]) -> datetime
8098
+ * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]], limit: 128) -> datetime
7955
8099
  *
7956
8100
  * Parses the given representation of date and time, and creates a
7957
8101
  * DateTime object. This method does not function as a validator.
@@ -7965,13 +8109,18 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
7965
8109
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
7966
8110
  * DateTime.parse('3rd Feb 2001 04:05:06 PM')
7967
8111
  * #=> #<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.
7968
8116
  */
7969
8117
  static VALUE
7970
8118
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
7971
8119
  {
7972
- VALUE str, comp, sg;
8120
+ VALUE str, comp, sg, opt;
7973
8121
 
7974
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
8122
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
8123
+ if (!NIL_P(opt)) argc--;
7975
8124
 
7976
8125
  switch (argc) {
7977
8126
  case 0:
@@ -7983,18 +8132,20 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
7983
8132
  }
7984
8133
 
7985
8134
  {
7986
- VALUE argv2[2], hash;
7987
-
7988
- argv2[0] = str;
7989
- argv2[1] = comp;
7990
- hash = date_s__parse(2, argv2, klass);
8135
+ int argc2 = 2;
8136
+ VALUE argv2[3];
8137
+ argv2[0] = str;
8138
+ argv2[1] = comp;
8139
+ argv2[2] = opt;
8140
+ if (!NIL_P(opt)) argc2++;
8141
+ VALUE hash = date_s__parse(argc2, argv2, klass);
7991
8142
  return dt_new_by_frags(klass, hash, sg);
7992
8143
  }
7993
8144
  }
7994
8145
 
7995
8146
  /*
7996
8147
  * call-seq:
7997
- * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8148
+ * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
7998
8149
  *
7999
8150
  * Creates a new DateTime object by parsing from a string according to
8000
8151
  * some typical ISO 8601 formats.
@@ -8005,13 +8156,18 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8005
8156
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8006
8157
  * DateTime.iso8601('2001-W05-6T04:05:06+07:00')
8007
8158
  * #=> #<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.
8008
8163
  */
8009
8164
  static VALUE
8010
8165
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8011
8166
  {
8012
- VALUE str, sg;
8167
+ VALUE str, sg, opt;
8013
8168
 
8014
- rb_scan_args(argc, argv, "02", &str, &sg);
8169
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8170
+ if (!NIL_P(opt)) argc--;
8015
8171
 
8016
8172
  switch (argc) {
8017
8173
  case 0:
@@ -8021,27 +8177,37 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8021
8177
  }
8022
8178
 
8023
8179
  {
8024
- VALUE hash = date_s__iso8601(klass, str);
8180
+ int argc2 = 1;
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);
8025
8186
  return dt_new_by_frags(klass, hash, sg);
8026
8187
  }
8027
8188
  }
8028
8189
 
8029
8190
  /*
8030
8191
  * call-seq:
8031
- * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8192
+ * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8032
8193
  *
8033
8194
  * Creates a new DateTime object by parsing from a string according to
8034
8195
  * some typical RFC 3339 formats.
8035
8196
  *
8036
8197
  * DateTime.rfc3339('2001-02-03T04:05:06+07:00')
8037
8198
  * #=> #<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.
8038
8203
  */
8039
8204
  static VALUE
8040
8205
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8041
8206
  {
8042
- VALUE str, sg;
8207
+ VALUE str, sg, opt;
8043
8208
 
8044
- rb_scan_args(argc, argv, "02", &str, &sg);
8209
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8210
+ if (!NIL_P(opt)) argc--;
8045
8211
 
8046
8212
  switch (argc) {
8047
8213
  case 0:
@@ -8051,27 +8217,37 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8051
8217
  }
8052
8218
 
8053
8219
  {
8054
- VALUE hash = date_s__rfc3339(klass, str);
8220
+ int argc2 = 1;
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);
8055
8226
  return dt_new_by_frags(klass, hash, sg);
8056
8227
  }
8057
8228
  }
8058
8229
 
8059
8230
  /*
8060
8231
  * call-seq:
8061
- * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8232
+ * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8062
8233
  *
8063
8234
  * Creates a new DateTime object by parsing from a string according to
8064
8235
  * some typical XML Schema formats.
8065
8236
  *
8066
8237
  * DateTime.xmlschema('2001-02-03T04:05:06+07:00')
8067
8238
  * #=> #<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.
8068
8243
  */
8069
8244
  static VALUE
8070
8245
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8071
8246
  {
8072
- VALUE str, sg;
8247
+ VALUE str, sg, opt;
8073
8248
 
8074
- rb_scan_args(argc, argv, "02", &str, &sg);
8249
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8250
+ if (!NIL_P(opt)) argc--;
8075
8251
 
8076
8252
  switch (argc) {
8077
8253
  case 0:
@@ -8081,28 +8257,38 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8081
8257
  }
8082
8258
 
8083
8259
  {
8084
- VALUE hash = date_s__xmlschema(klass, str);
8260
+ int argc2 = 1;
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);
8085
8266
  return dt_new_by_frags(klass, hash, sg);
8086
8267
  }
8087
8268
  }
8088
8269
 
8089
8270
  /*
8090
8271
  * call-seq:
8091
- * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8092
- * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8272
+ * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8273
+ * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8093
8274
  *
8094
8275
  * Creates a new DateTime object by parsing from a string according to
8095
8276
  * some typical RFC 2822 formats.
8096
8277
  *
8097
8278
  * DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700')
8098
8279
  * #=> #<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.
8099
8284
  */
8100
8285
  static VALUE
8101
8286
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8102
8287
  {
8103
- VALUE str, sg;
8288
+ VALUE str, sg, opt;
8104
8289
 
8105
- rb_scan_args(argc, argv, "02", &str, &sg);
8290
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8291
+ if (!NIL_P(opt)) argc--;
8106
8292
 
8107
8293
  switch (argc) {
8108
8294
  case 0:
@@ -8112,7 +8298,12 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8112
8298
  }
8113
8299
 
8114
8300
  {
8115
- VALUE hash = date_s__rfc2822(klass, str);
8301
+ int argc2 = 1;
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);
8116
8307
  return dt_new_by_frags(klass, hash, sg);
8117
8308
  }
8118
8309
  }
@@ -8126,13 +8317,18 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8126
8317
  *
8127
8318
  * DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
8128
8319
  * #=> #<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.
8129
8324
  */
8130
8325
  static VALUE
8131
8326
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8132
8327
  {
8133
- VALUE str, sg;
8328
+ VALUE str, sg, opt;
8134
8329
 
8135
- rb_scan_args(argc, argv, "02", &str, &sg);
8330
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8331
+ if (!NIL_P(opt)) argc--;
8136
8332
 
8137
8333
  switch (argc) {
8138
8334
  case 0:
@@ -8142,27 +8338,37 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8142
8338
  }
8143
8339
 
8144
8340
  {
8145
- VALUE hash = date_s__httpdate(klass, str);
8341
+ int argc2 = 1;
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);
8146
8347
  return dt_new_by_frags(klass, hash, sg);
8147
8348
  }
8148
8349
  }
8149
8350
 
8150
8351
  /*
8151
8352
  * call-seq:
8152
- * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8353
+ * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8153
8354
  *
8154
8355
  * Creates a new DateTime object by parsing from a string according to
8155
8356
  * some typical JIS X 0301 formats.
8156
8357
  *
8157
8358
  * DateTime.jisx0301('H13.02.03T04:05:06+07:00')
8158
8359
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8360
+ *
8361
+ * Raise an ArgumentError when the string length is longer than _limit_.
8362
+ * You can stop this check by passing `limit: nil`, but note that
8363
+ * it may take a long time to parse.
8159
8364
  */
8160
8365
  static VALUE
8161
8366
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8162
8367
  {
8163
- VALUE str, sg;
8368
+ VALUE str, sg, opt;
8164
8369
 
8165
- rb_scan_args(argc, argv, "02", &str, &sg);
8370
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8371
+ if (!NIL_P(opt)) argc--;
8166
8372
 
8167
8373
  switch (argc) {
8168
8374
  case 0:
@@ -8172,7 +8378,12 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8172
8378
  }
8173
8379
 
8174
8380
  {
8175
- VALUE hash = date_s__jisx0301(klass, str);
8381
+ int argc2 = 1;
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);
8176
8387
  return dt_new_by_frags(klass, hash, sg);
8177
8388
  }
8178
8389
  }
@@ -9323,19 +9534,19 @@ Init_date_core(void)
9323
9534
  rb_define_singleton_method(cDate, "strptime", date_s_strptime, -1);
9324
9535
  rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
9325
9536
  rb_define_singleton_method(cDate, "parse", date_s_parse, -1);
9326
- rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, 1);
9537
+ rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, -1);
9327
9538
  rb_define_singleton_method(cDate, "iso8601", date_s_iso8601, -1);
9328
- rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, 1);
9539
+ rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, -1);
9329
9540
  rb_define_singleton_method(cDate, "rfc3339", date_s_rfc3339, -1);
9330
- rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, 1);
9541
+ rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, -1);
9331
9542
  rb_define_singleton_method(cDate, "xmlschema", date_s_xmlschema, -1);
9332
- rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, 1);
9333
- rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, 1);
9543
+ rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, -1);
9544
+ rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, -1);
9334
9545
  rb_define_singleton_method(cDate, "rfc2822", date_s_rfc2822, -1);
9335
9546
  rb_define_singleton_method(cDate, "rfc822", date_s_rfc2822, -1);
9336
- rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, 1);
9547
+ rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, -1);
9337
9548
  rb_define_singleton_method(cDate, "httpdate", date_s_httpdate, -1);
9338
- rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
9549
+ rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, -1);
9339
9550
  rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
9340
9551
 
9341
9552
  rb_define_method(cDate, "initialize", date_initialize, -1);
data/lib/date.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'date_core'
5
5
 
6
6
  class Date
7
+ VERSION = '2.0.2' # :nodoc:
7
8
 
8
9
  class Infinity < Numeric # :nodoc:
9
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadayoshi Funaba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-07 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.0.2
64
+ rubygems_version: 3.3.0.dev
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: A subclass of Object includes Comparable module for handling dates.