current-locale 0.1.0.1 → 0.2.0.0
raw patch · 2 files changed
+31/−25 lines, 2 filesdep +splitPVP ok
version bump matches the API change (PVP)
Dependencies added: split
API changes (from Hackage documentation)
Files
- System/CurrentLocale.hs +27/−22
- current-locale.cabal +4/−3
System/CurrentLocale.hs view
@@ -1,34 +1,39 @@ -- |Get the current system locale in 'System.Locale' format. module System.CurrentLocale (currentLocale) where +import Control.Applicative+import Data.List.Split (splitOn) import System.Locale import System.Process -format :: String -> String -> IO String-format fmt date = do- output <- readProcess "date" ["+" ++ fmt, "-d", date] ""- return (stripNL output)- where stripNL x = (lines x) !! 0--formatWDay :: (String, String) -> IO (String, String)-formatWDay (wday, _) = do- full <- format "%A" wday- short <- format "%a" wday- return (full, short)+getLocaleData :: IO [String]+getLocaleData =+ lines <$> readProcess "locale"+ ["abday", "day",+ "abmon", "mon",+ "am_pm",+ "d_t_fmt",+ "d_fmt",+ "t_fmt",+ "t_fmt_ampm"]+ "" -formatMonth :: (String, String) -> IO (String, String)-formatMonth (month, _) = do- let mdate = month ++ " 1"- full <- format "%B" mdate- short <- format "%b" mdate- return (full, short)+split :: String -> [String]+split = splitOn ";" --- |Get the current system locale.+-- |Get the current system locale. This function does not initialize the+-- 'System.Locale.TimeLocale.intervals' field. currentLocale :: IO TimeLocale currentLocale = do- wDays <- mapM formatWDay $ wDays defaultTimeLocale- months <- mapM formatMonth $ months defaultTimeLocale+ [abday, day, abmon, mon, am_pm, d_t_fmt, d_fmt, t_fmt, t_fmt_ampm] <- getLocaleData+ let [am, pm] = split am_pm+ return defaultTimeLocale- { wDays = wDays- , months = months+ { wDays = zip (split day) (split abday)+ , months = zip (split mon) (split abmon)+ , amPm = (am, pm)+ , dateTimeFmt = d_t_fmt+ , dateFmt = d_fmt+ , timeFmt = t_fmt+ , time12Fmt = t_fmt_ampm }
current-locale.cabal view
@@ -1,8 +1,8 @@ name: current-locale-version: 0.1.0.1+version: 0.2.0.0 synopsis: Get the current system locale in System.Locale format description:- Use the system 'date' command to find out the current+ Use the system 'locale' command to find out the current system locale in System.Locale format. homepage: https://github.com/koterpillar/current-locale license: MIT@@ -14,7 +14,8 @@ cabal-version: >=1.8 library exposed-modules: System.CurrentLocale- build-depends: old-locale >= 1.0, process >= 1.0.1.1, base > 3 && < 5+ build-depends: old-locale >= 1.0, process >= 1.0.1.1, base > 3 && < 5, split+ ghc-options: -Wall -fwarn-tabs source-repository head type: git location: git://github.com/koterpillar/current-locale.git