git.iko.soy/typeable/timezone-olson
on master help sign in
Add Semigroup instance for GHC >= 8.4.
7226ad8
Data/Time/LocalTime/TimeZone/Olson/Types.hs+17−1
@@ -1,8 +1,9 @@
1{-# OPTIONS_HADDOCK hide #-}
1{-# OPTIONS_HADDOCK hide #-}
2+{-# LANGUAGE CPP #-}
2-----------------------------------------------------------------------------
3-----------------------------------------------------------------------------
3-- |
4-- |
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
6--
7--
7-- Maintainer : Yitzchak Gale <gale@sefer.org>
8-- Maintainer : Yitzchak Gale <gale@sefer.org>
8-- Portability : portable
9-- Portability : portable
@@ -36,6 +37,9 @@ module Data.Time.LocalTime.TimeZone.Olson.Types
36)
37)
37where
38where
38
39
40+#if MIN_VERSION_base(4,11,0)
41+import Data.Semigroup (Semigroup(..))
42+#endif
39import Data.Monoid (Monoid(..))
43import Data.Monoid (Monoid(..))
40import Control.Monad (mplus)
44import Control.Monad (mplus)
41
45
@@ -71,6 +75,17 @@ data OlsonData =
71 }
75 }
72 deriving (Eq, Show)
76 deriving (Eq, Show)
73
77
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')
83+ where
84+ shiftBy n trans = trans {transIndex = n + transIndex trans}
85+
86+instance Monoid OlsonData where
87+ mempty = OlsonData [] [] [] Nothing
88+#else
74instance Monoid OlsonData where
89instance Monoid OlsonData where
75 mempty = OlsonData [] [] [] Nothing
90 mempty = OlsonData [] [] [] Nothing
76 mappend (OlsonData a b c d ) (OlsonData a' b' c' d') =
91 mappend (OlsonData a b c d ) (OlsonData a' b' c' d') =
@@ -78,6 +93,7 @@ instance Monoid OlsonData where
78 (b ++ b') (c ++ c') (d `mplus` d')
93 (b ++ b') (c ++ c') (d `mplus` d')
79 where
94 where
80 shiftBy n trans = trans {transIndex = n + transIndex trans}
95 shiftBy n trans = trans {transIndex = n + transIndex trans}
96+#endif
81
97
82-- | A @Transition@ represents a moment when the clocks change in a
98-- | A @Transition@ represents a moment when the clocks change in a
83-- timezone. It consists of a Unix timestamp value that indicates the
99-- timezone. It consists of a Unix timestamp value that indicates the