class Time # Returns a new Time created from the ISO date format String "YYYYMMDDhhmmss" def self.from_iso(t) return nil unless t if t.to_s =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/ utc(Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i, Regexp.last_match(4).to_i, Regexp.last_match(5).to_i, Regexp.last_match(6).to_i) else raise ArgumentError, "invalid iso time format: #{t}" end end # Returns the Time as ISO date format String "YYYYMMDDhhmmss" def to_iso getutc.strftime("%Y%m%d%H%M%S") end end