diff --git a/lib/zip/dos_time.rb b/lib/zip/dos_time.rb index 1d77aa4..326645a 100644 --- a/lib/zip/dos_time.rb +++ b/lib/zip/dos_time.rb @@ -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. diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 2988b26..e6875e3 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -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) diff --git a/test/output_stream_test.rb b/test/output_stream_test.rb index c89cbbc..7384674 100644 --- a/test/output_stream_test.rb +++ b/test/output_stream_test.rb @@ -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