Skip to content

Commit

Permalink
Add a convenience method for creating DOSTime instances.
Browse files Browse the repository at this point in the history
DOSTime::from_time creates a DOSTime instance from a vanilla Time
instance.
  • Loading branch information
hainesr committed Oct 6, 2019
1 parent 71987f1 commit dbbb6cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/zip/dos_time.rb
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/zip/entry.rb
Expand Up @@ -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)
Expand Down

0 comments on commit dbbb6cf

Please sign in to comment.