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