[project @ 2002-04-24 16:31:37 by simonmar]
[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/core/LICENSE)
6 -- 
7 -- Maintainer  :  libraries@haskell.org
8 -- Stability   :  provisional
9 -- Portability :  portable
10 --
11 -- $Id: Locale.hs,v 1.2 2002/04/24 16:31:45 simonmar Exp $
12 --
13 -- Operations for defining locale-specific date and time formats.
14 --
15 -----------------------------------------------------------------------------
16
17 module System.Locale
18     ( TimeLocale(..)
19     , defaultTimeLocale
20     
21     , iso8601DateFormat
22     , rfc822DateFormat
23     )
24 where
25
26 import Prelude
27
28 data TimeLocale = TimeLocale {
29         wDays  :: [(String, String)],   -- full and abbreviated week days
30         months :: [(String, String)],   -- full and abbreviated months
31         intervals :: [(String, String)],
32         amPm   :: (String, String),     -- AM/PM symbols
33         dateTimeFmt, dateFmt,           -- formatting strings
34         timeFmt, time12Fmt :: String     
35         } deriving (Eq, Ord, Show)
36
37 defaultTimeLocale :: TimeLocale 
38 defaultTimeLocale =  TimeLocale { 
39         wDays  = [("Sunday",   "Sun"),  ("Monday",    "Mon"),   
40                   ("Tuesday",  "Tue"),  ("Wednesday", "Wed"), 
41                   ("Thursday", "Thu"),  ("Friday",    "Fri"), 
42                   ("Saturday", "Sat")],
43
44         months = [("January",   "Jan"), ("February",  "Feb"),
45                   ("March",     "Mar"), ("April",     "Apr"),
46                   ("May",       "May"), ("June",      "Jun"),
47                   ("July",      "Jul"), ("August",    "Aug"),
48                   ("September", "Sep"), ("October",   "Oct"),
49                   ("November",  "Nov"), ("December",  "Dec")],
50
51         intervals = [ ("year","years")
52                     , ("month", "months")
53                     , ("day","days")
54                     , ("hour","hours")
55                     , ("min","mins")
56                     , ("sec","secs")
57                     , ("usec","usecs")
58                     ],
59
60         amPm = ("AM", "PM"),
61         dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y",
62         dateFmt = "%m/%d/%y",
63         timeFmt = "%H:%M:%S",
64         time12Fmt = "%I:%M:%S %p"
65         }
66
67
68 iso8601DateFormat :: Maybe String -> String
69 iso8601DateFormat timeFmt =
70     "%Y-%m-%d" ++ case timeFmt of
71              Nothing  -> "" -- normally, ISO-8601 just defines YYYY-MM-DD
72              Just fmt -> ' ' : fmt -- but we can add a time spec
73
74
75 rfc822DateFormat :: String
76 rfc822DateFormat = "%a, %_d %b %Y %H:%M:%S %Z"