date 2.0.0 → 2.0.1

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/date/date_core.c +296 -88
  3. 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: 9e9443b3ef9379645949642103301f3690370faafae8013d06e95e3c6f7e3cad
4
+ data.tar.gz: 279fb25c099c4d6441343bbd5a47da7aeb7fc1840410d84e6fefe89ebda8b1a0
5
5
  SHA512:
6
- metadata.gz: 51f50fb953dbf4aa82c35e3e6145e0ce10c8696ec17f9577339297ee0cfc6b4fb8f0bfa05d353e2571f5963ef8f1a53dfe351b69b9acf756212b1283629f2b9d
7
- data.tar.gz: ddc9ed30e31c2dc6bb29af2c25457338d46c73ca81d73cc6fb90312d5b837b8bd1784fc3e8236f36f7f4e74a2590e36637b3b4acfffa4119119f562ef3da7c30
6
+ metadata.gz: 9bab83cdb75a5a67c800b82615853a5e10e5961371cfbe5ff7c71ad6f8b3ea1749730f382580ddf24d2cdb27735cf34f03443de7e491620aa1753cdf18ed8ac5
7
+ data.tar.gz: 8060944cf766e59e231c279c524b51c9ef9d06ae959e2077a1da1627d1de04e2f798fc1d1a28dfe2c3a0b0ce772f4f4ba369b1bf5aeca1cd6d085fa02319d871
data/ext/date/date_core.c CHANGED
@@ -4292,12 +4292,37 @@ 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
+ StringValue(str);
4310
+ size_t slen = RSTRING_LEN(str);
4311
+ size_t limit = get_limit(opt);
4312
+ if (slen > limit) {
4313
+ rb_raise(rb_eArgError,
4314
+ "string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit);
4315
+ }
4316
+ }
4317
+
4295
4318
  static VALUE
4296
4319
  date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4297
