packages feed

hercules-ci-api-core 0.1.4.0 → 0.1.5.0

raw patch · 3 files changed

+90/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Hercules.API.DayOfWeek: Fri :: DayOfWeek
+ Hercules.API.DayOfWeek: Mon :: DayOfWeek
+ Hercules.API.DayOfWeek: Sat :: DayOfWeek
+ Hercules.API.DayOfWeek: Sun :: DayOfWeek
+ Hercules.API.DayOfWeek: Thu :: DayOfWeek
+ Hercules.API.DayOfWeek: Tue :: DayOfWeek
+ Hercules.API.DayOfWeek: Wed :: DayOfWeek
+ Hercules.API.DayOfWeek: data DayOfWeek
+ Hercules.API.DayOfWeek: fromNum :: (Integral n, Eq n) => n -> DayOfWeek
+ Hercules.API.DayOfWeek: fromNumMaybe :: (Num n, Eq n) => n -> Maybe DayOfWeek
+ Hercules.API.DayOfWeek: fromTime :: DayOfWeek -> DayOfWeek
+ Hercules.API.DayOfWeek: instance Control.DeepSeq.NFData Hercules.API.DayOfWeek.DayOfWeek
+ Hercules.API.DayOfWeek: instance Data.Aeson.Types.FromJSON.FromJSON Hercules.API.DayOfWeek.DayOfWeek
+ Hercules.API.DayOfWeek: instance Data.Aeson.Types.ToJSON.ToJSON Hercules.API.DayOfWeek.DayOfWeek
+ Hercules.API.DayOfWeek: instance Data.Swagger.Internal.Schema.ToSchema Hercules.API.DayOfWeek.DayOfWeek
+ Hercules.API.DayOfWeek: instance GHC.Classes.Eq Hercules.API.DayOfWeek.DayOfWeek
+ Hercules.API.DayOfWeek: instance GHC.Generics.Generic Hercules.API.DayOfWeek.DayOfWeek
+ Hercules.API.DayOfWeek: instance GHC.Show.Show Hercules.API.DayOfWeek.DayOfWeek
+ Hercules.API.DayOfWeek: toNum :: Num n => DayOfWeek -> n
+ Hercules.API.DayOfWeek: toTime :: DayOfWeek -> DayOfWeek

Files

CHANGELOG.md view
@@ -4,6 +4,12 @@  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +## [0.1.5.0] - 2022-11-15++### Added++ - `DayOfWeek`+ ## [0.1.4.0] - 2022-03-15  ### Updated@@ -32,6 +38,8 @@  - Initial release, split out of hercules-ci-api +[0.1.5.0]: https://github.com/hercules-ci/hercules-ci-agent/releases/tag/hercules-ci-api-core-0.1.5.0+[0.1.4.0]: https://github.com/hercules-ci/hercules-ci-agent/releases/tag/hercules-ci-api-core-0.1.4.0 [0.1.3.0]: https://github.com/hercules-ci/hercules-ci-agent/releases/tag/hercules-ci-api-core-0.1.3.0 [0.1.2.0]: https://github.com/hercules-ci/hercules-ci-agent/releases/tag/hercules-ci-api-core-0.1.2.0 [0.1.1.0]: https://github.com/hercules-ci/hercules-ci-agent/releases/tag/hercules-ci-api-core-0.1.1.0
hercules-ci-api-core.cabal view
@@ -1,7 +1,7 @@ cabal-version: 1.12  name:           hercules-ci-api-core-version:        0.1.4.0+version:        0.1.5.0 synopsis:       Types and convenience modules use across Hercules CI API packages category:       API, CI, Testing, DevOps, Nix homepage:       https://github.com/hercules-ci/hercules-ci-agent#readme@@ -20,6 +20,7 @@  library   exposed-modules:+      Hercules.API.DayOfWeek       Hercules.API.Id       Hercules.API.Name       Hercules.API.Prelude
+ src/Hercules/API/DayOfWeek.hs view
@@ -0,0 +1,80 @@+{-# LANGUAGE DeriveAnyClass #-}++-- This module pins down the details of week days in the API. It's boilerplate-y+-- but that makes it robust.++-- | A day of week type. Integer representations are not used in the API, but+-- are provided for convenience and will not change.+module Hercules.API.DayOfWeek+  ( DayOfWeek (..),++    -- * Conversions for @time@ package+    toTime,+    fromTime,++    -- * Optional, stable, opinionated integer conversions+    toNum,+    fromNumMaybe,+    fromNum,+  )+where++import Control.DeepSeq (NFData)+import Data.Aeson (FromJSON, ToJSON)+import Data.Maybe (fromJust)+import Data.Swagger (ToSchema)+import qualified Data.Time+import GHC.Generics (Generic)+import Prelude (Eq, Integral, Maybe (..), Num (..), Show, mod)++-- | Day of week representation used in the API.+data DayOfWeek = Mon | Tue | Wed | Thu | Fri | Sat | Sun+  deriving (Generic, Show, Eq, NFData, ToJSON, FromJSON, ToSchema)++-- | Conversion to @time@ package representation.+toTime :: DayOfWeek -> Data.Time.DayOfWeek+toTime Mon = Data.Time.Monday+toTime Tue = Data.Time.Tuesday+toTime Wed = Data.Time.Wednesday+toTime Thu = Data.Time.Thursday+toTime Fri = Data.Time.Friday+toTime Sat = Data.Time.Saturday+toTime Sun = Data.Time.Sunday++-- | Conversion from @time@ package representation.+fromTime :: Data.Time.DayOfWeek -> DayOfWeek+fromTime Data.Time.Monday = Mon+fromTime Data.Time.Tuesday = Tue+fromTime Data.Time.Wednesday = Wed+fromTime Data.Time.Thursday = Thu+fromTime Data.Time.Friday = Fri+fromTime Data.Time.Saturday = Sat+fromTime Data.Time.Sunday = Sun++-- | Conversion to integers where 'Mon' -> 1, 'Sun' -> 7+toNum :: Num n => DayOfWeek -> n+toNum Mon = 1+toNum Tue = 2+toNum Wed = 3+toNum Thu = 4+toNum Fri = 5+toNum Sat = 6+toNum Sun = 7++-- | Conversion from integers where @1 -> Just 'Mon'@, @7 -> Just 'Sun'@, @outside of 1..7 -> Nothing@+fromNumMaybe :: (Num n, Eq n) => n -> Maybe DayOfWeek+fromNumMaybe 1 = Just Mon+fromNumMaybe 2 = Just Tue+fromNumMaybe 3 = Just Wed+fromNumMaybe 4 = Just Thu+fromNumMaybe 5 = Just Fri+fromNumMaybe 6 = Just Sat+fromNumMaybe 7 = Just Sun+fromNumMaybe _ = Nothing++-- | Conversion from integers where @{...,-7,0,7,...} -> Just 'Sun'@, @{...,-6,1,8,...} -> Just 'Mon'@, etc.+--+-- Requires a sensible implementation of the 'Integral' 'mod' method that returns non-negative numbers.+-- 'Integer', 'Int', 'Int8', etc are ok. So is the 'Word' family of types, though beware of 'minBound' overflows.+fromNum :: (Integral n, Eq n) => n -> DayOfWeek+fromNum n = fromJust (fromNumMaybe (1 + (n - 1) `mod` 7))