Load timezones more leniently. (#582)

Summary:
On some linux systems, such as on NixOS, /usr/share/zoneinfo does not
exist. What does exist in its place is /etc/zoneinfo. So, we should try to load
that if /usr/share/zoneinfo does not exist.

Pull Request resolved: https://github.com/facebook/duckling/pull/582

Reviewed By: girifb

Differential Revision: D27086925

Pulled By: chessai

fbshipit-source-id: f4a38822be9888d57034f67a6f7abd17d56d38b8
This commit is contained in:
chessai 2021-03-16 12:59:13 -07:00 committed by Facebook GitHub Bot
parent 55168db92f
commit 8de488475a

View File

@ -6,10 +6,12 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
import Control.Applicative hiding (empty)
import Control.Arrow ((***))
import Control.Exception (SomeException, catch)
import Control.Monad (unless, when)
import Control.Monad.IO.Class
import Data.Aeson
@ -57,9 +59,15 @@ setupLogs conf = do
when shouldLogErrors $ createIfMissing "log/error.log"
when shouldLogAccesses $ createIfMissing "log/access.log"
loadTZs :: IO (HashMap Text TimeZoneSeries)
loadTZs = do
let defaultPath = "/usr/share/zoneinfo/"
let fallbackPath = "/etc/zoneinfo/"
loadTimeZoneSeries defaultPath `catch` (\(_ :: SomeException) -> loadTimeZoneSeries fallbackPath)
main :: IO ()
main = do
tzs <- loadTimeZoneSeries "/usr/share/zoneinfo/"
tzs <- loadTZs
p <- lookupEnv "PORT"
conf <- commandLineConfig $
maybe defaultConfig (`setPort` defaultConfig) (readMaybe =<< p)