Skip to content

Resolving TZInfo::DataSourceNotFound Errors

Phil Ross edited this page Mar 20, 2015 · 2 revisions

You may encounter a TZInfo::DataSourceNotFound exception with the message No source of timezone data could be found when you use TZInfo or other libraries that depend on it (for example, Active Support and Ruby on Rails). The error indicates that TZInfo was unable to find a source of time zone data on your system. This will typically occur if you are using Windows.

The simplest way to resolve this error is to install the tzinfo-data gem, either by editing your Gemfile or by running gem install tzinfo-data.

On most Unix-based systems (e.g. Linux), TZInfo is able to use the system zoneinfo directory as a source of data. However, Windows doesn't include such a directory, so the tzinfo-data gem needs to be installed instead. The tzinfo-data gem contains the same zoneinfo data, but is packaged as a set of Ruby modules.

Using tzinfo-data with Bundler or Ruby on Rails

If you are using Ruby on Rails or your project uses Bundler to manage dependencies, you'll need to make sure that the tzinfo-data gem is included in your Gemfile.

First of all, check your Gemfile to see if there is an existing reference to tzinfo-data. If there isn't already a reference, then add the following line:

gem 'tzinfo-data'

If you are using Ruby on Rails and your project was created on Windows, then you may find that there is already a line in your Gemfile like the following:

gem 'tzinfo-data', platforms: [:mingw, :mswin]

If you are using a 64-bit version of Ruby on Windows, then add :x64_mingw to the list of platforms as follows:

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

If you are using JRuby, then add :jruby to the list of platforms:

gem 'tzinfo-data', platforms: [:mingw, :mswin, :jruby]

Alternatively, you can remove the platforms option altogether.

After editing your Gemfile, run bundle update at the command line to install the tzinfo-data gem. You'll then be able to start your project.

Installing tzinfo-data manually

TZInfo attempts to load tzinfo-data by calling require 'tzinfo/data'. If the tzinfo-data/lib directory is on the Ruby load path, then TZInfo will be able to find and use tzinfo-data.

If you are not using a dependency management system such as Bundler, then installing the tzinfo-data gem should be sufficient to resolve the error:

gem install tzinfo-data

Manually specifying the path to a zoneinfo directory

If TZInfo fails to locate the system zoneinfo directory automatically, the path can be specified manually using TZInfo::DataSource.set:

TZInfo::DataSource.set(:zoneinfo, zoneinfo_path)

See Also

Clone this wiki locally
You can’t perform that action at this time.