date 3.2.0 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
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: 3ccbc0063defa6a784459e629b4dc402cdb7c35d7ca51bfbe371ac46210b6b59
4
- data.tar.gz: c5c53dd9af2ea3ddb18ff390c9aa5a89370f6fecd068fba64ff425e5ea192d19
3
+ metadata.gz: 91f6620791550924cc059c5c534ada4a811b273d900399be6c4406801a4dbcc6
4
+ data.tar.gz: 68b1c8be2eb0aefffd9b5fe450a03834655cbe3d8892682778f24ad0102920ca
5
5
  SHA512:
6
- metadata.gz: be4016ed18b870b75821d2af83d30d79d1530b4f79125a042ccad4b67f9e578ec95313bcdfd2113a995c0281be917d14fe0a9b17200f5a8a15b9672f0b6ca146
7
- data.tar.gz: 44898ccbbc5709310ee930c574d07fd4ea897c41934fbf631a401eabe7876145a8e4914d7e8b27d9525414ea112440f1a26e04409fbb3fcbddd08d6b8538ec44
6
+ metadata.gz: 508e707ba98f9a77b0dad3689627d3f5c2dc1a87b84a4b017e09bb4374ddaecebd7c834c75440dc6d8d27f767b971915626073e7bd796d4695e29c54e8e9d73a
7
+ data.tar.gz: 1841c19c7365a7f10eb80ab4aac688fcaf68623b7cc39b083b3ff19a2e43b782a2f7f04b77ad3cfa3d4094611f87394d2bb5fe2ca5359a623092f6d4bae60959
data/ext/date/date_core.c CHANGED
@@ -4328,12 +4328,40 @@ date_s_strptime(int argc, VALUE *argv, VALUE klass)
4328
4328
 
4329
4329
  VALUE date__parse(VALUE str, VALUE comp);
4330
4330
 
