Sha256: bdc690441eed6b8b974a0a2bc2777bafc991a6613a5e72ec1699a42123139de6

Contents?: true

Size: 729 Bytes

Versions: 13

Compression:

Stored size: 729 Bytes

Contents

# typed: ignore
# frozen_string_literal: true

require "bigdecimal"

module EML
  module UK
    class ParseDate
      extend T::Sig

      def self.call(date_string)
        new(date_string).call
      end

      def initialize(date_string)
        @date_string = date_string
      end

      def call
        return if @date_string.nil?

        matches = @date_string.match(%r(/Date\(((\d{13})([\+\-]\d{4})?)\)/))
        return if matches.nil?

        milliseconds = BigDecimal(matches[2])
        timezone_offset = matches[3]

        time = Time.at(milliseconds / 1000).utc
        return time if timezone_offset.nil?

        time.localtime("#{timezone_offset[0, 3]}:#{timezone_offset[3, 4]}")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
eml-3.0.0 lib/eml/uk/lib/parse_date.rb
eml-2.2.0 lib/eml/uk/lib/parse_date.rb
eml-2.1.8 lib/eml/uk/lib/parse_date.rb
eml-2.1.7 lib/eml/uk/lib/parse_date.rb
eml-2.1.6 lib/eml/uk/lib/parse_date.rb
eml-2.1.5 lib/eml/uk/lib/parse_date.rb
eml-2.1.4 lib/eml/uk/lib/parse_date.rb
eml-2.1.3 lib/eml/uk/lib/parse_date.rb
eml-2.1.2 lib/eml/uk/lib/parse_date.rb
eml-2.1.1 lib/eml/uk/lib/parse_date.rb
eml-2.1.0 lib/eml/uk/lib/parse_date.rb
eml-2.0.0 lib/eml/uk/lib/parse_date.rb
eml-1.0.0 lib/eml/uk/lib/parse_date.rb