Class: Time

Inherits:
Object show all
Defined in:
lib/rbyaml/rubytypes.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.yaml_new(klass, tag, val) ⇒ Object



292
293
294
295
296
297
298
299
300
# File 'lib/rbyaml/rubytypes.rb', line 292

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 RbYAML::TypeError, "Invalid Time: " + val.inspect
  end
end

Instance Method Details

#is_complex_yaml?Boolean

Returns:

  • (Boolean)


291
# File 'lib/rbyaml/rubytypes.rb', line 291

def is_complex_yaml?; false; end

#to_yaml_node(repre) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/rbyaml/rubytypes.rb', line 301

def to_yaml_node(repre)
  RbYAML::quick_emit_node( object_id, repre ) do |out|
    tz = "Z"
    # from the tidy Tobias Peters <[email protected]> Thanks!
    unless utc?
      utc_same_instant = 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 = strftime( "%Y-%m-%d %H:%M:%S" )
    standard += ".%06d" % [usec] if usec.nonzero?
    standard += " %s" % [tz]
    out.scalar(taguri, standard, nil)
  end
end