d15ca1e24af19da6f7be5f74d15c58f28409269f
[packages/time.git] / lib / Data / Time / Format / Locale.hs
1 -- Note: this file derives from old-locale:System.Locale.hs, which is copyright (c) The University of Glasgow 2001
2
3 module Data.Time.Format.Locale (
4
5 TimeLocale(..)
6
7 , defaultTimeLocale
8
9 , iso8601DateFormat
10 , rfc822DateFormat
11 )
12 where
13
14 import Data.Time.LocalTime.Internal.TimeZone
15
16
17 data TimeLocale = TimeLocale {
18 -- |full and abbreviated week days, starting with Sunday
19 wDays :: [(String, String)],
20 -- |full and abbreviated months
21 months :: [(String, String)],
22 -- |AM\/PM symbols
23 amPm :: (String, String),
24 -- |formatting strings
25 dateTimeFmt, dateFmt,
26 timeFmt, time12Fmt :: String,
27 -- |time zones known by name
28 knownTimeZones :: [TimeZone]
29 } deriving (Eq, Ord, Show)
30
31 -- | Locale representing American usage.
32 --
33 -- 'knownTimeZones' contains only the ten time-zones mentioned in RFC 822 sec. 5:
34 -- \"UT\", \"GMT\", \"EST\", \"EDT\", \"CST\", \"CDT\", \"MST\", \"MDT\", \"PST\", \"PDT\".
35 -- Note that the parsing functions will regardless parse \"UTC\", single-letter military time-zones, and +HHMM format.
36 defaultTimeLocale :: TimeLocale
37 defaultTimeLocale = TimeLocale {
38 wDays = [("Sunday", "Sun"), ("Monday", "Mon"),
39 ("Tuesday", "Tue"), ("Wednesday", "Wed"),
40 ("Thursday", "Thu"), ("Friday", "Fri"),
41 ("Saturday", "Sat")],
42
43 months = [("January", "Jan"), ("February", "Feb"),
44 ("March", "Mar"), ("April", "Apr"),
45 ("May", "May"), ("June", "Jun"),
46 ("July", "Jul"), ("August", "Aug"),
47 ("September", "Sep"), ("October", "Oct"),
48 ("November", "Nov"), ("December", "Dec")],
49
50 amPm = ("AM", "PM"),
51 dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y",
52 dateFmt = "%m/%d/%y",
53 timeFmt = "%H:%M:%S",
54 time12Fmt = "%I:%M:%S %p",
55 knownTimeZones =
56 [
57 TimeZone 0 False "UT",
58 TimeZone 0 False "GMT",
59 TimeZone (-5 * 60) False "EST",
60 TimeZone (-4 * 60) True "EDT",
61 TimeZone (-6 * 60) False "CST",
62 TimeZone (-5 * 60) True "CDT",
63 TimeZone (-7 * 60) False "MST",
64 TimeZone (-6 * 60) True "MDT",
65 TimeZone (-8 * 60) False "PST",
66 TimeZone (-7 * 60) True "PDT"
67 ]
68 }
69
70 {- | Construct format string according to <http://en.wikipedia.org/wiki/ISO_8601 ISO-8601>.
71
72 The @Maybe String@ argument allows to supply an optional time specification. E.g.:
73
74 @
75 'iso8601DateFormat' Nothing == "%Y-%m-%d" -- i.e. @/YYYY-MM-DD/@
76 'iso8601DateFormat' (Just "%H:%M:%S") == "%Y-%m-%dT%H:%M:%S" -- i.e. @/YYYY-MM-DD/T/HH:MM:SS/@
77 @
78 -}
79
80 iso8601DateFormat :: Maybe String -> String
81 iso8601DateFormat mTimeFmt =
82 "%Y-%m-%d" ++ case mTimeFmt of
83 Nothing -> ""
84 Just fmt -> 'T' : fmt
85
86 -- | Format string according to <http://tools.ietf.org/html/rfc822#section-5 RFC822>.
87 rfc822DateFormat :: String
88 rfc822DateFormat = "%a, %_d %b %Y %H:%M:%S %Z"