mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
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:
parent
55168db92f
commit
8de488475a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user