Add `Entry#absolute_time?`.

This method returns `true` if an entry has timezone information in its
timestamps, `false` otherwise.
This commit is contained in:
Robert Haines 2024-03-07 21:31:24 +00:00
parent 8afc2514f7
commit d53f046bc7
2 changed files with 13 additions and 0 deletions

View File

@ -176,6 +176,11 @@ module Zip
send(:time=, value, component: :ctime) send(:time=, value, component: :ctime)
end end
# Does this entry return time fields with accurate timezone information?
def absolute_time?
@extra.member?('UniversalTime') || @extra.member?('NTFS')
end
# Return the compression method for this entry. # Return the compression method for this entry.
# #
# Returns STORED if the entry is a directory or if the compression # Returns STORED if the entry is a directory or if the compression

View File

@ -340,4 +340,12 @@ class ZipEntryTest < MiniTest::Test
entry.gather_fileinfo_from_srcpath('test/data/mimetype') entry.gather_fileinfo_from_srcpath('test/data/mimetype')
assert_equal(entry.time, File.stat('test/data/mimetype').mtime) assert_equal(entry.time, File.stat('test/data/mimetype').mtime)
end end
def test_absolute_time
entry = ::Zip::Entry.new
refute(entry.absolute_time?)
entry.time = Time.now
assert(entry.absolute_time?)
end
end end