Class: Zip::DOSTime

Inherits:
Time
  • Object
show all
Includes:
JRubyCMP
Defined in:
lib/zip/dos_time.rb

Overview

:nodoc:all

Defined Under Namespace

Modules: JRubyCMP

Constant Summary collapse

DOS_EPOCH_YEAR =

The MS-DOS date field is seven bits of "year minus 1980", so only 1980-01-01 00:00:00 through 2107-12-31 23:59:58 can be represented. Times outside that are clamped rather than allowed to wrap: the real time is still carried in the universal time (UT) extra field, but the DOS fields have to stay in range for readers that only look at those.

1980
DOS_MAX_YEAR =
2107
DOS_MIN_DATE =

1980-01-01

0x0021
DOS_MAX_DATE =

2107-12-31

0xff9f
DOS_MIN_TIME =

00:00:00

0x0000
DOS_MAX_TIME =

23:59:58

0xbf7d

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JRubyCMP

#<, #<=, #==, #>, #>=

Instance Attribute Details

#absolute_time=(value) ⇒ Object (writeonly)

:nodoc:



31
32
33
# File 'lib/zip/dos_time.rb', line 31

def absolute_time=(value)
  @absolute_time = value
end

Class Method Details

.from_time(time) ⇒ Object

Create a DOSTime instance from a vanilla Time instance.



71
72
73
# File 'lib/zip/dos_time.rb', line 71

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



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/zip/dos_time.rb', line 75

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.



64
65
66
67
68
# File 'lib/zip/dos_time.rb', line 64

def <=>(other)
  return unless other.kind_of?(Time)

  (to_i / 2) <=> (other.to_i / 2)
end

#absolute_time?Boolean

Returns:



33
34
35
36
37
# File 'lib/zip/dos_time.rb', line 33

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? || @absolute_time
end

#dos_equals(other) ⇒ Object

Deprecated. Remove for version 4.



58
59
60
61
# File 'lib/zip/dos_time.rb', line 58

def dos_equals(other) # rubocop:disable Naming/PredicateMethod
  warn 'Zip::DOSTime#dos_equals is deprecated. Use `==` instead.'
  self == other
end

#to_binary_dos_dateObject



48
49
50
51
52
53
54
55
# File 'lib/zip/dos_time.rb', line 48

def to_binary_dos_date
  return DOS_MIN_DATE if year < DOS_EPOCH_YEAR
  return DOS_MAX_DATE if year > DOS_MAX_YEAR

  day +
    (month << 5) +
    ((year - DOS_EPOCH_YEAR) << 9)
end

#to_binary_dos_timeObject



39
40
41
42
43
44
45
46
# File 'lib/zip/dos_time.rb', line 39

def to_binary_dos_time
  return DOS_MIN_TIME if year < DOS_EPOCH_YEAR
  return DOS_MAX_TIME if year > DOS_MAX_YEAR

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