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

Invalid result when formatting time zone as hour and minute offset from UTC #11

pawelkrol opened this issue Jun 6, 2016 · 1 comment


Copy link

pawelkrol commented Jun 6, 2016

Formatting time zone object using abbreviated time zone name (%Z) seems to work just fine, however formatting it as hour and minute offset from UTC (%z) appears to return an invalid result. See an example below, I would expect to get -05:00 rather than +00:00:

2.1.8 :001 > tz ='America/Chicago')
 => #<TZInfo::DataTimezone: America/Chicago>
2.1.8 :002 > tz.strftime('%Z')
 => "CDT"
2.1.8 :003 > tz.strftime('%:z')
 => "+00:00"

Is this problem related to your code, or is it dependent on specific environment settings and/or ruby installation? If the latter is the case, do you know any workaround to address it? Many thanks!

Copy link

philr commented Jun 6, 2016

The Timezone#strftime method in the latest tzinfo release doesn't support %z (it gets passed to Time#strftime, which returns '+0000').

There is a change in the tzinfo git repository that adds support for %z. You could take the latest version of Timezone#strftime from timezone.rb and apply it as a monkey patch.

Alternatively, you could obtain the current offset using Timezone#period_for_utc and then format it separately:

# => -18000

@philr philr closed this as completed Jun 6, 2016
@philr philr added the question label Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants