Issue #14850 has been updated by nobu (Nobuyoshi Nakada).


Here're my plans.

> ## timezone argument to `Time.at`
> 
> `Time.at` already has the fraction second and its unit arguments.
> To add another optional argument feels complicated, or a keyword argument?

To add `in` keyword argument.

```ruby
Time.at(1540000000, in: Timezone.fetch("Asia/Colombo")) #=> 2018-10-20 07:16:40 +0530
```

> ## look-up timezone by the name
> 
> With "tzinfo" gem, `Time.new(Y, M, D, h, m, s, TZInfo::Timezone.get(zone_name))`, and
> with "timeone" gem, `Time.new(Y, M, D, h, m, s, Timezone[zone_name])` are possible but not handy.
> `Time.new(Y, M, D, h, m, s, zone_name)` feels preferable, but I don't want to couple them tightly.

If `find_timezone` class method is defined, it will be called with the `zone_name` argument.

Any options?
If no objection, I'll commit the above features.

----------------------------------------
Feature #14850: Add official API for setting timezone on Time
https://bugs.ruby-lang.org/issues/14850#change-74644

* Author: sam.saffron (Sam Saffron)
* Status: Closed
* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>