@@ -1,8 +1,9 @@
1{-# OPTIONS_HADDOCK hide #-}
1{-# OPTIONS_HADDOCK hide #-}
2-----------------------------------------------------------------------------
3-----------------------------------------------------------------------------
4-- Module : Data.Time.LocalTime.TimeZone.Olson.Types
5-- Module : Data.Time.LocalTime.TimeZone.Olson.Types
5−-- Copyright : Yitzchak Gale 2010
6+-- Copyright : Yitzchak Gale 2018
7-- Maintainer : Yitzchak Gale <gale@sefer.org>
8-- Maintainer : Yitzchak Gale <gale@sefer.org>
8-- Portability : portable
9-- Portability : portable
@@ -14,7 +15,7 @@
15-- Both Version 1 and Version 2 timezone data can be represented.
16-- Both Version 1 and Version 2 timezone data can be represented.
17−{- Copyright (c) 2010 Yitzchak Gale. All rights reserved.
18+{- Copyright (c) 2018 Yitzchak Gale. All rights reserved.
18For licensing information, see the BSD3-style license in the file
19For licensing information, see the BSD3-style license in the file
19LICENSE that was originally distributed by the author together with
20LICENSE that was originally distributed by the author together with
20this file. -}
21this file. -}
@@ -36,22 +37,33 @@ module Data.Time.LocalTime.TimeZone.Olson.Types
40+#if MIN_VERSION_base(4,11,0)
41+import Data.Semigroup (Semigroup(..))
39import Data.Monoid (Monoid(..))
43import Data.Monoid (Monoid(..))
40import Control.Monad (mplus)
44import Control.Monad (mplus)
42-- | @OlsonData@ represents a full set of timezone data for a location.
46-- | @OlsonData@ represents a full set of timezone data for a location.
44−-- @OlsonData@ can represent timezone data from files in Version 1 format
48+-- @OlsonData@ can represent timezone data from files in Version 1, 2,
45−-- or Version 2 format. Version 1 format files can only contain timestamp
49+-- or 3 format.
46−-- values that can be represented in less than 32 bits, and cannot contain
51+-- Version 1 format files can only contain timestamp values that can
52+-- be represented in less than 32 bits, and cannot contain a POSIX TZ
49−-- In a Version 2 format file, the timezone data is split into two parts.
55+-- In a Version 2 format file, the timezone data is split into two
50−-- The first part contains timezone data for which all timestamp values
56+-- parts. The first part contains timezone data for which all
51−-- can be represented in less than 32 bits, and the second part contains
57+-- timestamp values can be represented in less than 32 bits, and the
52−-- timezone data for which 32 bits or more are required to represent
58+-- second part contains timezone data for which 32 bits or more are
53−-- timestamp values. The POSIX TZ string, if present, can only be rendered
59+-- required to represent timestamp values. The POSIX TZ string, if
60+-- present, can only be rendered in a Version 2 file, and appears
54−-- in a Version 2 file, and appears after both parts of the timezone data.
61+-- after both parts of the timezone data.
63+-- Version 3 format files relax certain syntax requirements for the
64+-- POSIX TZ string. Since we represent the POSIX TZ string as an
65+-- unparsed 'String', Version 3 is identical to Version 2 for our
55data OlsonData =
67data OlsonData =
56 OlsonData {
68 OlsonData {
57 olsonTransitions :: [Transition],
69 olsonTransitions :: [Transition],
@@ -63,6 +75,17 @@ data OlsonData =
64 deriving (Eq, Show)
76 deriving (Eq, Show)
78+#if MIN_VERSION_base(4,11,0)
79+instance Semigroup OlsonData where
80+ OlsonData a b c d <> OlsonData a' b' c' d' =
81+ OlsonData (a ++ map (shiftBy $ length b) a')
82+ (b ++ b') (c ++ c') (d `mplus` d')
84+ shiftBy n trans = trans {transIndex = n + transIndex trans}
86+instance Monoid OlsonData where
87+ mempty = OlsonData [] [] [] Nothing
66instance Monoid OlsonData where
89instance Monoid OlsonData where
67 mempty = OlsonData [] [] [] Nothing
90 mempty = OlsonData [] [] [] Nothing
68 mappend (OlsonData a b c d ) (OlsonData a' b' c' d') =
91 mappend (OlsonData a b c d ) (OlsonData a' b' c' d') =
@@ -70,6 +93,7 @@ instance Monoid OlsonData where
70 (b ++ b') (c ++ c') (d `mplus` d')
93 (b ++ b') (c ++ c') (d `mplus` d')
72 shiftBy n trans = trans {transIndex = n + transIndex trans}
95 shiftBy n trans = trans {transIndex = n + transIndex trans}
74-- | A @Transition@ represents a moment when the clocks change in a
98-- | A @Transition@ represents a moment when the clocks change in a
75-- timezone. It consists of a Unix timestamp value that indicates the
99-- timezone. It consists of a Unix timestamp value that indicates the