time 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/time.rb +56 -9
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc9964ca1d565e8395c46c83ffcf74b0a69ba3655dae9869a1a90f349b8d6586
4
- data.tar.gz: c7500638e2132c8d5ed66243bea7d3e93f52933ecd504e159385a788e4682bc2
3
+ metadata.gz: 6ad6ef6fa9d67bc974c6b57e3885ddbf4950f1467be228eee70a9104f905a5ec
4
+ data.tar.gz: de3739295b2c8923b7e76b1a895235052dcb4b49a3fff8725aede781568cbea3
5
5
  SHA512:
6
- metadata.gz: 28c4cdaa51d8060a1ba0282fbe6d49e5f1b7574e693631fe2fd038503bc26a1e95004e8e931a908bdd3b8af11e7018307541e40163d62898422319d07ff40c02
7
- data.tar.gz: 68b674ba7b85e2f7a2bb731bf89f515b81fcda6a5dd3501e8f1debb9bda574a530c6941fce013179ea54d91e8ddbf53ab1e7c1312226098bc17a10cb9a57bee5
6
+ metadata.gz: afdc920a6bb5caf7081e7d3019a0162559f9ed8fce7bd884c0c83f51caa88647d78ef0b1588fc1691f209aebae5a306341e2a155ed56a6a18005e191a52f5b56
7
+ data.tar.gz: cb6f69028390588f8986d32e4d3c9322fc5cd3ef96e5c161415d46562b6179158c9efb8490b920c59e4adcb3ccae16866ab370b8b15c2fc5b92540d1033a48b7
data/lib/time.rb CHANGED
@@ -27,7 +27,7 @@ require 'date'
27
27
  # #
28
28
  class Time
29
29
 
30
- VERSION = "0.4.2" # :nodoc:
30
+ VERSION = "0.5.0" # :nodoc:
31
31
 
32
32
  class << Time
33
33
 
@@ -369,6 +369,9 @@ class Time
369
369
  # If the extracted time zone abbreviation does not match any of them,
370
370
  # it is ignored and the given time is regarded as a local time.
371
371
  #
372
+ # A +zone+ argument can be provided to specify the zone for the given
373
+ # +date+, if the +date+ does not include a time zone or offset.
374
+ #
372
375
  # ArgumentError is raised if Date._parse cannot extract information from
373
376
  # +date+ or if the Time class cannot represent specified date.
374
377
  #
@@ -382,12 +385,12 @@ class Time
382
385
  #
383
386
  # You must require 'time' to use this method.
384
387
  #
385
- def parse(date, now=self.now)
388
+ def parse(date, now=self.now, zone: nil)
386
389
  comp = !block_given?
387
390
  d = Date._parse(date, comp)
388
391
  year = d[:year]
389
392
  year = yield(year) if year && !comp
390
- make_time(date, year, d[:yday], d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
393
+ make_time(date, year, d[:yday], d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone] || zone, now)
391
394
  end
392
395
 
393
396
  #
@@ -507,7 +510,7 @@ class Time
507
510
  # require 'time'
508
511
  #
509
512
  # Time.rfc2822("Wed, 05 Oct 2011 22:26:12 -0400")
510
- # #=> 2010-10-05 22:26:12 -0400
513
+ # #=> 2011-10-05 22:26:12 -0400
511
514
  #
512
515
  # You must require 'time' to use this method.
513
516
  #
@@ -624,13 +627,58 @@ class Time
624
627
  # You must require 'time' to use this method.
625
628
  #
626
629
  def xmlschema(time)
627
- if /\A\s*
630
+ pattern = /\A\s*
628
631
  (-?\d+)-(\d\d)-(\d\d)
629
632
  T
630
633
  (\d\d):(\d\d):(\d\d)
631
634
  (\.\d+)?
632
635
  (Z|[+-]\d\d(?::?\d\d)?)?
633
- \s*\z/ix =~ time
636
+ \s*\z/ix
637
+ _xmlschema(pattern, time) or
638
+ raise ArgumentError.new("invalid xmlschema format: #{time.inspect}")
639
+ end
640
+ alias iso8601 xmlschema
641
+
642
+ #
643
+ # Parses +time+ as a dateTime defined by RFC3339 and converts it to
644
+ # a Time object.
645
+ #
646
+ # ArgumentError is raised if +time+ is not compliant with the format or if
647
+ # the Time class cannot represent the specified time.
648
+ #
649
+ # See #xmlschema for more information on this format.
650
+ #
651
+ # require 'time'
652
+ #
653
+ # Time.rfc3339("2011-10-05T22:26:12-04:00")
654
+ # #=> 2011-10-05 22:26:12-04:00
655
+ #
656
+ # You must require 'time' to use this method.
657
+ #
658
+ def rfc3339(time)
659
+ pattern = /\A\s*
660
+ (-?\d{4})-(\d\d)-(\d\d)
661
+ [T ]
662
+ (\d\d):(\d\d):(\d\d)
663
+ (\.\d+)?
664
+ (Z|[+-]\d\d:\d\d)
665
+ \s*\z/ix
666
+ _xmlschema(pattern, time) or
667
+ raise ArgumentError.new("invalid rfc3339 format: #{time.inspect}")
668
+ end
669
+
670
+ private
671
+
672
+ if RUBY_VERSION >= "3.2"
673
+ def _xmlschema(pattern, time) # :nodoc:
674
+ return unless pattern.match?(time)
675
+ time = time.strip
676
+ time.upcase!
677
+ new(time)
678
+ end
679
+ else
680
+ def _xmlschema(pattern, time) # :nodoc:
681
+ return unless pattern =~ time
634
682
  year = $1.to_i
635
683
  mon = $2.to_i
636
684
  day = $3.to_i
@@ -652,11 +700,9 @@ class Time
652
700
  else
653
701
  self.local(year, mon, day, hour, min, sec, usec)
654
702
  end
655
- else
656
- raise ArgumentError.new("invalid xmlschema format: #{time.inspect}")
657
703
  end
658
704
  end
659
- alias iso8601 xmlschema
705
+
660
706
  end # class << self
661
707
 
662
708
  #
@@ -731,4 +777,5 @@ class Time
731
777
  end
732
778
  end
733
779
  alias iso8601 xmlschema unless method_defined?(:iso8601)
780
+ alias rfc3339 xmlschema
734
781
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-12-17 00:00:00.000000000 Z
10
+ date: 2026-10-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: date
@@ -43,6 +43,7 @@ licenses:
43
43
  metadata:
44
44
  homepage_uri: https://github.com/ruby/time
45
45
  source_code_uri: https://github.com/ruby/time
46
+ changelog_uri: https://github.com/ruby/time/releases
46
47
  rdoc_options: []
47
48
  require_paths:
48
49
  - lib