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

TZInfo::Timezone.get('America/New_York').utc_to_local(nil) = -18000 #39

augnustin opened this issue Jun 15, 2015 · 1 comment


Copy link

I would expect:

TZInfo::Timezone.get('America/New_York').utc_to_local(nil) # to equal nil

Because the time difference of nothing is nothing.

Used in code, it goes like:

TZInfo::Timezone.get('America/New_York').utc_to_local(Object.updated_at) # Object.updated_at can be nil

which consequently requires a if Object.updated_at appended, which is IMHO less elegant.

Copy link

philr commented Jan 3, 2017

Sorry for the delay in responding to this.

I've decided to make TZInfo raise an exception when passed a nil time (this is now implemented on the master branch). On balance, I think it is better to be explicit about handling nil values.

As for keeping the code elegant, you could add a method to the Time class in your project and then use it along with the safe navigation (&.) operator. For example:

class Time
  def to_new_york


@philr philr closed this as completed Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants