[project @ 2000-06-19 13:28:35 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / Locale.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1995-99
3 %
4 \section[Time]{Haskell 1.4 Locale Library}
5
6
7 \begin{code}
8 module Locale
9     ( TimeLocale(..)
10     , defaultTimeLocale
11     
12     , iso8601DateFormat
13     , rfc822DateFormat
14     )
15 where
16
17 import Prelude  -- so as to force recompilations when reqd.
18
19 data TimeLocale = TimeLocale {
20         wDays  :: [(String, String)],   -- full and abbreviated week days
21         months :: [(String, String)],   -- full and abbreviated months
22         intervals :: [(String, String)],
23         amPm   :: (String, String),     -- AM/PM symbols
24         dateTimeFmt, dateFmt,           -- formatting strings
25         timeFmt, time12Fmt :: String     
26         } deriving (Eq, Ord, Show)
27
28 defaultTimeLocale :: TimeLocale 
29 defaultTimeLocale =  TimeLocale { 
30         wDays  = [("Sunday",   "Sun"),  ("Monday",    "Mon"),   
31                   ("Tuesday",  "Tue"),  ("Wednesday", "Wed"), 
32                   ("Thursday", "Thu"),  ("Friday",    "Fri"), 
33                   ("Saturday", "Sat")],
34
35         months = [("January",   "Jan"), ("February",  "Feb"),
36                   ("March",     "Mar"), ("April",     "Apr"),
37                   ("May",       "May"), ("June",      "Jun"),
38                   ("July",      "Jul"), ("August",    "Aug"),
39                   ("September", "Sep"), ("October",   "Oct"),
40                   ("November",  "Nov"), ("December",  "Dec")],
41
42         intervals = [ ("year","years")
43                     , ("month", "months")
44                     , ("day","days")
45                     , ("hour","hours")
46                     , ("min","mins")
47                     , ("sec","secs")
48                     , ("usec","usecs")
49                     ],
50
51         amPm = ("AM", "PM"),
52         dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y",
53         dateFmt = "%m/%d/%y",
54         timeFmt = "%H:%M:%S",
55         time12Fmt = "%I:%M:%S %p"
56         }
57
58
59 iso8601DateFormat :: Maybe String -> String
60 iso8601DateFormat timeFmt =
61     "%Y-%m-%d" ++ case timeFmt of
62              Nothing  -> "" -- normally, ISO-8601 just defines YYYY-MM-DD
63              Just fmt -> ' ' : fmt -- but we can add a time spec
64
65
66 rfc822DateFormat :: String
67 rfc822DateFormat = "%a, %_d %b %Y %H:%M:%S %Z"
68 \end{code}