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.10.1 lib/fs/iso9660/util.rb
manageiq-smartstate-0.10.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.9.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.8.1 lib/fs/iso9660/util.rb
manageiq-smartstate-0.8.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.7.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.6.2 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.10 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.10 lib/fs/iso9660/util.rb
manageiq-smartstate-0.6.1 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.9 lib/fs/iso9660/util.rb
manageiq-smartstate-0.6.0 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.9 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.8 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.8 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.7 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.7 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.6 lib/fs/iso9660/util.rb
manageiq-smartstate-0.3.6 lib/fs/iso9660/util.rb
manageiq-smartstate-0.5.5 lib/fs/iso9660/util.rb