Class: Zip::DOSTime
Overview
:nodoc:all
Defined Under Namespace
Modules: JRubyCMP
Instance Attribute Summary collapse
-
#absolute_time ⇒ Object
writeonly
Register DX, the Date: Bits 0-4 day (1-31) bits 5-8 month (1-12) bits 9-15 year (four digit year minus 1980).
Class Method Summary collapse
-
.from_time(time) ⇒ Object
Create a DOSTime instance from a vanilla Time instance.
- .parse_binary_dos_format(bin_dos_date, bin_dos_time) ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Dos time is only stored with two seconds accuracy.
- #absolute_time? ⇒ Boolean
- #dos_equals(other) ⇒ Object
- #to_binary_dos_date ⇒ Object
- #to_binary_dos_time ⇒ Object
Methods included from JRubyCMP
Instance Attribute Details
#absolute_time=(value) ⇒ Object (writeonly)
Register DX, the Date: Bits 0-4 day (1-31) bits 5-8 month (1-12) bits 9-15 year (four digit year minus 1980)
19 20 21 |
# File 'lib/zip/dos_time.rb', line 19 def absolute_time=(value) @absolute_time = value end |
Class Method Details
.from_time(time) ⇒ Object
Create a DOSTime instance from a vanilla Time instance.
52 53 54 |
# File 'lib/zip/dos_time.rb', line 52 def self.from_time(time) local(time.year, time.month, time.day, time.hour, time.min, time.sec) end |
.parse_binary_dos_format(bin_dos_date, bin_dos_time) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/zip/dos_time.rb', line 56 def self.parse_binary_dos_format(bin_dos_date, bin_dos_time) second = 2 * (0b11111 & bin_dos_time) minute = (0b11111100000 & bin_dos_time) >> 5 hour = (0b1111100000000000 & bin_dos_time) >> 11 day = (0b11111 & bin_dos_date) month = (0b111100000 & bin_dos_date) >> 5 year = ((0b1111111000000000 & bin_dos_date) >> 9) + 1980 time = local(year, month, day, hour, minute, second) time.absolute_time = false time end |
Instance Method Details
#<=>(other) ⇒ Object
Dos time is only stored with two seconds accuracy.
45 46 47 48 49 |
# File 'lib/zip/dos_time.rb', line 45 def <=>(other) return unless other.kind_of?(Time) (to_i / 2) <=> (other.to_i / 2) end |
#absolute_time? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/zip/dos_time.rb', line 21 def absolute_time? # If absolute time is not set, we can assume it is an absolute time # because times do have timezone information by default. @absolute_time.nil? ? true : @absolute_time end |
#dos_equals(other) ⇒ Object
39 40 41 42 |
# File 'lib/zip/dos_time.rb', line 39 def dos_equals(other) warn 'Zip::DOSTime#dos_equals is deprecated. Use `==` instead.' self == other end |
#to_binary_dos_date ⇒ Object
33 34 35 36 37 |
# File 'lib/zip/dos_time.rb', line 33 def to_binary_dos_date day + (month << 5) + ((year - 1980) << 9) end |
#to_binary_dos_time ⇒ Object
27 28 29 30 31 |
# File 'lib/zip/dos_time.rb', line 27 def to_binary_dos_time (sec / 2) + (min << 5) + (hour << 11) end |