[commit: packages/time] format-widths, improve-leapseconds, master, posix-perf, tasty, wip/travis: remove dependency on old-locale (907cbc2)

git at git.haskell.org git at git.haskell.org
Mon Feb 20 21:16:19 UTC 2017


Repository : ssh://git@git.haskell.org/time

On branches: format-widths,improve-leapseconds,master,posix-perf,tasty,wip/travis
Link       : http://git.haskell.org/packages/time.git/commitdiff/907cbc2c7c3fcecea255028fb895c3f5b144a6eb

>---------------------------------------------------------------

commit 907cbc2c7c3fcecea255028fb895c3f5b144a6eb
Author: Ashley Yakeley <ashley at yakeley.org>
Date:   Sat Aug 23 21:56:11 2014 -0700

    remove dependency on old-locale


>---------------------------------------------------------------

907cbc2c7c3fcecea255028fb895c3f5b144a6eb
 lib/Data/Time/Format/Locale.hs | 78 ++++++++++++++++++++++++++++++++++++++++++
 lib/Data/Time/Format/Parse.hs  |  4 +--
 lib/System/Locale.hs           |  5 +++
 time.cabal                     |  8 ++---
 4 files changed, 89 insertions(+), 6 deletions(-)

diff --git a/lib/Data/Time/Format/Locale.hs b/lib/Data/Time/Format/Locale.hs
new file mode 100644
index 0000000..11ec05a
--- /dev/null
+++ b/lib/Data/Time/Format/Locale.hs
@@ -0,0 +1,78 @@
+-- Note: this file derives from old-locale:System.Locale.hs, which is copyright (c) The University of Glasgow 2001
+
+module Data.Time.Format.Locale (
+
+    TimeLocale(..)
+
+    , defaultTimeLocale
+
+    , iso8601DateFormat
+    , rfc822DateFormat
+    )
+where
+
+import Prelude
+
+data TimeLocale = TimeLocale {
+        -- |full and abbreviated week days
+        wDays  :: [(String, String)],
+        -- |full and abbreviated months
+        months :: [(String, String)],
+        intervals :: [(String, String)],
+        -- |AM\/PM symbols
+        amPm   :: (String, String),
+        -- |formatting strings
+        dateTimeFmt, dateFmt,
+        timeFmt, time12Fmt :: String
+        } deriving (Eq, Ord, Show)
+
+defaultTimeLocale :: TimeLocale
+defaultTimeLocale =  TimeLocale {
+        wDays  = [("Sunday",   "Sun"),  ("Monday",    "Mon"),
+                  ("Tuesday",  "Tue"),  ("Wednesday", "Wed"),
+                  ("Thursday", "Thu"),  ("Friday",    "Fri"),
+                  ("Saturday", "Sat")],
+
+        months = [("January",   "Jan"), ("February",  "Feb"),
+                  ("March",     "Mar"), ("April",     "Apr"),
+                  ("May",       "May"), ("June",      "Jun"),
+                  ("July",      "Jul"), ("August",    "Aug"),
+                  ("September", "Sep"), ("October",   "Oct"),
+                  ("November",  "Nov"), ("December",  "Dec")],
+
+        intervals = [ ("year","years")
+                    , ("month", "months")
+                    , ("day","days")
+                    , ("hour","hours")
+                    , ("min","mins")
+                    , ("sec","secs")
+                    , ("usec","usecs")
+                    ],
+
+        amPm = ("AM", "PM"),
+        dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y",
+        dateFmt = "%m/%d/%y",
+        timeFmt = "%H:%M:%S",
+        time12Fmt = "%I:%M:%S %p"
+        }
+
+
+{- | Construct format string according to <http://en.wikipedia.org/wiki/ISO_8601 ISO-8601>.
+
+The @Maybe String@ argument allows to supply an optional time specification. E.g.:
+
+@
+'iso8601DateFormat' Nothing            == "%Y-%m-%d"           -- i.e. @/YYYY-MM-DD/@
+'iso8601DateFormat' (Just "%H:%M:%S")  == "%Y-%m-%dT%H:%M:%S"  -- i.e. @/YYYY-MM-DD/T/HH:MM:SS/@
+@
+-}
+
+iso8601DateFormat :: Maybe String -> String
+iso8601DateFormat mTimeFmt =
+    "%Y-%m-%d" ++ case mTimeFmt of
+             Nothing  -> ""
+             Just fmt -> 'T' : fmt
+
+-- | Format string according to <http://tools.ietf.org/html/rfc822#section-5 RFC822>.
+rfc822DateFormat :: String
+rfc822DateFormat = "%a, %_d %b %Y %H:%M:%S %Z"
diff --git a/lib/Data/Time/Format/Parse.hs b/lib/Data/Time/Format/Parse.hs
index 5b0b762..82c48df 100644
--- a/lib/Data/Time/Format/Parse.hs
+++ b/lib/Data/Time/Format/Parse.hs
@@ -11,7 +11,7 @@ module Data.Time.Format.Parse
 #endif
     ParseTime(..),
     -- * Locale
-    module System.Locale
+    module Data.Time.Format.Locale
     ) where
 
 import Data.Time.Clock.POSIX
@@ -29,7 +29,7 @@ import Data.Fixed
 import Data.List
 import Data.Maybe
 import Data.Ratio
-import System.Locale
+import Data.Time.Format.Locale
 #if LANGUAGE_Rank2Types
 import Text.ParserCombinators.ReadP hiding (char, string)
 #endif
diff --git a/lib/System/Locale.hs b/lib/System/Locale.hs
new file mode 100644
index 0000000..88961cc
--- /dev/null
+++ b/lib/System/Locale.hs
@@ -0,0 +1,5 @@
+module System.Locale
+{-# DEPRECATED "Use Data.Time.Format instead" #-}
+(module Data.Time.Format.Locale)
+where
+import Data.Time.Format.Locale
diff --git a/time.cabal b/time.cabal
index 881fd7d..23a388f 100644
--- a/time.cabal
+++ b/time.cabal
@@ -36,8 +36,7 @@ library
     hs-source-dirs: lib
     build-depends:
         base >= 4.4 && < 5,
-        deepseq >= 1.1,
-        old-locale
+        deepseq >= 1.1
     ghc-options: -Wall
     default-language: Haskell2010
     if impl(ghc)
@@ -64,7 +63,8 @@ library
         Data.Time.Clock.TAI,
         Data.Time.LocalTime,
         Data.Time.Format,
-        Data.Time
+        Data.Time,
+        System.Locale
     default-extensions:    CPP
     c-sources: lib/cbits/HsTime.c
     other-modules:
@@ -80,6 +80,7 @@ library
         Data.Time.LocalTime.TimeOfDay,
         Data.Time.LocalTime.LocalTime,
         Data.Time.Format.Parse
+        Data.Time.Format.Locale
     include-dirs: lib/include
     if os(windows)
         install-includes:
@@ -108,7 +109,6 @@ test-suite tests
     build-depends:
         base,
         deepseq,
-        old-locale,
         time == 1.5,
         QuickCheck >= 2.5.1,
         test-framework >= 0.8,



More information about the ghc-commits mailing list