Time (Class)

In: yaml/rubytypes.rb
Parent: Object

Emit a Time object as an ISO 8601 timestamp

Methods

Public Instance methods

[Source]

# File yaml/rubytypes.rb, line 509
    def is_complex_yaml?
        self.class != Time or not to_yaml_properties.empty?
    end

[Source]

# File yaml/rubytypes.rb, line 515
        def to_yaml( opts = {} )
                YAML::quick_emit( nil, opts ) { |out|
            if self.is_complex_yaml?
                out.map( self.to_yaml_type ) { |map|
                    map.add( 'at', ::Time.at( self ) )
                    to_yaml_properties.each { |m|
                        map.add( m, instance_variable_get( m ) )
                    }
                }
            else
                tz = "Z"
                # from the tidy Tobias Peters <t-peters@gmx.de> Thanks!

                unless self.utc?
                    utc_same_instant = self.dup.utc
                    utc_same_writing = Time.utc(year,month,day,hour,min,sec,usec)
                    difference_to_utc = utc_same_writing - utc_same_instant
                    if (difference_to_utc < 0) 
                        difference_sign = '-'
                        absolute_difference = -difference_to_utc
                    else
                        difference_sign = '+'
                        absolute_difference = difference_to_utc
                    end
                    difference_minutes = (absolute_difference/60).round
                    tz = "%s%02d:%02d" % [ difference_sign, difference_minutes / 60, difference_minutes % 60]
                end
                standard = self.strftime( "%Y-%m-%d %H:%M:%S" )
                standard += ".%06d" % [usec] if usec.nonzero?
                standard += " %s" % [tz]
                standard.to_yaml( :Emitter => out, :KeepValue => true )
            end
                }
        end

[Source]

# File yaml/rubytypes.rb, line 512
    def to_yaml_type
        "!ruby/time#{ if self.class != ::Time; ":#{ self.class }"; end }"
    end

[Validate]