[project @ 2002-08-30 13:43:57 by stolz]
[ghc-base.git] / System / Locale.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module      :  System.Locale
4 -- Copyright   :  (c) The University of Glasgow 2001
5 -- License     :  BSD-style (see the file libraries/base/LICENSE)
6 -- 
7 -- Maintainer  :  libraries@haskell.org
8 -- Stability   :  provisional
9 -- Portability :  portable
10 --
11 -- Operations for defining locale-specific date and time formats.
12 --
13 -----------------------------------------------------------------------------
14
15 module System.Locale (
16
17     -- |The 'Locale' library provides the ability to adapt to local conventions.
18     -- At present, it supports only time and date information as used by
19     -- 'calendarTimeToString' from the "System.Time" library.
20     
21     TimeLocale(..)
22
23     , defaultTimeLocale
24     
25     , iso8601DateFormat
26     , rfc822DateFormat
27     )
28 where
29
30 import Prelude
31
32 data TimeLocale = TimeLocale {
33         -- |full and abbreviated week days
34         wDays  :: [(String, String)],
35         -- |full and abbreviated months
36         months :: [(String, String)],
37         intervals :: [(String, String)],
38         -- |AM\/PM symbols
39         amPm   :: (String, String),
40         -- |formatting strings
41         dateTimeFmt, dateFmt,
42         timeFmt, time12Fmt :: String     
43         } deriving (Eq, Ord, Show)
44
45 defaultTimeLocale :: TimeLocale 
46 defaultTimeLocale =  TimeLocale { 
47         wDays  = [("Sunday",   "Sun"),  ("Monday",    "Mon"),   
48                   ("Tuesday",  "Tue"),  ("Wednesday", "Wed"), 
49                   ("Thursday", "Thu"),  ("Friday",    "Fri"), 
50                   ("Saturday", "Sat")],
51
52         months = [("January",   "Jan"), ("February",  "Feb"),
53                   ("March",     "Mar"), ("April",     "Apr"),
54                   ("May",       "May"), ("June",      "Jun"),
55                   ("July",      "Jul"), ("August",    "Aug"),
56                   ("September", "Sep"), ("October",   "Oct"),
57                   ("November",  "Nov"), ("December",  "Dec")],
58
59         intervals = [ ("year","years")
60                     , ("month", "months")
61                     , ("day","days")
62                     , ("hour","hours")
63                     , ("min","mins")
64                     , ("sec","secs")
65                     , ("usec","usecs")
66                     ],
67
68         amPm = ("AM", "PM"),
69         dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y",
70         dateFmt = "%m/%d/%y",
71         timeFmt = "%H:%M:%S",
72         time12Fmt = "%I:%M:%S %p"
73         }
74
75
76 -- |Normally, ISO-8601 just defines YYYY-MM-DD
77 -- but we can add a time spec.
78
79 iso8601DateFormat :: Maybe String -> String
80 iso8601DateFormat timeFmt =
81     "%Y-%m-%d" ++ case timeFmt of
82              Nothing  -> "" 
83              Just fmt -> ' ' : fmt
84
85
86 rfc822DateFormat :: String
87 rfc822DateFormat = "%a, %_d %b %Y %H:%M:%S %Z"