Add a convenience method for creating DOSTime instances.

DOSTime::from_time creates a DOSTime instance from a vanilla Time
instance.
This commit is contained in:
Robert Haines 2019-10-06 20:01:14 +01:00
parent 8c694d38ee
commit 2bdd37d894
2 changed files with 6 additions and 3 deletions

View File

@ -29,6 +29,11 @@ module Zip
to_i / 2 == other.to_i / 2 to_i / 2 == other.to_i / 2
end end
# Create a DOSTime instance from a vanilla Time instance.
def self.from_time(time)
local(time.year, time.month, time.day, time.hour, time.min, time.sec)
end
def self.parse_binary_dos_format(binaryDosDate, binaryDosTime) def self.parse_binary_dos_format(binaryDosDate, binaryDosTime)
second = 2 * (0b11111 & binaryDosTime) second = 2 * (0b11111 & binaryDosTime)
minute = (0b11111100000 & binaryDosTime) >> 5 minute = (0b11111100000 & binaryDosTime) >> 5

View File

@ -406,9 +406,7 @@ module Zip
@unix_uid = stat.uid @unix_uid = stat.uid
@unix_gid = stat.gid @unix_gid = stat.gid
@unix_perms = stat.mode & 0o7777 @unix_perms = stat.mode & 0o7777
@time = ::Zip::DOSTime.from_time(stat.mtime)
mtime = stat.mtime
@time = ::Zip::DOSTime.local(mtime.year, mtime.month, mtime.day, mtime.hour, mtime.min, mtime.sec)
end end
def set_unix_attributes_on_path(dest_path) def set_unix_attributes_on_path(dest_path)