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