Last active
August 29, 2015 14:02
-
-
Save asaaki/f3b20b3e28101df1784d to your computer and use it in GitHub Desktop.
Timezones: float offset to numerical string presentation of zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ZoneConversion | |
module_function | |
def float2zone(offset) | |
("%+06.2f" % offset).tr(".", ":") | |
end | |
end | |
### Example | |
offset = 4.0 | |
ZoneConversion.float2zone(offset) | |
#=> "+04:00" | |
offset = -8.0 | |
ZoneConversion.float2zone(offset) | |
#=> "-08:00" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment