Merge pull request #464 from hainesr/remove_dosequals

Replace and deprecate `Zip::DOSTime#dos_equals`.
This commit is contained in:
Oleksandr Simonov 2021-05-03 10:22:13 +03:00 committed by GitHub
commit 7f3bb29487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -24,9 +24,14 @@ module Zip
((year - 1980) << 9)
end
# Dos time is only stored with two seconds accuracy
def dos_equals(other)
to_i / 2 == other.to_i / 2
warn 'Zip::DOSTime#dos_equals is deprecated. Use `==` instead.'
self == other
end
# Dos time is only stored with two seconds accuracy.
def <=>(other)
(to_i / 2) <=> (other.to_i / 2)
end
# Create a DOSTime instance from a vanilla Time instance.

View File

@ -530,10 +530,9 @@ module Zip
return false unless other.class == self.class
# Compares contents of local entry and exposed fields
keys_equal = %w[compression_method crc compressed_size size name extra filepath].all? do |k|
%w[compression_method crc compressed_size size name extra filepath time].all? do |k|
other.__send__(k.to_sym) == __send__(k.to_sym)
end
keys_equal && time.dos_equals(other.time)
end
def <=>(other)

View File

@ -102,7 +102,7 @@ class ZipOutputStreamTest < MiniTest::Test
::Zip::InputStream.open(TEST_ZIP.zip_name) do |io|
while (entry = io.get_next_entry)
# Compare DOS Times, since they are stored with two seconds accuracy
assert(::Zip::DOSTime.at(file.mtime).dos_equals(::Zip::DOSTime.at(entry.mtime)))
assert(::Zip::DOSTime.at(file.mtime) == ::Zip::DOSTime.at(entry.mtime))
end
end
end