From f53ff535f737e36d3943472a594b387a36f16fa6 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sun, 6 Oct 2019 20:01:14 +0100 Subject: [PATCH] Add a convenience method for creating DOSTime instances. DOSTime::from_time creates a DOSTime instance from a vanilla Time instance. --- lib/zip/dos_time.rb | 5 +++++ lib/zip/entry.rb | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/zip/dos_time.rb b/lib/zip/dos_time.rb index bf0cb7e0..c912b773 100644 --- a/lib/zip/dos_time.rb +++ b/lib/zip/dos_time.rb @@ -29,6 +29,11 @@ def dos_equals(other) to_i / 2 == other.to_i / 2 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) second = 2 * (0b11111 & binaryDosTime) minute = (0b11111100000 & binaryDosTime) >> 5 diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 815986c0..7066c0a4 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -406,9 +406,7 @@ def get_extra_attributes_from_path(path) # :nodoc: @unix_uid = stat.uid @unix_gid = stat.gid @unix_perms = stat.mode & 0o7777 - - mtime = stat.mtime - @time = ::Zip::DOSTime.local(mtime.year, mtime.month, mtime.day, mtime.hour, mtime.min, mtime.sec) + @time = ::Zip::DOSTime.from_time(stat.mtime) end def set_unix_attributes_on_path(dest_path)