Parent

Time

Public Class Methods

yaml_new( klass, tag, val ) click to toggle source
 
               # File syck/lib/syck/rubytypes.rb, line 315
def Time.yaml_new( klass, tag, val )
    if Hash === val
        t = val.delete( 'at' )
        val.each { |k,v| t.instance_variable_set( k, v ) }
        t
    else
        raise YAML::TypeError, "Invalid Time: " + val.inspect
    end
end
            

Public Instance Methods

to_yaml( opts = {} ) click to toggle source
 
               # File syck/lib/syck/rubytypes.rb, line 324
def to_yaml( opts = {} )
return super unless YAML::ENGINE.syck?
        YAML::quick_emit( self, opts ) do |out|
    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]
    if to_yaml_properties.empty?
        out.scalar( taguri, standard, :plain )
    else
        out.map( taguri, to_yaml_style ) do |map|
            map.add( 'at', standard )
            to_yaml_properties.each do |m|
                map.add( m, instance_variable_get( m ) )
            end
        end
    end
end
end
            

Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.

If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file a bug report so that it can be corrected for the next release. Thank you.

blog comments powered by Disqus