Class: SafeYAML::Parse::Date

### Home Classes Methods

### In Files

- lib/safe_yaml/parse/date.rb

### Parent

Object

### Methods

- ::value

### Class/Module Index

Quicksearch

- SafeYAML
- SafeYAML::Deep
- SafeYAML::LibyamlChecker
- SafeYAML::Parse
- SafeYAML::Parse::Date
- SafeYAML::Parse::Hexadecimal
- SafeYAML::Parse::Sexagesimal
- SafeYAML::PsychHandler
- SafeYAML::PsychResolver
- SafeYAML::Resolver
- SafeYAML::SafeToRubyVisitor
- SafeYAML::SyckResolver
- SafeYAML::Transform
- SafeYAML::Transform::ToBoolean
- SafeYAML::Transform::ToDate
- SafeYAML::Transform::ToFloat
- SafeYAML::Transform::ToInteger
- SafeYAML::Transform::ToNil
- SafeYAML::Transform::ToSymbol
- SafeYAML::Transform::TransformationMap
- SafeYAML::Transform::TransformationMap::CaseAgnosticMap
- SafeYAML::Transform::TransformationMap::ClassMethods
- Object
- YAML

No matching classes.

# SafeYAML::Parse::Date

### Constants

DATE_MATCHER

  This one's easy enough :)

MICROSECONDS_PER_SECOND
SECONDS_PER_DAY
SEC_FRACTION_MULTIPLIER

  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.

TIME_MATCHER

  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: yaml.org/type/timestamp.html

TO_TIME_AVAILABLE

  The DateTime class has a to_time method in Ruby 1.9+; Before that we'll just need to convert DateTime to Time ourselves.

### Public Class Methods

value(value) click to toggle source

    # File lib/safe_yaml/parse/date.rb, line 24
    def self.value(value)
      d = DateTime.parse(value)

      return d.to_time if TO_TIME_AVAILABLE

      usec = d.sec_fraction * SEC_FRACTION_MULTIPLIER
      time = Time.utc(d.year, d.month, d.day, d.hour, d.min, d.sec, usec) - (d.offset * SECONDS_PER_DAY)
      time.getlocal
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.