Sha256: 326b26a2926226d2b409e5eca9436edb2964a9e3476f1c66a97f103ee0b9aa69

Contents?: true

Size: 1.31 KB

Versions: 66

Compression:

Stored size: 1.31 KB

Contents

# encoding: US-ASCII

require 'ostruct'

require 'binary_struct'

module Iso9660
  module Util
    ISO_DATE = BinaryStruct.new([
      'a4', 'year',   # Absolute year.
      'a2', 'month',
      'a2', 'day',
      'a2', 'hour',
      'a2', 'min',
      'a2', 'sec',
      'a2', 'hun',
      'c',  'offset'  # 15-min intervals (iow 4 per time zone).
    ])

    ISO_DATE_SHORT = BinaryStruct.new([
      'C',  'year',   # Since 1900.
      'C',  'month',
      'C',  'day',
      'C',  'hour',
      'C',  'min',
      'C',  'sec',
      'c',  'offset'  # 15-min intervals.
    ])

    def self.IsoToRubyDate(isodate)
      begin
        tv = OpenStruct.new(ISO_DATE.decode(isodate))
      rescue
        return Time.at(0).gmtime
      end
      Time.gm(tv.sec, tv.min, tv.hour, tv.day, tv.month, tv.year, nil, nil, nil, tv.offset / 4)
    end

    def self.GetTimezone(isodate)
      isodate[16, 1].unpack('c')[0] / 4
    end

    def self.IsoShortToRubyDate(isoShort)
      return Time.at(0).gmtime if isoShort == "\0" * 7
      begin
        tv = OpenStruct.new(ISO_DATE_SHORT.decode(isoShort))
      rescue
        return Time.at(0).gmtime
      end
      Time.gm(tv.sec, tv.min, tv.hour, tv.day, tv.month, tv.year + 1900, nil, nil, nil, tv.offset / 4)
    end

    def self.GetShortTimezone(isoShort)
      isoShort[7] / 4
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
manageiq-smartstate-0.5.4 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.5 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.3 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.2 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.1 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.4 lib/fs/iso9660/util.rb
manageiq-smartstate-0.4.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.18.2 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.3 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.2 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.1 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.24 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.18.1 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.23 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.22 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.21 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.20 lib/fs/iso9660/util.rb
manageiq-smartstate-0.2.19 lib/fs/iso9660/util.rb