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