Class: Archive::Zip::DOSTime
- Inherits:
-
Object
- Object
- Archive::Zip::DOSTime
- Includes:
- Comparable
- Defined in:
- lib/archive/zip/dos_time.rb
Overview
instances of Time.
Instance Method Summary collapse
-
#cmp(other) ⇒ Object
(also: #<=>)
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.
-
#initialize(time = nil) ⇒ DOSTime
constructor
Creates a new instance of DOSTime.
-
#to_i ⇒ Object
Returns the time value of this object as an integer representing the DOS time structure.
-
#to_time ⇒ Object
Returns a Time instance which is equivalent to the time represented by this object.
Constructor Details
#initialize(time = nil) ⇒ DOSTime
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.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/archive/zip/dos_time.rb', line 20 def initialize(time = nil) @dos_time = case time when nil from_time(Time.now) when Time from_time(time) else time end validate end |
Instance Method Details
#cmp(other) ⇒ Object Also known as: <=>
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.
35 36 37 38 |
# File 'lib/archive/zip/dos_time.rb', line 35 def cmp(other) raise ArgumentError, 'other must be a DOSTime' unless DOSTime === other to_i <=> other.to_i end |
#to_i ⇒ Object
Returns the time value of this object as an integer representing the DOS time structure.
43 44 45 |
# File 'lib/archive/zip/dos_time.rb', line 43 def to_i @dos_time end |
#to_time ⇒ Object
Returns a Time instance which is equivalent to the time represented by this object.
49 50 51 52 53 54 55 56 57 |
# File 'lib/archive/zip/dos_time.rb', line 49 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 |