Sha256: aa7b1b4ee6563c60076377123bbc93ee6500f3ae20e5d737ad49374ba4434706

Contents?: true

Size: 1.12 KB

Versions: 102

Compression:

Stored size: 1.12 KB

Contents

module SafeYAML
  class Parse
    class Date
      # This one's easy enough :)
      DATE_MATCHER = /\A(\d{4})-(\d{2})-(\d{2})\Z/.freeze

      # This unbelievable little gem is taken basically straight from the YAML spec, but made
      # slightly more readable (to my poor eyes at least) to me:
      # http://yaml.org/type/timestamp.html
      TIME_MATCHER = /\A\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d{2}:\d{2}(?:\.\d*)?\s*(?:Z|[-+]\d{1,2}(?::?\d{2})?)?\Z/.freeze

      SECONDS_PER_DAY = 60 * 60 * 24
      MICROSECONDS_PER_SECOND = 1000000

      # So this is weird. In Ruby 1.8.7, the DateTime#sec_fraction method returned fractional
      # seconds in units of DAYS for some reason. In 1.9.2, they changed the units -- much more
      # reasonably -- to seconds.
      SEC_FRACTION_MULTIPLIER = RUBY_VERSION == "1.8.7" ? (SECONDS_PER_DAY * MICROSECONDS_PER_SECOND) : MICROSECONDS_PER_SECOND

      def self.value(value)
        d = DateTime.parse(value)
        usec = d.sec_fraction * SEC_FRACTION_MULTIPLIER
        Time.utc(d.year, d.month, d.day, d.hour, d.min, d.sec, usec) - (d.offset * SECONDS_PER_DAY)
      end
    end
  end
end

Version data entries

102 entries across 102 versions & 3 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.7 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.7-x86-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.7-x64-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.6 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.6-x86-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.6-x64-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.5 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.5-x86-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.5-x64-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.4 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.4-x86-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-3.8.4-x64-mingw32 lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb