Sha256: 08adf940b9c052e720efdbfa285bc5ca1b3d3143a24e0d75538c03e545acad3f

Contents?: true

Size: 1.47 KB

Versions: 42

Compression:

Stored size: 1.47 KB

Contents

module Zip
  class DOSTime < Time #:nodoc:all
    # MS-DOS File Date and Time format as used in Interrupt 21H Function 57H:

    # Register CX, the Time:
    # Bits 0-4  2 second increments (0-29)
    # Bits 5-10 minutes (0-59)
    # bits 11-15 hours (0-24)

    # Register DX, the Date:
    # Bits 0-4 day (1-31)
    # bits 5-8 month (1-12)
    # bits 9-15 year (four digit year minus 1980)

    def to_binary_dos_time
      (sec / 2) +
        (min << 5) +
        (hour << 11)
    end

    def to_binary_dos_date
      day +
        (month << 5) +
        ((year - 1980) << 9)
    end

    # Dos time is only stored with two seconds accuracy
    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(bin_dos_date, bin_dos_time)
      second = 2 * (0b11111 & bin_dos_time)
      minute = (0b11111100000 & bin_dos_time) >> 5
      hour   = (0b1111100000000000 & bin_dos_time) >> 11
      day    = (0b11111 & bin_dos_date)
      month  = (0b111100000 & bin_dos_date) >> 5
      year   = ((0b1111111000000000 & bin_dos_date) >> 9) + 1980
      begin
        local(year, month, day, hour, minute, second)
      end
    end
  end
end

# Copyright (C) 2002, 2003 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.

Version data entries

42 entries across 32 versions & 8 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
lg_pod_plugin-1.0.8 lib/zip/dos_time.rb
lg_pod_plugin-1.0.7 lib/zip/dos_time.rb
lg_pod_plugin-1.0.6 lib/zip/dos_time.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/rubyzip-2.3.0/lib/zip/dos_time.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/lib/zip/dos_time.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/rubyzip-2.3.0/lib/zip/dos_time.rb
rubyzip-2.3.2 lib/zip/dos_time.rb