Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define =~ method on Timezone identifier #99

Merged
merged 1 commit into from Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/tzinfo/timezone.rb
Expand Up @@ -1119,6 +1119,14 @@ def hash
identifier.hash
end

# @param regex [Regex] a `Regex` to match against the identifier of this
# {Timezone}.
# @return [Integer, nil] `Integer` offset of the match on the identifier,
# otherwise `nil` if there is no match.
def =~(regex)
regex =~ identifier
end

# Returns a serialized representation of this {Timezone}. This method is
# called when using `Marshal.dump` with an instance of {Timezone}.
#
Expand Down
6 changes: 6 additions & 0 deletions test/tc_timezone.rb
Expand Up @@ -1700,6 +1700,12 @@ def test_hash
assert_equal('America/New_York'.hash, TestTimezone.new('America/New_York').hash)
end

define_method("test_=~_operator_matches_against_identifier") do
tz = TestTimezone.new('Europe/London')
assert_equal(0, tz =~ /Europe\/London/)
assert_nil(tz =~ /America\/NewYork/)
end

def test_marshal_data
tz = Timezone.get('Europe/London')
marshalled_tz = Marshal.load(Marshal.dump(tz))
Expand Down