diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-08-11 18:59:38 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-08-11 18:59:38 -0400 |
commit | 91b423d3bb726c5ab30dbd24b50d4414aac3af41 (patch) | |
tree | 92ee11c0163a63381fd3031f5672deb6bd6662df /src | |
parent | 36f59f798104e3f01c4f3815401d809809e4859c (diff) | |
download | zip-crystal-91b423d3bb726c5ab30dbd24b50d4414aac3af41.tar.bz2 zip-crystal-91b423d3bb726c5ab30dbd24b50d4414aac3af41.zip |
move timehelper down
Diffstat (limited to 'src')
-rw-r--r-- | src/zip.cr | 72 |
1 files changed, 36 insertions, 36 deletions
@@ -303,42 +303,6 @@ module Zip end # - # Helper methods for converting to and from `Time` objects. - # - module TimeHelper - # - # Convert given `Time` to a DOS-style datetime, write the result to - # the given IO, and return the number of bytes written. - # - private def write_time(io : IO, time : Time) : UInt32 - year = Math.max(1980, time.year) - 1980 - - # convert to dos timestamp - (( - (year << 25) | (time.month << 21) | (time.day << 16) | - (time.hour << 11) | (time.minute << 5) | (time.second >> 1) - ) & UInt32::MAX).to_u32.to_io(io, LE) - - # return number of bytes written - 4_u32 - end - - # - # Convert given DOS datetime to a `Time` object. - # - private def from_dos_time(v : UInt32) : Time - Time.new( - year: (v >> 25) + 1980, - month: (v >> 21) & 0b0000_1111, - day: (v >> 16) & 0b0001_1111, - hour: (v >> 11) & 0b0001_1111, - minute: (v >> 5) & 0b0011_1111, - second: (v << 1) & 0b0011_1110, - ) - end - end - - # # Version identifier used to identify the version needed to extract a # given file and to indicate the format of the external file # attributes. @@ -419,6 +383,42 @@ module Zip end # + # Helper methods for converting to and from `Time` objects. + # + module TimeHelper + # + # Convert given `Time` to a DOS-style datetime, write the result to + # the given IO, and return the number of bytes written. + # + private def write_time(io : IO, time : Time) : UInt32 + year = Math.max(1980, time.year) - 1980 + + # convert to dos timestamp + (( + (year << 25) | (time.month << 21) | (time.day << 16) | + (time.hour << 11) | (time.minute << 5) | (time.second >> 1) + ) & UInt32::MAX).to_u32.to_io(io, LE) + + # return number of bytes written + 4_u32 + end + + # + # Convert given DOS datetime to a `Time` object. + # + private def from_dos_time(v : UInt32) : Time + Time.new( + year: (v >> 25) + 1980, + month: (v >> 21) & 0b0000_1111, + day: (v >> 16) & 0b0001_1111, + hour: (v >> 11) & 0b0001_1111, + minute: (v >> 5) & 0b0011_1111, + second: (v << 1) & 0b0011_1110, + ) + end + end + + # # Helper methods for reading and writing uncompressed data. # module NoneCompressionHelper |