4320
  {
4298
- VALUE vstr, vcomp, hash;
4321
+ VALUE vstr, vcomp, hash, opt;
4299
4322
 
4300
- rb_scan_args(argc, argv, "11", &vstr, &vcomp);
4323
+ rb_scan_args(argc, argv, "11:", &vstr, &vcomp, &opt);
4324
+ if (!NIL_P(opt)) argc--;
4325
+ check_limit(vstr, opt);
4301
4326
  StringValue(vstr);
4302
4327
  if (!rb_enc_str_asciicompat_p(vstr))
4303
4328
  rb_raise(rb_eArgError,
@@ -4322,7 +4347,7 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4322
4347
 
4323
4348
  /*
4324
4349
  * call-seq:
4325
- * Date._parse(string[, comp=true]) -> hash
4350
+ * Date._parse(string[, comp=true], limit: 128) -> hash
4326
4351
  *
4327
4352
  * Parses the given representation of date and time, and returns a
4328
4353
  * hash of parsed elements. This method does not function as a
@@ -4333,6 +4358,10 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4333
4358
  * it full.
4334
4359
  *
4335
4360
  * Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
4361
+ *
4362
+ * Raise an ArgumentError when the string length is longer than _limit_.
4363
+ * You can stop this check by passing `limit: nil`, but note that
4364
+ * it may take a long time to parse.
4336
4365
  */
4337
4366
  static VALUE
4338
4367
  date_s__parse(int argc, VALUE *argv, VALUE klass)
@@ -4342,7 +4371,7 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4342
4371
 
4343
4372
  /*
4344
4373
  * call-seq:
4345
- * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]]) -> date
4374
+ * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
4346
4375
  *
4347
4376
  * Parses the given representation of date and time, and creates a
4348
4377
  * date object. This method does not function as a validator.
@@ -4354,13 +4383,18 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4354
4383
  * Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
4355
4384
  * Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
4356
4385
  * Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
4386
+ *
4387
+ * Raise an ArgumentError when the string length is longer than _limit_.
4388
+ * You can stop this check by passing `limit: nil`, but note that
4389
+ * it may take a long time to parse.
4357
4390
  */
4358
4391
  static VALUE
4359
4392
  date_s_parse(int argc, VALUE *argv, VALUE klass)
4360
4393
  {
4361
- VALUE str, comp, sg;
4394
+ VALUE str, comp, sg, opt;
4362
4395
 
4363
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
4396
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
4397
+ if (!NIL_P(opt)) argc--;
4364
4398
 
4365
4399
  switch (argc) {
4366
4400
  case 0:
@@ -4372,11 +4406,12 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
4372
4406
  }
4373
4407
 
4374
4408
  {
4375
- VALUE argv2[2], hash;
4376
-
4377
- argv2[0] = str;
4378
- argv2[1] = comp;
4379
- hash = date_s__parse(2, argv2, klass);
4409
+ int argc2 = 2;
4410
+ VALUE argv2[3];
4411
+ argv2[0] = str;
4412
+ argv2[1] = comp;
4413
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4414
+ VALUE hash = date_s__parse(argc2, argv2, klass);
4380
4415
  return d_new_by_frags(klass, hash, sg);
4381
4416
  }
4382
4417
  }
@@ -4390,19 +4425,28 @@ VALUE date__jisx0301(VALUE);
4390
4425
 
4391
4426
  /*
4392
4427
  * call-seq:
4393
- * Date._iso8601(string) -> hash
4428
+ * Date._iso8601(string, limit: 128) -> hash
4394
4429
  *
4395
4430
  * Returns a hash of parsed elements.
4431
+ *
4432
+ * Raise an ArgumentError when the string length is longer than _limit_.
4433
+ * You can stop this check by passing `limit: nil`, but note that
4434
+ * it may take a long time to parse.
4396
4435
  */
4397
4436
  static VALUE
4398
- date_s__iso8601(VALUE klass, VALUE str)
4437
+ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
4399
4438
  {
4439
+ VALUE str, opt;
4440
+
4441
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4442
+ check_limit(str, opt);
4443
+
4400
4444
  return date__iso8601(str);
4401
4445
  }
4402
4446
 
4403
4447
  /*
4404
4448
  * call-seq:
4405
- * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY]) -> date
4449
+ * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4406
4450
  *
4407
4451
  * Creates a new Date object by parsing from a string according to
4408
4452
  * some typical ISO 8601 formats.
@@ -4410,13 +4454,18 @@ date_s__iso8601(VALUE klass, VALUE str)
4410
4454
  * Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
4411
4455
  * Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
4412
4456
  * Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
4457
+ *
4458
+ * Raise an ArgumentError when the string length is longer than _limit_.
4459
+ * You can stop this check by passing `limit: nil`, but note that
4460
+ * it may take a long time to parse.
4413
4461
  */
4414
4462
  static VALUE
4415
4463
  date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4416
4464
  {
4417
- VALUE str, sg;
4465
+ VALUE str, sg, opt;
4418
4466
 
4419
- rb_scan_args(argc, argv, "02", &str, &sg);
4467
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4468
+ if (!NIL_P(opt)) argc--;
4420
4469
 
4421
4470
  switch (argc) {
4422
4471
  case 0:
@@ -4426,38 +4475,56 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4426
4475
  }
4427
4476
 
4428
4477
  {
4429
- VALUE hash = date_s__iso8601(klass, str);
4478
+ int argc2 = 1;
4479
+ VALUE argv2[2];
4480
+ argv2[0] = str;
4481
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4482
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
4430
4483
  return d_new_by_frags(klass, hash, sg);
4431
4484
  }
4432
4485
  }
4433
4486
 
4434
4487
  /*
4435
4488
  * call-seq:
4436
- * Date._rfc3339(string) -> hash
4489
+ * Date._rfc3339(string, limit: 128) -> hash
4437
4490
  *
4438
4491
  * Returns a hash of parsed elements.
4492
+ *
4493
+ * Raise an ArgumentError when the string length is longer than _limit_.
4494
+ * You can stop this check by passing `limit: nil`, but note that
4495
+ * it may take a long time to parse.
4439
4496
  */
4440
4497
  static VALUE
4441
- date_s__rfc3339(VALUE klass, VALUE str)
4498
+ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
4442
4499
  {
4500
+ VALUE str, opt;
4501
+
4502
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4503
+ check_limit(str, opt);
4504
+
4443
4505
  return date__rfc3339(str);
4444
4506
  }
4445
4507
 
4446
4508
  /*
4447
4509
  * call-seq:
4448
- * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> date
4510
+ * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
4449
4511
  *
4450
4512
  * Creates a new Date object by parsing from a string according to
4451
4513
  * some typical RFC 3339 formats.
4452
4514
  *
4453
4515
  * Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
4516
+ *
4517
+ * Raise an ArgumentError when the string length is longer than _limit_.
4518
+ * You can stop this check by passing `limit: nil`, but note that
4519
+ * it may take a long time to parse.
4454
4520
  */
4455
4521
  static VALUE
4456
4522
  date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4457
4523
  {
4458
- VALUE str, sg;
4524
+ VALUE str, sg, opt;
4459
4525
 
4460
- rb_scan_args(argc, argv, "02", &str, &sg);
4526
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4527
+ if (!NIL_P(opt)) argc--;
4461
4528
 
4462
4529
  switch (argc) {
4463
4530
  case 0:
@@ -4467,38 +4534,56 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4467
4534
  }
4468
4535
 
4469
4536
  {
4470
- VALUE hash = date_s__rfc3339(klass, str);
4537
+ int argc2 = 1;
4538
+ VALUE argv2[2];
4539
+ argv2[0] = str;
4540
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4541
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
4471
4542
  return d_new_by_frags(klass, hash, sg);
4472
4543
  }
4473
4544
  }
4474
4545
 
4475
4546
  /*
4476
4547
  * call-seq:
4477
- * Date._xmlschema(string) -> hash
4548
+ * Date._xmlschema(string, limit: 128) -> hash
4478
4549
  *
4479
4550
  * Returns a hash of parsed elements.
4551
+ *
4552
+ * Raise an ArgumentError when the string length is longer than _limit_.
4553
+ * You can stop this check by passing `limit: nil`, but note that
4554
+ * it may take a long time to parse.
4480
4555
  */
4481
4556
  static VALUE
4482
- date_s__xmlschema(VALUE klass, VALUE str)
4557
+ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
4483
4558
  {
4559
+ VALUE str, opt;
4560
+
4561
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4562
+ check_limit(str, opt);
4563
+
4484
4564
  return date__xmlschema(str);
4485
4565
  }
4486
4566
 
4487
4567
  /*
4488
4568
  * call-seq:
4489
- * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY]) -> date
4569
+ * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4490
4570
  *
4491
4571
  * Creates a new Date object by parsing from a string according to
4492
4572
  * some typical XML Schema formats.
4493
4573
  *
4494
4574
  * Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
4575
+ *
4576
+ * Raise an ArgumentError when the string length is longer than _limit_.
4577
+ * You can stop this check by passing `limit: nil`, but note that
4578
+ * it may take a long time to parse.
4495
4579
  */
4496
4580
  static VALUE
4497
4581
  date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4498
4582
  {
4499
- VALUE str, sg;
4583
+ VALUE str, sg, opt;
4500
4584
 
4501
- rb_scan_args(argc, argv, "02", &str, &sg);
4585
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4586
+ if (!NIL_P(opt)) argc--;
4502
4587
 
4503
4588
  switch (argc) {
4504
4589
  case 0:
@@ -4508,41 +4593,58 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4508
4593
  }
4509
4594
 
4510
4595
  {
4511
- VALUE hash = date_s__xmlschema(klass, str);
4596
+ int argc2 = 1;
4597
+ VALUE argv2[2];
4598
+ argv2[0] = str;
4599
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4600
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
4512
4601
  return d_new_by_frags(klass, hash, sg);
4513
4602
  }
4514
4603
  }
4515
4604
 
4516
4605
  /*
4517
4606
  * call-seq:
4518
- * Date._rfc2822(string) -> hash
4519
- * Date._rfc822(string) -> hash
4607
+ * Date._rfc2822(string, limit: 128) -> hash
4608
+ * Date._rfc822(string, limit: 128) -> hash
4520
4609
  *
4521
4610
  * Returns a hash of parsed elements.
4611
+ *
4612
+ * Raise an ArgumentError when the string length is longer than _limit_.
4613
+ * You can stop this check by passing `limit: nil`, but note that
4614
+ * it may take a long time to parse.
4522
4615
  */
4523
4616
  static VALUE
4524
- date_s__rfc2822(VALUE klass, VALUE str)
4617
+ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
4525
4618
  {
4619
+ VALUE str, opt;
4620
+
4621
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4622
+ check_limit(str, opt);
4623
+
4526
4624
  return date__rfc2822(str);
4527
4625
  }
4528
4626
 
4529
4627
  /*
4530
4628
  * 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
4629
+ * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4630
+ * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4533
4631
  *
4534
4632
  * Creates a new Date object by parsing from a string according to
4535
4633
  * some typical RFC 2822 formats.
4536
4634
  *
4537
4635
  * Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
4538
4636
  * #=> #<Date: 2001-02-03 ...>
4637
+ *
4638
+ * Raise an ArgumentError when the string length is longer than _limit_.
4639
+ * You can stop this check by passing `limit: nil`, but note that
4640
+ * it may take a long time to parse.
4539
4641
  */
4540
4642
  static VALUE
4541
4643
  date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4542
4644
  {
4543
- VALUE str, sg;
4645
+ VALUE str, sg, opt;
4544
4646
 
4545
- rb_scan_args(argc, argv, "02", &str, &sg);
4647
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4546
4648
 
4547
4649
  switch (argc) {
4548
4650
  case 0:
@@ -4552,39 +4654,56 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4552
4654
  }
4553
4655
 
4554
4656
  {
4555
- VALUE hash = date_s__rfc2822(klass, str);
4657
+ int argc2 = 1;
4658
+ VALUE argv2[2];
4659
+ argv2[0] = str;
4660
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4661
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
4556
4662
  return d_new_by_frags(klass, hash, sg);
4557
4663
  }
4558
4664
  }
4559
4665
 
4560
4666
  /*
4561
4667
  * call-seq:
4562
- * Date._httpdate(string) -> hash
4668
+ * Date._httpdate(string, limit: 128) -> hash
4563
4669
  *
4564
4670
  * Returns a hash of parsed elements.
4671
+ *
4672
+ * Raise an ArgumentError when the string length is longer than _limit_.
4673
+ * You can stop this check by passing `limit: nil`, but note that
4674
+ * it may take a long time to parse.
4565
4675
  */
4566
4676
  static VALUE
4567
- date_s__httpdate(VALUE klass, VALUE str)
4677
+ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
4568
4678
  {
4679
+ VALUE str, opt;
4680
+
4681
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4682
+ check_limit(str, opt);
4683
+
4569
4684
  return date__httpdate(str);
4570
4685
  }
4571
4686
 
4572
4687
  /*
4573
4688
  * call-seq:
4574
- * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]) -> date
4689
+ * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
4575
4690
  *
4576
4691
  * Creates a new Date object by parsing from a string according to
4577
4692
  * some RFC 2616 format.
4578
4693
  *
4579
4694
  * Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
4580
4695
  * #=> #<Date: 2001-02-03 ...>
4696
+ *
4697
+ * Raise an ArgumentError when the string length is longer than _limit_.
4698
+ * You can stop this check by passing `limit: nil`, but note that
4699
+ * it may take a long time to parse.
4581
4700
  */
4582
4701
  static VALUE
4583
4702
  date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4584
4703
  {
4585
- VALUE str, sg;
4704
+ VALUE str, sg, opt;
4586
4705
 
4587
- rb_scan_args(argc, argv, "02", &str, &sg);
4706
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4588
4707
 
4589
4708
  switch (argc) {
4590
4709
  case 0:
@@ -4594,38 +4713,56 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4594
4713
  }
4595
4714
 
4596
4715
  {
4597
- VALUE hash = date_s__httpdate(klass, str);
4716
+ int argc2 = 1;
4717
+ VALUE argv2[2];
4718
+ argv2[0] = str;
4719
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4720
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
4598
4721
  return d_new_by_frags(klass, hash, sg);
4599
4722
  }
4600
4723
  }
4601
4724
 
4602
4725
  /*
4603
4726
  * call-seq:
4604
- * Date._jisx0301(string) -> hash
4727
+ * Date._jisx0301(string, limit: 128) -> hash
4605
4728
  *
4606
4729
  * Returns a hash of parsed elements.
4730
+ *
4731
+ * Raise an ArgumentError when the string length is longer than _limit_.
4732
+ * You can stop this check by passing `limit: nil`, but note that
4733
+ * it may take a long time to parse.
4607
4734
  */
4608
4735
  static VALUE
4609
- date_s__jisx0301(VALUE klass, VALUE str)
4736
+ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4610
4737
  {
4738
+ VALUE str, opt;
4739
+
4740
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4741
+ check_limit(str, opt);
4742
+
4611
4743
  return date__jisx0301(str);
4612
4744
  }
4613
4745
 
4614
4746
  /*
4615
4747
  * call-seq:
4616
- * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY]) -> date
4748
+ * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4617
4749
  *
4618
4750
  * Creates a new Date object by parsing from a string according to
4619
4751
  * some typical JIS X 0301 formats.
4620
4752
  *
4621
4753
  * Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
4754
+ *
4755
+ * Raise an ArgumentError when the string length is longer than _limit_.
4756
+ * You can stop this check by passing `limit: nil`, but note that
4757
+ * it may take a long time to parse.
4622
4758
  */
4623
4759
  static VALUE
4624
4760
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4625
4761
  {
4626
- VALUE str, sg;
4762
+ VALUE str, sg, opt;
4627
4763
 
4628
- rb_scan_args(argc, argv, "02", &str, &sg);
4764
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4765
+ if (!NIL_P(opt)) argc--;
4629
4766
 
4630
4767
  switch (argc) {
4631
4768
  case 0:
@@ -4635,7 +4772,11 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4635
4772
  }
4636
4773
 
4637
4774
  {
4638
- VALUE hash = date_s__jisx0301(klass, str);
4775
+ int argc2 = 1;
4776
+ VALUE argv2[2];
4777
+ argv2[0] = str;
4778
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4779
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
4639
4780
  return d_new_by_frags(klass, hash, sg);
4640
4781
  }
4641
4782
  }
@@ -7951,7 +8092,7 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
7951
8092
 
7952
8093
  /*
7953
8094
  * call-seq:
7954
- * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]) -> datetime
8095
+ * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]], limit: 128) -> datetime
7955
8096
  *
7956
8097
  * Parses the given representation of date and time, and creates a
7957
8098
  * DateTime object. This method does not function as a validator.
@@ -7965,13 +8106,18 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
7965
8106
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
7966
8107
  * DateTime.parse('3rd Feb 2001 04:05:06 PM')
7967
8108
  * #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
8109
+ *
8110
+ * Raise an ArgumentError when the string length is longer than _limit_.
8111
+ * You can stop this check by passing `limit: nil`, but note that
8112
+ * it may take a long time to parse.
7968
8113
  */
7969
8114
  static VALUE
7970
8115
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
7971
8116
  {
7972
- VALUE str, comp, sg;
8117
+ VALUE str, comp, sg, opt;
7973
8118
 
7974
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
8119
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
8120
+ if (!NIL_P(opt)) argc--;
7975
8121
 
7976
8122
  switch (argc) {
7977
8123
  case 0:
@@ -7983,18 +8129,20 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
7983
8129
  }
7984
8130
 
7985
8131
  {
7986
- VALUE argv2[2], hash;
7987
-
7988
- argv2[0] = str;
7989
- argv2[1] = comp;
7990
- hash = date_s__parse(2, argv2, klass);
8132
+ int argc2 = 2;
8133
+ VALUE argv2[3];
8134
+ argv2[0] = str;
8135
+ argv2[1] = comp;
8136
+ argv2[2] = opt;
8137
+ if (!NIL_P(opt)) argc2++;
8138
+ VALUE hash = date_s__parse(argc2, argv2, klass);
7991
8139
  return dt_new_by_frags(klass, hash, sg);
7992
8140
  }
7993
8141
  }
7994
8142
 
7995
8143
  /*
7996
8144
  * call-seq:
7997
- * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8145
+ * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
7998
8146
  *
7999
8147
  * Creates a new DateTime object by parsing from a string according to
8000
8148
  * some typical ISO 8601 formats.
@@ -8005,13 +8153,18 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8005
8153
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8006
8154
  * DateTime.iso8601('2001-W05-6T04:05:06+07:00')
8007
8155
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8156
+ *
8157
+ * Raise an ArgumentError when the string length is longer than _limit_.
8158
+ * You can stop this check by passing `limit: nil`, but note that
8159
+ * it may take a long time to parse.
8008
8160
  */
8009
8161
  static VALUE
8010
8162
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8011
8163
  {
8012
- VALUE str, sg;
8164
+ VALUE str, sg, opt;
8013
8165
 
8014
- rb_scan_args(argc, argv, "02", &str, &sg);
8166
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8167
+ if (!NIL_P(opt)) argc--;
8015
8168
 
8016
8169
  switch (argc) {
8017
8170
  case 0:
@@ -8021,27 +8174,37 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8021
8174
  }
8022
8175
 
8023
8176
  {
8024
- VALUE hash = date_s__iso8601(klass, str);
8177
+ int argc2 = 1;
8178
+ VALUE argv2[2];
8179
+ argv2[0] = str;
8180
+ argv2[1] = opt;
8181
+ if (!NIL_P(opt)) argc2--;
8182
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
8025
8183
  return dt_new_by_frags(klass, hash, sg);
8026
8184
  }
8027
8185
  }
8028
8186
 
8029
8187
  /*
8030
8188
  * call-seq:
8031
- * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8189
+ * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8032
8190
  *
8033
8191
  * Creates a new DateTime object by parsing from a string according to
8034
8192
  * some typical RFC 3339 formats.
8035
8193
  *
8036
8194
  * DateTime.rfc3339('2001-02-03T04:05:06+07:00')
8037
8195
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8196
+ *
8197
+ * Raise an ArgumentError when the string length is longer than _limit_.
8198
+ * You can stop this check by passing `limit: nil`, but note that
8199
+ * it may take a long time to parse.
8038
8200
  */
8039
8201
  static VALUE
8040
8202
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8041
8203
  {
8042
- VALUE str, sg;
8204
+ VALUE str, sg, opt;
8043
8205
 
8044
- rb_scan_args(argc, argv, "02", &str, &sg);
8206
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8207
+ if (!NIL_P(opt)) argc--;
8045
8208
 
8046
8209
  switch (argc) {
8047
8210
  case 0:
@@ -8051,27 +8214,37 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8051
8214
  }
8052
8215
 
8053
8216
  {
8054
- VALUE hash = date_s__rfc3339(klass, str);
8217
+ int argc2 = 1;
8218
+ VALUE argv2[2];
8219
+ argv2[0] = str;
8220
+ argv2[1] = opt;
8221
+ if (!NIL_P(opt)) argc2++;
8222
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
8055
8223
  return dt_new_by_frags(klass, hash, sg);
8056
8224
  }
8057
8225
  }
8058
8226
 
8059
8227
  /*
8060
8228
  * call-seq:
8061
- * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8229
+ * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8062
8230
  *
8063
8231
  * Creates a new DateTime object by parsing from a string according to
8064
8232
  * some typical XML Schema formats.
8065
8233
  *
8066
8234
  * DateTime.xmlschema('2001-02-03T04:05:06+07:00')
8067
8235
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8236
+ *
8237
+ * Raise an ArgumentError when the string length is longer than _limit_.
8238
+ * You can stop this check by passing `limit: nil`, but note that
8239
+ * it may take a long time to parse.
8068
8240
  */
8069
8241
  static VALUE
8070
8242
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8071
8243
  {
8072
- VALUE str, sg;
8244
+ VALUE str, sg, opt;
8073
8245
 
8074
- rb_scan_args(argc, argv, "02", &str, &sg);
8246
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8247
+ if (!NIL_P(opt)) argc--;
8075
8248
 
8076
8249
  switch (argc) {
8077
8250
  case 0:
@@ -8081,28 +8254,38 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8081
8254
  }
8082
8255
 
8083
8256
  {
8084
- VALUE hash = date_s__xmlschema(klass, str);
8257
+ int argc2 = 1;
8258
+ VALUE argv2[2];
8259
+ argv2[0] = str;
8260
+ argv2[1] = opt;
8261
+ if (!NIL_P(opt)) argc2++;
8262
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
8085
8263
  return dt_new_by_frags(klass, hash, sg);
8086
8264
  }
8087
8265
  }
8088
8266
 
8089
8267
  /*
8090
8268
  * 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
8269
+ * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8270
+ * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8093
8271
  *
8094
8272
  * Creates a new DateTime object by parsing from a string according to
8095
8273
  * some typical RFC 2822 formats.
8096
8274
  *
8097
8275
  * DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700')
8098
8276
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8277
+ *
8278
+ * Raise an ArgumentError when the string length is longer than _limit_.
8279
+ * You can stop this check by passing `limit: nil`, but note that
8280
+ * it may take a long time to parse.
8099
8281
  */
8100
8282
  static VALUE
8101
8283
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8102
8284
  {
8103
- VALUE str, sg;
8285
+ VALUE str, sg, opt;
8104
8286
 
8105
- rb_scan_args(argc, argv, "02", &str, &sg);
8287
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8288
+ if (!NIL_P(opt)) argc--;
8106
8289
 
8107
8290
  switch (argc) {
8108
8291
  case 0:
@@ -8112,7 +8295,12 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8112
8295
  }
8113
8296
 
8114
8297
  {
8115
- VALUE hash = date_s__rfc2822(klass, str);
8298
+ int argc2 = 1;
8299
+ VALUE argv2[2];
8300
+ argv2[0] = str;
8301
+ argv2[1] = opt;
8302
+ if (!NIL_P(opt)) argc2++;
8303
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
8116
8304
  return dt_new_by_frags(klass, hash, sg);
8117
8305
  }
8118
8306
  }
@@ -8126,13 +8314,18 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8126
8314
  *
8127
8315
  * DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
8128
8316
  * #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
8317
+ *
8318
+ * Raise an ArgumentError when the string length is longer than _limit_.
8319
+ * You can stop this check by passing `limit: nil`, but note that
8320
+ * it may take a long time to parse.
8129
8321
  */
8130
8322
  static VALUE
8131
8323
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8132
8324
  {
8133
- VALUE str, sg;
8325
+ VALUE str, sg, opt;
8134
8326
 
8135
- rb_scan_args(argc, argv, "02", &str, &sg);
8327
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8328
+ if (!NIL_P(opt)) argc--;
8136
8329
 
8137
8330
  switch (argc) {
8138
8331
  case 0:
@@ -8142,27 +8335,37 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8142
8335
  }
8143
8336
 
8144
8337
  {
8145
- VALUE hash = date_s__httpdate(klass, str);
8338
+ int argc2 = 1;
8339
+ VALUE argv2[2];
8340
+ argv2[0] = str;
8341
+ argv2[1] = opt;
8342
+ if (!NIL_P(opt)) argc2++;
8343
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
8146
8344
  return dt_new_by_frags(klass, hash, sg);
8147
8345
  }
8148
8346
  }
8149
8347
 
8150
8348
  /*
8151
8349
  * call-seq:
8152
- * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8350
+ * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8153
8351
  *
8154
8352
  * Creates a new DateTime object by parsing from a string according to
8155
8353
  * some typical JIS X 0301 formats.
8156
8354
  *
8157
8355
  * DateTime.jisx0301('H13.02.03T04:05:06+07:00')
8158
8356
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8357
+ *
8358
+ * Raise an ArgumentError when the string length is longer than _limit_.
8359
+ * You can stop this check by passing `limit: nil`, but note that
8360
+ * it may take a long time to parse.
8159
8361
  */
8160
8362
  static VALUE
8161
8363
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8162
8364
  {
8163
- VALUE str, sg;
8365
+ VALUE str, sg, opt;
8164
8366
 
8165
- rb_scan_args(argc, argv, "02", &str, &sg);
8367
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8368
+ if (!NIL_P(opt)) argc--;
8166
8369
 
8167
8370
  switch (argc) {
8168
8371
  case 0:
@@ -8172,7 +8375,12 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8172
8375
  }
8173
8376
 
8174
8377
  {
8175
- VALUE hash = date_s__jisx0301(klass, str);
8378
+ int argc2 = 1;
8379
+ VALUE argv2[2];
8380
+ argv2[0] = str;
8381
+ argv2[1] = opt;
8382
+ if (!NIL_P(opt)) argc2++;
8383
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
8176
8384
  return dt_new_by_frags(klass, hash, sg);
8177
8385
  }
8178
8386
  }
@@ -9323,19 +9531,19 @@ Init_date_core(void)
9323
9531
  rb_define_singleton_method(cDate, "strptime", date_s_strptime, -1);
9324
9532
  rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
9325
9533
  rb_define_singleton_method(cDate, "parse", date_s_parse, -1);
9326
- rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, 1);
9534
+ rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, -1);
9327
9535
  rb_define_singleton_method(cDate, "iso8601", date_s_iso8601, -1);
9328
- rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, 1);
9536
+ rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, -1);
9329
9537
  rb_define_singleton_method(cDate, "rfc3339", date_s_rfc3339, -1);
9330
- rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, 1);
9538
+ rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, -1);
9331
9539
  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);
9540
+ rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, -1);
9541
+ rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, -1);
9334
9542
  rb_define_singleton_method(cDate, "rfc2822", date_s_rfc2822, -1);
9335
9543
  rb_define_singleton_method(cDate, "rfc822", date_s_rfc2822, -1);
9336
- rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, 1);
9544
+ rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, -1);
9337
9545
  rb_define_singleton_method(cDate, "httpdate", date_s_httpdate, -1);
9338
- rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
9546
+ rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, -1);
9339
9547
  rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
9340
9548
 
9341
9549
  rb_define_method(cDate, "initialize", date_initialize, -1);
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.1
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-15 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.1.4
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: A subclass of Object includes Comparable module for handling dates.