0

Is there any way for me to tell Ruby to use a certain time zone as if it were the local time zone?

TMI:

I realize that in Rails there is a lot of support for time zones, but I've just been put on a project which uses Ruby without Rails, and I need to fix a time zone in order to support some existing Rspec tests.

Among these tests are some calls to an FTP servIs there er with Net::FTP. The returned mtime is getting cast into my development machine's local time, breaking a number of existing specs.

JellicleCat
  • 28,480
  • 24
  • 109
  • 162
  • 2
    Just ignore the accepted answer in the linked question but use the highest-voted answer instead. tl;dr: set the `TZ` environment variable to override the system-provided timezone for the current process. – Holger Just Oct 23 '19 at 19:28

1 Answers1

1

Not in STDLIB but you could use the TZInfo gem to accomplish this. They have a well written README.

  • Thanks. I have read the README, but I don't see a way to specify a system timezone. The only approach I see is to edit each of my specs to explicitly convert times from one zone to another. Am I missing something? – JellicleCat Oct 23 '19 at 18:22