lib/tzinfo/timezone.rb in tzinfo-0.3.60 vs lib/tzinfo/timezone.rb in tzinfo-0.3.61

- old
+ new

@@ -99,11 +99,11 @@ # # Raises InvalidTimezoneIdentifier if the timezone couldn't be found. def self.get(identifier) instance = @@loaded_zones[identifier] unless instance - raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /^[A-Za-z0-9\+\-_]+(\/[A-Za-z0-9\+\-_]+)*$/ + raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /\A[A-Za-z0-9+\-_]+(\/[A-Za-z0-9+\-_]+)*\z/ identifier = identifier.gsub(/-/, '__m__').gsub(/\+/, '__p__') begin # Use a temporary variable to avoid an rdoc warning file = "tzinfo/definitions/#{identifier}".untaint require file @@ -496,13 +496,16 @@ local.strftime(format) end # Compares two Timezones based on their identifier. Returns -1 if tz is less # than self, 0 if tz is equal to self and +1 if tz is greater than self. + # + # Returns nil if tz is not comparable with Timezone instances. def <=>(tz) + return nil unless tz.is_a?(Timezone) identifier <=> tz.identifier end - + # Returns true if and only if the identifier of tz is equal to the # identifier of this Timezone. def eql?(tz) self == tz end