From: shevegen@... Date: 2018-06-18T11:37:13+00:00 Subject: [ruby-core:87508] [Ruby trunk Feature#14850] Add official API for setting timezone on Time Issue #14850 has been updated by shevegen (Robert A. Heiler). I agree in regards to it being odd that in an OOP-centric language we have to fiddle with environment variables. Irrelevant fun fact: - I once set TZ as alias towards '.tar.gz' or something like that. Turns out that was not good for when you want to compile programs from source in bash ... things failed to compile/work past that point. :) There are quite a few environment variables that can induce an odd behaviour. This is not so much related to your issue request but I can completely understand where you are coming from, because while manipulating ENV works (I use it to modify CFLAGS for example, in the ruby-project that I use to compile programs from source), it's not extremely elegant. So personally, I agree with your general issue request about having some way to set the timezone. I don't care so much where it resides (Time, Date... whatever, though the fewer cases where time-related information is stored, the better). API-wise, though, I think the ActiveSupport API or choice of name is bad. ActiveSupport::TimeWithZone I am not sure about: Time.zone = But I think that this is mostly a detail that can be expanded on when matz/the ruby core team would approve of this. Some of the API in ActiveSupport is weird to me though. There is one thing for you to consider in the request, because what happens in regards to backwards compatibility? Some people may rely on that ENV behaviour. So the method should also clearly state whether it will modify ENV, or have no effect on ENV (but in that case, what happens when people modify ENV['TZ'] - will that have an impact?) I think these details have to be added into the issue request. Perhaps as a compromise an argument could be used to denote this, with the default argument retaining the old behaviour as-is, whereas people who want an API + method need to pass some additional argument to it. ---------------------------------------- Feature #14850: Add official API for setting timezone on Time https://bugs.ruby-lang.org/issues/14850#change-72512 * Author: sam.saffron (Sam Saffron) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Only way of setting zone on a Time object appears to be via marshalling and messing with ENV. ``` >> ENV['TZ'] = 'America/New_York' >> Time.now.zone => "EDT" >> ENV['TZ'] = 'Europe/London' >> Time.now.zone => "BST" ``` Is there any particular reason there is no direct, supported API for setting timezone? ActiveSupport carries http://api.rubyonrails.org/v5.1/classes/ActiveSupport/TimeWithZone.html for this exact reason, it would be nice for core Ruby to support this out-of-the-box -- https://bugs.ruby-lang.org/ Unsubscribe: