Sha256: f1f795c04b6e1ed6d29cbd15bfd508a9619e9b687871d104c17c773b5b446082
Contents?: true
Size: 1.02 KB
Versions: 22
Compression:
Stored size: 1.02 KB
Contents
require 'tzinfo' class BigqueryMigration class TimeWithZone # [+-]HH:MM, [+-]HHMM, [+-]HH NUMERIC_PATTERN = %r{\A[+-]\d\d(:?\d\d)?\z} # Region/Zone, Region/Zone/Zone NAME_PATTERN = %r{\A[^/]+/[^/]+(/[^/]+)?\z} class << self def time_with_zone(time, timezone) time.localtime(zone_offset(timezone)) end def strptime_with_zone(date, format, timezone) time = Time.strptime(date, format) _utc_offset = time.utc_offset _zone_offset = zone_offset(timezone) time.localtime(_zone_offset) + _utc_offset - _zone_offset end private def zone_offset(timezone) if NUMERIC_PATTERN === timezone Time.zone_offset(timezone) elsif NAME_PATTERN === timezone tz = TZInfo::Timezone.get(timezone) tz.current_period.utc_total_offset elsif "UTC" == timezone # special treatment 0 else raise ArgumentError, "timezone format is invalid: #{timezone}" end end end end end
Version data entries
22 entries across 22 versions & 1 rubygems