Class: Time

Inherits:
Object show all
Defined in:
lib/amp/dependencies/zip/stdrubyext.rb,
lib/amp/support/support.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_binary_dos_format(binaryDosDate, binaryDosTime) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/amp/dependencies/zip/stdrubyext.rb', line 85

def self.parse_binary_dos_format(binaryDosDate, binaryDosTime)
  second = 2 * (       0b11111 & binaryDosTime)
  minute = (     0b11111100000 & binaryDosTime) >> 5 
  hour   = (0b1111100000000000 & binaryDosTime) >> 11
  day    = (           0b11111 & binaryDosDate) 
  month  = (       0b111100000 & binaryDosDate) >> 5
  year   = ((0b1111111000000000 & binaryDosDate) >> 9) + 1980
  begin
    return Time.local(year, month, day, hour, minute, second)
  end
end

Instance Method Details

#date_str(offset = 0, format = "%a %b %d %H:%M:%S %Y %1%2") ⇒ Object

Returns a nifty date stamp for certain diff types. not used yet.



856
857
858
859
860
861
862
863
864
865
# File 'lib/amp/support/support.rb', line 856

def date_str(offset=0, format="%a %b %d %H:%M:%S %Y %1%2")
  t, tz = self, offset
  if format =~ /%1/ || format =~ /%2/
    sign = (tz > 0) ? "-" : "+"
    minutes = tz.abs / 60
    format.gsub!(/%1/, "#{sign}#{(minutes / 60).to_s.rjust(2,'0')}")
    format.gsub!(/%2/, "#{(minutes % 60).to_s.rjust(2,'0')}")
  end
  (self - tz).gmtime.strftime(format)
end

#dos_equals(other) ⇒ Object

Dos time is only stored with two seconds accuracy



81
82
83
# File 'lib/amp/dependencies/zip/stdrubyext.rb', line 81

def dos_equals(other)
  to_i/2 == other.to_i/2
end

#to_binary_dos_dateObject



74
75
76
77
78
# File 'lib/amp/dependencies/zip/stdrubyext.rb', line 74

def to_binary_dos_date
  (day) +
    (month << 5) +
    ((year - 1980) << 9)
end

#to_binary_dos_timeObject



68
69
70
71
72
# File 'lib/amp/dependencies/zip/stdrubyext.rb', line 68

def to_binary_dos_time
  (sec/2) +
    (min  << 5) +
    (hour << 11)
end

#to_diffString

Returns the date in a format suitable for unified diffs.

Returns:

  • (String)

    diff format: 2009-03-28 18:45:12.541298



851
852
853
# File 'lib/amp/support/support.rb', line 851

def to_diff
  strftime("%Y-%m-%d %H:%M:%S.#{usec}")
end