Sha256: 8ec826f4f7b30f108fb0f648e14c7ae0663ded3c6879a1ab90101e267474a557
Contents?: true
Size: 738 Bytes
Versions: 124
Compression:
Stored size: 738 Bytes
Contents
# frozen_string_literal: true class ReeDatetime::OffsetToString include Ree::FnDSL fn :offset_to_string MAX_OFFSET = 86_400 OFFSET_CACHE = {} doc("Converts an offset in seconds to a formatted string (ex. 3600 => '+01:00") contract(Integer => String).throws(ArgumentError) def call(offset) return OFFSET_CACHE[offset] if OFFSET_CACHE.has_key?(offset) if !(-MAX_OFFSET..MAX_OFFSET).include?(offset) raise ArgumentError, "offset should be in (-#{MAX_OFFSET}..#{MAX_OFFSET})" end val = offset.abs hours = val / 3600 minutes = (val % 3600) / 60 str = "#{offset < 0 ? '-' : '+'}#{hours < 10 ? '0' : ''}#{hours}:#{minutes < 10 ? '0' : ''}#{minutes}" OFFSET_CACHE[offset] = str end end
Version data entries
124 entries across 124 versions & 1 rubygems