4331
+ static size_t
4332
+ get_limit(VALUE opt)
4333
+ {
4334
+ if (!NIL_P(opt)) {
4335
+ VALUE limit = rb_hash_aref(opt, ID2SYM(rb_intern("limit")));
4336
+ if (NIL_P(limit)) return SIZE_MAX;
4337
+ return NUM2SIZET(limit);
4338
+ }
4339
+ return 128;
4340
+ }
4341
+
4342
+ static void
4343
+ check_limit(VALUE str, VALUE opt)
4344
+ {
4345
+ if (NIL_P(str)) return;
4346
+ if (SYMBOL_P(str)) str = rb_sym2str(str);
4347
+
4348
+ StringValue(str);
4349
+ size_t slen = RSTRING_LEN(str);
4350
+ size_t limit = get_limit(opt);
4351
+ if (slen > limit) {
4352
+ rb_raise(rb_eArgError,
4353
+ "string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit);
4354
+ }
4355
+ }
4356
+
4331
4357
  static VALUE
4332
4358
  date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4333
4359
  {
4334
- VALUE vstr, vcomp, hash;
4360
+ VALUE vstr, vcomp, hash, opt;
4335
4361
 
4336
- rb_scan_args(argc, argv, "11", &vstr, &vcomp);
4362
+ rb_scan_args(argc, argv, "11:", &vstr, &vcomp, &opt);
4363
+ if (!NIL_P(opt)) argc--;
4364
+ check_limit(vstr, opt);
4337
4365
  StringValue(vstr);
4338
4366
  if (!rb_enc_str_asciicompat_p(vstr))
4339
4367
  rb_raise(rb_eArgError,
@@ -4348,7 +4376,7 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4348
4376
 
4349
4377
  /*
4350
4378
  * call-seq:
4351
- * Date._parse(string[, comp=true]) -> hash
4379
+ * Date._parse(string[, comp=true], limit: 128) -> hash
4352
4380
  *
4353
4381
  * Parses the given representation of date and time, and returns a
4354
4382
  * hash of parsed elements.
@@ -4363,6 +4391,10 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4363
4391
  * it full.
4364
4392
  *
4365
4393
  * Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
4394
+ *
4395
+ * Raise an ArgumentError when the string length is longer than _limit_.
4396
+ * You can stop this check by passing `limit: nil`, but note that
4397
+ * it may take a long time to parse.
4366
4398
  */
4367
4399
  static VALUE
4368
4400
  date_s__parse(int argc, VALUE *argv, VALUE klass)
@@ -4372,7 +4404,7 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4372
4404
 
4373
4405
  /*
4374
4406
  * call-seq:
4375
- * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]]) -> date
4407
+ * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
4376
4408
  *
4377
4409
  * Parses the given representation of date and time, and creates a
4378
4410
  * date object.
@@ -4389,13 +4421,18 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4389
4421
  * Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
4390
4422
  * Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
4391
4423
  * Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
4424
+ *
4425
+ * Raise an ArgumentError when the string length is longer than _limit_.
4426
+ * You can stop this check by passing `limit: nil`, but note that
4427
+ * it may take a long time to parse.
4392
4428
  */
4393
4429
  static VALUE
4394
4430
  date_s_parse(int argc, VALUE *argv, VALUE klass)
4395
4431
  {
4396
- VALUE str, comp, sg;
4432
+ VALUE str, comp, sg, opt;
4397
4433
 
4398
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
4434
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
4435
+ if (!NIL_P(opt)) argc--;
4399
4436
 
4400
4437
  switch (argc) {
4401
4438
  case 0:
@@ -4407,11 +4444,12 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
4407
4444
  }
4408
4445
 
4409
4446
  {
4410
- VALUE argv2[2], hash;
4411
-
4412
- argv2[0] = str;
4413
- argv2[1] = comp;
4414
- hash = date_s__parse(2, argv2, klass);
4447
+ int argc2 = 2;
4448
+ VALUE argv2[3];
4449
+ argv2[0] = str;
4450
+ argv2[1] = comp;
4451
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4452
+ VALUE hash = date_s__parse(argc2, argv2, klass);
4415
4453
  return d_new_by_frags(klass, hash, sg);
4416
4454
  }
4417
4455
  }
@@ -4425,19 +4463,28 @@ VALUE date__jisx0301(VALUE);
4425
4463
 
4426
4464
  /*
4427
4465
  * call-seq:
4428
- * Date._iso8601(string) -> hash
4466
+ * Date._iso8601(string, limit: 128) -> hash
4429
4467
  *
4430
4468
  * Returns a hash of parsed elements.
4469
+ *
4470
+ * Raise an ArgumentError when the string length is longer than _limit_.
4471
+ * You can stop this check by passing `limit: nil`, but note that
4472
+ * it may take a long time to parse.
4431
4473
  */
4432
4474
  static VALUE
4433
- date_s__iso8601(VALUE klass, VALUE str)
4475
+ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
4434
4476
  {
4477
+ VALUE str, opt;
4478
+
4479
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4480
+ check_limit(str, opt);
4481
+
4435
4482
  return date__iso8601(str);
4436
4483
  }
4437
4484
 
4438
4485
  /*
4439
4486
  * call-seq:
4440
- * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY]) -> date
4487
+ * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4441
4488
  *
4442
4489
  * Creates a new Date object by parsing from a string according to
4443
4490
  * some typical ISO 8601 formats.
@@ -4445,13 +4492,18 @@ date_s__iso8601(VALUE klass, VALUE str)
4445
4492
  * Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
4446
4493
  * Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
4447
4494
  * Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
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.
4448
4499
  */
4449
4500
  static VALUE
4450
4501
  date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4451
4502
  {
4452
- VALUE str, sg;
4503
+ VALUE str, sg, opt;
4453
4504
 
4454
- rb_scan_args(argc, argv, "02", &str, &sg);
4505
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4506
+ if (!NIL_P(opt)) argc--;
4455
4507
 
4456
4508
  switch (argc) {
4457
4509
  case 0:
@@ -4461,38 +4513,56 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4461
4513
  }
4462
4514
 
4463
4515
  {
4464
- VALUE hash = date_s__iso8601(klass, str);
4516
+ int argc2 = 1;
4517
+ VALUE argv2[2];
4518
+ argv2[0] = str;
4519
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4520
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
4465
4521
  return d_new_by_frags(klass, hash, sg);
4466
4522
  }
4467
4523
  }
4468
4524
 
4469
4525
  /*
4470
4526
  * call-seq:
4471
- * Date._rfc3339(string) -> hash
4527
+ * Date._rfc3339(string, limit: 128) -> hash
4472
4528
  *
4473
4529
  * Returns a hash of parsed elements.
4530
+ *
4531
+ * Raise an ArgumentError when the string length is longer than _limit_.
4532
+ * You can stop this check by passing `limit: nil`, but note that
4533
+ * it may take a long time to parse.
4474
4534
  */
4475
4535
  static VALUE
4476
- date_s__rfc3339(VALUE klass, VALUE str)
4536
+ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
4477
4537
  {
4538
+ VALUE str, opt;
4539
+
4540
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4541
+ check_limit(str, opt);
4542
+
4478
4543
  return date__rfc3339(str);
4479
4544
  }
4480
4545
 
4481
4546
  /*
4482
4547
  * call-seq:
4483
- * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> date
4548
+ * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
4484
4549
  *
4485
4550
  * Creates a new Date object by parsing from a string according to
4486
4551
  * some typical RFC 3339 formats.
4487
4552
  *
4488
4553
  * Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
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.
4489
4558
  */
4490
4559
  static VALUE
4491
4560
  date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4492
4561
  {
4493
- VALUE str, sg;
4562
+ VALUE str, sg, opt;
4494
4563
 
4495
- rb_scan_args(argc, argv, "02", &str, &sg);
4564
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4565
+ if (!NIL_P(opt)) argc--;
4496
4566
 
4497
4567
  switch (argc) {
4498
4568
  case 0:
@@ -4502,38 +4572,56 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4502
4572
  }
4503
4573
 
4504
4574
  {
4505
- VALUE hash = date_s__rfc3339(klass, str);
4575
+ int argc2 = 1;
4576
+ VALUE argv2[2];
4577
+ argv2[0] = str;
4578
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4579
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
4506
4580
  return d_new_by_frags(klass, hash, sg);
4507
4581
  }
4508
4582
  }
4509
4583
 
4510
4584
  /*
4511
4585
  * call-seq:
4512
- * Date._xmlschema(string) -> hash
4586
+ * Date._xmlschema(string, limit: 128) -> hash
4513
4587
  *
4514
4588
  * Returns a hash of parsed elements.
4589
+ *
4590
+ * Raise an ArgumentError when the string length is longer than _limit_.
4591
+ * You can stop this check by passing `limit: nil`, but note that
4592
+ * it may take a long time to parse.
4515
4593
  */
4516
4594
  static VALUE
4517
- date_s__xmlschema(VALUE klass, VALUE str)
4595
+ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
4518
4596
  {
4597
+ VALUE str, opt;
4598
+
4599
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4600
+ check_limit(str, opt);
4601
+
4519
4602
  return date__xmlschema(str);
4520
4603
  }
4521
4604
 
4522
4605
  /*
4523
4606
  * call-seq:
4524
- * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY]) -> date
4607
+ * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4525
4608
  *
4526
4609
  * Creates a new Date object by parsing from a string according to
4527
4610
  * some typical XML Schema formats.
4528
4611
  *
4529
4612
  * Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
4613
+ *
4614
+ * Raise an ArgumentError when the string length is longer than _limit_.
4615
+ * You can stop this check by passing `limit: nil`, but note that
4616
+ * it may take a long time to parse.
4530
4617
  */
4531
4618
  static VALUE
4532
4619
  date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4533
4620
  {
4534
- VALUE str, sg;
4621
+ VALUE str, sg, opt;
4535
4622
 
4536
- rb_scan_args(argc, argv, "02", &str, &sg);
4623
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4624
+ if (!NIL_P(opt)) argc--;
4537
4625
 
4538
4626
  switch (argc) {
4539
4627
  case 0:
@@ -4543,41 +4631,58 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4543
4631
  }
4544
4632
 
4545
4633
  {
4546
- VALUE hash = date_s__xmlschema(klass, str);
4634
+ int argc2 = 1;
4635
+ VALUE argv2[2];
4636
+ argv2[0] = str;
4637
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4638
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
4547
4639
  return d_new_by_frags(klass, hash, sg);
4548
4640
  }
4549
4641
  }
4550
4642
 
4551
4643
  /*
4552
4644
  * call-seq:
4553
- * Date._rfc2822(string) -> hash
4554
- * Date._rfc822(string) -> hash
4645
+ * Date._rfc2822(string, limit: 128) -> hash
4646
+ * Date._rfc822(string, limit: 128) -> hash
4555
4647
  *
4556
4648
  * Returns a hash of parsed elements.
4649
+ *
4650
+ * Raise an ArgumentError when the string length is longer than _limit_.
4651
+ * You can stop this check by passing `limit: nil`, but note that
4652
+ * it may take a long time to parse.
4557
4653
  */
4558
4654
  static VALUE
4559
- date_s__rfc2822(VALUE klass, VALUE str)
4655
+ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
4560
4656
  {
4657
+ VALUE str, opt;
4658
+
4659
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4660
+ check_limit(str, opt);
4661
+
4561
4662
  return date__rfc2822(str);
4562
4663
  }
4563
4664
 
4564
4665
  /*
4565
4666
  * call-seq:
4566
- * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
4567
- * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
4667
+ * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4668
+ * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4568
4669
  *
4569
4670
  * Creates a new Date object by parsing from a string according to
4570
4671
  * some typical RFC 2822 formats.
4571
4672
  *
4572
4673
  * Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
4573
4674
  * #=> #<Date: 2001-02-03 ...>
4675
+ *
4676
+ * Raise an ArgumentError when the string length is longer than _limit_.
4677
+ * You can stop this check by passing `limit: nil`, but note that
4678
+ * it may take a long time to parse.
4574
4679
  */
4575
4680
  static VALUE
4576
4681
  date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4577
4682
  {
4578
- VALUE str, sg;
4683
+ VALUE str, sg, opt;
4579
4684
 
4580
- rb_scan_args(argc, argv, "02", &str, &sg);
4685
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4581
4686
 
4582
4687
  switch (argc) {
4583
4688
  case 0:
@@ -4587,39 +4692,56 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4587
4692
  }
4588
4693
 
4589
4694
  {
4590
- VALUE hash = date_s__rfc2822(klass, str);
4695
+ int argc2 = 1;
4696
+ VALUE argv2[2];
4697
+ argv2[0] = str;
4698
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4699
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
4591
4700
  return d_new_by_frags(klass, hash, sg);
4592
4701
  }
4593
4702
  }
4594
4703
 
4595
4704
  /*
4596
4705
  * call-seq:
4597
- * Date._httpdate(string) -> hash
4706
+ * Date._httpdate(string, limit: 128) -> hash
4598
4707
  *
4599
4708
  * Returns a hash of parsed elements.
4709
+ *
4710
+ * Raise an ArgumentError when the string length is longer than _limit_.
4711
+ * You can stop this check by passing `limit: nil`, but note that
4712
+ * it may take a long time to parse.
4600
4713
  */
4601
4714
  static VALUE
4602
- date_s__httpdate(VALUE klass, VALUE str)
4715
+ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
4603
4716
  {
4717
+ VALUE str, opt;
4718
+
4719
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4720
+ check_limit(str, opt);
4721
+
4604
4722
  return date__httpdate(str);
4605
4723
  }
4606
4724
 
4607
4725
  /*
4608
4726
  * call-seq:
4609
- * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]) -> date
4727
+ * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
4610
4728
  *
4611
4729
  * Creates a new Date object by parsing from a string according to
4612
4730
  * some RFC 2616 format.
4613
4731
  *
4614
4732
  * Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
4615
4733
  * #=> #<Date: 2001-02-03 ...>
4734
+ *
4735
+ * Raise an ArgumentError when the string length is longer than _limit_.
4736
+ * You can stop this check by passing `limit: nil`, but note that
4737
+ * it may take a long time to parse.
4616
4738
  */
4617
4739
  static VALUE
4618
4740
  date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4619
4741
  {
4620
- VALUE str, sg;
4742
+ VALUE str, sg, opt;
4621
4743
 
4622
- rb_scan_args(argc, argv, "02", &str, &sg);
4744
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4623
4745
 
4624
4746
  switch (argc) {
4625
4747
  case 0:
@@ -4629,26 +4751,39 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4629
4751
  }
4630
4752
 
4631
4753
  {
4632
- VALUE hash = date_s__httpdate(klass, str);
4754
+ int argc2 = 1;
4755
+ VALUE argv2[2];
4756
+ argv2[0] = str;
4757
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4758
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
4633
4759
  return d_new_by_frags(klass, hash, sg);
4634
4760
  }
4635
4761
  }
4636
4762
 
4637
4763
  /*
4638
4764
  * call-seq:
4639
- * Date._jisx0301(string) -> hash
4765
+ * Date._jisx0301(string, limit: 128) -> hash
4640
4766
  *
4641
4767
  * Returns a hash of parsed elements.
4768
+ *
4769
+ * Raise an ArgumentError when the string length is longer than _limit_.
4770
+ * You can stop this check by passing `limit: nil`, but note that
4771
+ * it may take a long time to parse.
4642
4772
  */
4643
4773
  static VALUE
4644
- date_s__jisx0301(VALUE klass, VALUE str)
4774
+ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4645
4775
  {
4776
+ VALUE str, opt;
4777
+
4778
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4779
+ check_limit(str, opt);
4780
+
4646
4781
  return date__jisx0301(str);
4647
4782
  }
4648
4783
 
4649
4784
  /*
4650
4785
  * call-seq:
4651
- * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY]) -> date
4786
+ * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4652
4787
  *
4653
4788
  * Creates a new Date object by parsing from a string according to
4654
4789
  * some typical JIS X 0301 formats.
@@ -4658,13 +4793,18 @@ date_s__jisx0301(VALUE klass, VALUE str)
4658
4793
  * For no-era year, legacy format, Heisei is assumed.
4659
4794
  *
4660
4795
  * Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
4796
+ *
4797
+ * Raise an ArgumentError when the string length is longer than _limit_.
4798
+ * You can stop this check by passing `limit: nil`, but note that
4799
+ * it may take a long time to parse.
4661
4800
  */
4662
4801
  static VALUE
4663
4802
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4664
4803
  {
4665
- VALUE str, sg;
4804
+ VALUE str, sg, opt;
4666
4805
 
4667
- rb_scan_args(argc, argv, "02", &str, &sg);
4806
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4807
+ if (!NIL_P(opt)) argc--;
4668
4808
 
4669
4809
  switch (argc) {
4670
4810
  case 0:
@@ -4674,7 +4814,11 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4674
4814
  }
4675
4815
 
4676
4816
  {
4677
- VALUE hash = date_s__jisx0301(klass, str);
4817
+ int argc2 = 1;
4818
+ VALUE argv2[2];
4819
+ argv2[0] = str;
4820
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4821
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
4678
4822
  return d_new_by_frags(klass, hash, sg);
4679
4823
  }
4680
4824
  }
@@ -8013,7 +8157,7 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8013
8157
 
8014
8158
  /*
8015
8159
  * call-seq:
8016
- * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]) -> datetime
8160
+ * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]], limit: 128) -> datetime
8017
8161
  *
8018
8162
  * Parses the given representation of date and time, and creates a
8019
8163
  * DateTime object.
@@ -8032,13 +8176,18 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8032
8176
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8033
8177
  * DateTime.parse('3rd Feb 2001 04:05:06 PM')
8034
8178
  * #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
8179
+ *
8180
+ * Raise an ArgumentError when the string length is longer than _limit_.
8181
+ * You can stop this check by passing `limit: nil`, but note that
8182
+ * it may take a long time to parse.
8035
8183
  */
8036
8184
  static VALUE
8037
8185
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8038
8186
  {
8039
- VALUE str, comp, sg;
8187
+ VALUE str, comp, sg, opt;
8040
8188
 
8041
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
8189
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
8190
+ if (!NIL_P(opt)) argc--;
8042
8191
 
8043
8192
  switch (argc) {
8044
8193
  case 0:
@@ -8050,18 +8199,20 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8050
8199
  }
8051
8200
 
8052
8201
  {
8053
- VALUE argv2[2], hash;
8054
-
8055
- argv2[0] = str;
8056
- argv2[1] = comp;
8057
- hash = date_s__parse(2, argv2, klass);
8202
+ int argc2 = 2;
8203
+ VALUE argv2[3];
8204
+ argv2[0] = str;
8205
+ argv2[1] = comp;
8206
+ argv2[2] = opt;
8207
+ if (!NIL_P(opt)) argc2++;
8208
+ VALUE hash = date_s__parse(argc2, argv2, klass);
8058
8209
  return dt_new_by_frags(klass, hash, sg);
8059
8210
  }
8060
8211
  }
8061
8212
 
8062
8213
  /*
8063
8214
  * call-seq:
8064
- * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8215
+ * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8065
8216
  *
8066
8217
  * Creates a new DateTime object by parsing from a string according to
8067
8218
  * some typical ISO 8601 formats.
@@ -8072,13 +8223,18 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8072
8223
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8073
8224
  * DateTime.iso8601('2001-W05-6T04:05:06+07:00')
8074
8225
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8226
+ *
8227
+ * Raise an ArgumentError when the string length is longer than _limit_.
8228
+ * You can stop this check by passing `limit: nil`, but note that
8229
+ * it may take a long time to parse.
8075
8230
  */
8076
8231
  static VALUE
8077
8232
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8078
8233
  {
8079
- VALUE str, sg;
8234
+ VALUE str, sg, opt;
8080
8235
 
8081
- rb_scan_args(argc, argv, "02", &str, &sg);
8236
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8237
+ if (!NIL_P(opt)) argc--;
8082
8238
 
8083
8239
  switch (argc) {
8084
8240
  case 0:
@@ -8088,27 +8244,37 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8088
8244
  }
8089
8245
 
8090
8246
  {
8091
- VALUE hash = date_s__iso8601(klass, str);
8247
+ int argc2 = 1;
8248
+ VALUE argv2[2];
8249
+ argv2[0] = str;
8250
+ argv2[1] = opt;
8251
+ if (!NIL_P(opt)) argc2--;
8252
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
8092
8253
  return dt_new_by_frags(klass, hash, sg);
8093
8254
  }
8094
8255
  }
8095
8256
 
8096
8257
  /*
8097
8258
  * call-seq:
8098
- * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8259
+ * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8099
8260
  *
8100
8261
  * Creates a new DateTime object by parsing from a string according to
8101
8262
  * some typical RFC 3339 formats.
8102
8263
  *
8103
8264
  * DateTime.rfc3339('2001-02-03T04:05:06+07:00')
8104
8265
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8266
+ *
8267
+ * Raise an ArgumentError when the string length is longer than _limit_.
8268
+ * You can stop this check by passing `limit: nil`, but note that
8269
+ * it may take a long time to parse.
8105
8270
  */
8106
8271
  static VALUE
8107
8272
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8108
8273
  {
8109
- VALUE str, sg;
8274
+ VALUE str, sg, opt;
8110
8275
 
8111
- rb_scan_args(argc, argv, "02", &str, &sg);
8276
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8277
+ if (!NIL_P(opt)) argc--;
8112
8278
 
8113
8279
  switch (argc) {
8114
8280
  case 0:
@@ -8118,27 +8284,37 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8118
8284
  }
8119
8285
 
8120
8286
  {
8121
- VALUE hash = date_s__rfc3339(klass, str);
8287
+ int argc2 = 1;
8288
+ VALUE argv2[2];
8289
+ argv2[0] = str;
8290
+ argv2[1] = opt;
8291
+ if (!NIL_P(opt)) argc2++;
8292
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
8122
8293
  return dt_new_by_frags(klass, hash, sg);
8123
8294
  }
8124
8295
  }
8125
8296
 
8126
8297
  /*
8127
8298
  * call-seq:
8128
- * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8299
+ * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8129
8300
  *
8130
8301
  * Creates a new DateTime object by parsing from a string according to
8131
8302
  * some typical XML Schema formats.
8132
8303
  *
8133
8304
  * DateTime.xmlschema('2001-02-03T04:05:06+07:00')
8134
8305
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8306
+ *
8307
+ * Raise an ArgumentError when the string length is longer than _limit_.
8308
+ * You can stop this check by passing `limit: nil`, but note that
8309
+ * it may take a long time to parse.
8135
8310
  */
8136
8311
  static VALUE
8137
8312
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8138
8313
  {
8139
- VALUE str, sg;
8314
+ VALUE str, sg, opt;
8140
8315
 
8141
- rb_scan_args(argc, argv, "02", &str, &sg);
8316
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8317
+ if (!NIL_P(opt)) argc--;
8142
8318
 
8143
8319
  switch (argc) {
8144
8320
  case 0:
@@ -8148,28 +8324,38 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8148
8324
  }
8149
8325
 
8150
8326
  {
8151
- VALUE hash = date_s__xmlschema(klass, str);
8327
+ int argc2 = 1;
8328
+ VALUE argv2[2];
8329
+ argv2[0] = str;
8330
+ argv2[1] = opt;
8331
+ if (!NIL_P(opt)) argc2++;
8332
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
8152
8333
  return dt_new_by_frags(klass, hash, sg);
8153
8334
  }
8154
8335
  }
8155
8336
 
8156
8337
  /*
8157
8338
  * call-seq:
8158
- * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8159
- * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8339
+ * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8340
+ * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8160
8341
  *
8161
8342
  * Creates a new DateTime object by parsing from a string according to
8162
8343
  * some typical RFC 2822 formats.
8163
8344
  *
8164
8345
  * DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700')
8165
8346
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8347
+ *
8348
+ * Raise an ArgumentError when the string length is longer than _limit_.
8349
+ * You can stop this check by passing `limit: nil`, but note that
8350
+ * it may take a long time to parse.
8166
8351
  */
8167
8352
  static VALUE
8168
8353
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8169
8354
  {
8170
- VALUE str, sg;
8355
+ VALUE str, sg, opt;
8171
8356
 
8172
- rb_scan_args(argc, argv, "02", &str, &sg);
8357
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8358
+ if (!NIL_P(opt)) argc--;
8173
8359
 
8174
8360
  switch (argc) {
8175
8361
  case 0:
@@ -8179,7 +8365,12 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8179
8365
  }
8180
8366
 
8181
8367
  {
8182
- VALUE hash = date_s__rfc2822(klass, str);
8368
+ int argc2 = 1;
8369
+ VALUE argv2[2];
8370
+ argv2[0] = str;
8371
+ argv2[1] = opt;
8372
+ if (!NIL_P(opt)) argc2++;
8373
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
8183
8374
  return dt_new_by_frags(klass, hash, sg);
8184
8375
  }
8185
8376
  }
@@ -8193,13 +8384,18 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8193
8384
  *
8194
8385
  * DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
8195
8386
  * #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
8387
+ *
8388
+ * Raise an ArgumentError when the string length is longer than _limit_.
8389
+ * You can stop this check by passing `limit: nil`, but note that
8390
+ * it may take a long time to parse.
8196
8391
  */
8197
8392
  static VALUE
8198
8393
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8199
8394
  {
8200
- VALUE str, sg;
8395
+ VALUE str, sg, opt;
8201
8396
 
8202
- rb_scan_args(argc, argv, "02", &str, &sg);
8397
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8398
+ if (!NIL_P(opt)) argc--;
8203
8399
 
8204
8400
  switch (argc) {
8205
8401
  case 0:
@@ -8209,14 +8405,19 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8209
8405
  }
8210
8406
 
8211
8407
  {
8212
- VALUE hash = date_s__httpdate(klass, str);
8408
+ int argc2 = 1;
8409
+ VALUE argv2[2];
8410
+ argv2[0] = str;
8411
+ argv2[1] = opt;
8412
+ if (!NIL_P(opt)) argc2++;
8413
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
8213
8414
  return dt_new_by_frags(klass, hash, sg);
8214
8415
  }
8215
8416
  }
8216
8417
 
8217
8418
  /*
8218
8419
  * call-seq:
8219
- * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8420
+ * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8220
8421
  *
8221
8422
  * Creates a new DateTime object by parsing from a string according to
8222
8423
  * some typical JIS X 0301 formats.
@@ -8228,13 +8429,18 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8228
8429
  *
8229
8430
  * DateTime.jisx0301('13.02.03T04:05:06+07:00')
8230
8431
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8432
+ *
8433
+ * Raise an ArgumentError when the string length is longer than _limit_.
8434
+ * You can stop this check by passing `limit: nil`, but note that
8435
+ * it may take a long time to parse.
8231
8436
  */
8232
8437
  static VALUE
8233
8438
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8234
8439
  {
8235
- VALUE str, sg;
8440
+ VALUE str, sg, opt;
8236
8441
 
8237
- rb_scan_args(argc, argv, "02", &str, &sg);
8442
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8443
+ if (!NIL_P(opt)) argc--;
8238
8444
 
8239
8445
  switch (argc) {
8240
8446
  case 0:
@@ -8244,7 +8450,12 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8244
8450
  }
8245
8451
 
8246
8452
  {
8247
- VALUE hash = date_s__jisx0301(klass, str);
8453
+ int argc2 = 1;
8454
+ VALUE argv2[2];
8455
+ argv2[0] = str;
8456
+ argv2[1] = opt;
8457
+ if (!NIL_P(opt)) argc2++;
8458
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
8248
8459
  return dt_new_by_frags(klass, hash, sg);
8249
8460
  }
8250
8461
  }
@@ -9403,19 +9614,19 @@ Init_date_core(void)
9403
9614
  rb_define_singleton_method(cDate, "strptime", date_s_strptime, -1);
9404
9615
  rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
9405
9616
  rb_define_singleton_method(cDate, "parse", date_s_parse, -1);
9406
- rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, 1);
9617
+ rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, -1);
9407
9618
  rb_define_singleton_method(cDate, "iso8601", date_s_iso8601, -1);
9408
- rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, 1);
9619
+ rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, -1);
9409
9620
  rb_define_singleton_method(cDate, "rfc3339", date_s_rfc3339, -1);
9410
- rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, 1);
9621
+ rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, -1);
9411
9622
  rb_define_singleton_method(cDate, "xmlschema", date_s_xmlschema, -1);
9412
- rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, 1);
9413
- rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, 1);
9623
+ rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, -1);
9624
+ rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, -1);
9414
9625
  rb_define_singleton_method(cDate, "rfc2822", date_s_rfc2822, -1);
9415
9626
  rb_define_singleton_method(cDate, "rfc822", date_s_rfc2822, -1);
9416
- rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, 1);
9627
+ rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, -1);
9417
9628
  rb_define_singleton_method(cDate, "httpdate", date_s_httpdate, -1);
9418
- rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
9629
+ rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, -1);
9419
9630
  rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
9420
9631
 
9421
9632
  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 = '3.2.2' # :nodoc:
7
8
 
8
9
  def infinite?
9
10
  false
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: 3.2.0
4
+ version: 3.2.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: 2021-10-14 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A subclass of Object includes Comparable module for handling dates.
14
14
  email:
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.2.22
51
+ rubygems_version: 3.3.0.dev
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: A subclass of Object includes Comparable module for handling dates.