Creates a new instance of DOSTime. dos_time is a 4 byte String or unsigned number (Integer) representing an MS-DOS time structure where:
Bits 0-4 |
2 second increments (0-29) |
Bits 5-10 |
minutes (0-59) |
Bits 11-15 |
hours (0-24) |
Bits 16-20 |
day (1-31) |
Bits 21-24 |
month (1-12) |
Bits 25-31 |
four digit year minus 1980 (0-119) |
If dos_time is ommitted or nil, a new instance is created based on the current time.
# File lib/archive/support/time.rb, line 44 def initialize(dos_time = nil) case dos_time when nil @dos_time = Time.now.to_dos_time.dos_time when Integer @dos_time = dos_time else unless dos_time.length == 4 then raise ArgumentError, 'length of DOS time structure is not 4' end @dos_time = dos_time.unpack('V')[0] end end
Returns -1 if other is a time earlier than this one, 0 if other is the same time, and 1 if other is a later time.
# File lib/archive/support/time.rb, line 60 def cmp(other) to_i <=> other.to_i end
Returns the 32 bit integer that backs this object packed into a String in little endian format. This is suitable for use with new.
# File lib/archive/support/time.rb, line 73 def pack [to_i].pack('V') end
Returns the time value of this object as an integer representing the DOS time structure.
# File lib/archive/support/time.rb, line 67 def to_i @dos_time end
Returns a Time instance which is equivalent to the time represented by this object.
# File lib/archive/support/time.rb, line 79 def to_time second = ((0b11111 & @dos_time) ) * 2 minute = ((0b111111 << 5 & @dos_time) >> 5) hour = ((0b11111 << 11 & @dos_time) >> 11) day = ((0b11111 << 16 & @dos_time) >> 16) month = ((0b1111 << 21 & @dos_time) >> 21) year = ((0b1111111 << 25 & @dos_time) >> 25) + 1980 return Time.local(year, month, day, hour, minute, second) end
Generated with the Darkfish Rdoc Generator 2.