• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

msakai / data-interval / 80

30 Aug 2025 08:23PM UTC coverage: 86.789% (+0.09%) from 86.702%
80

push

github

Bodigrim
Fix warnings

1 of 4 new or added lines in 4 files covered. (25.0%)

87 existing lines in 4 files now uncovered.

992 of 1143 relevant lines covered (86.79%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/Data/IntervalRelation.hs
1
{-# OPTIONS_GHC -Wall #-}
2
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
3
{-# LANGUAGE Safe #-}
4
-----------------------------------------------------------------------------
5
-- |
6
-- Module      :  Data.IntervalRelation
7
-- Copyright   :  (c) Masahiro Sakai 2016
8
-- License     :  BSD-style
9
--
10
-- Maintainer  :  masahiro.sakai@gmail.com
11
-- Stability   :  provisional
12
--
13
-- Interval relations and their algebra.
14
--
15
-----------------------------------------------------------------------------
16
module Data.IntervalRelation
17
  ( Relation(..)
18
  , invert
19
  )
20
  where
21

22
import Data.Data (Data)
23
import GHC.Generics (Generic)
24

25
-- | Describes how two intervals @x@ and @y@ can be related.
26
-- See [Allen's interval algebra](https://en.wikipedia.org/wiki/Allen%27s_interval_algebra)
27
-- and [Intervals and their relations](http://marcosh.github.io/post/2020/05/04/intervals-and-their-relations.html).
28
data Relation
29
  = Before
30
  -- ^ Any element of @x@ is smaller than any element of @y@,
31
  -- and intervals are not connected. In other words, there exists an element
32
  -- that is bigger than any element of @x@ and smaller than any element of @y@.
33
  | JustBefore
34
  -- ^ Any element of @x@ is smaller than any element of @y@,
35
  -- but intervals are connected and non-empty. This implies that intersection
36
  -- of intervals is empty, and union is a single interval.
37
  | Overlaps
38
  -- ^ Intersection of @x@ and @y@ is non-empty,
39
  -- @x@ start and finishes earlier than @y@. This implies that union
40
  -- is a single interval, and @x@ finishes no earlier than @y@ starts.
41
  | Starts
42
  -- ^ @x@ is a proper subset of @y@,
43
  -- and they share lower bounds.
44
  | During
45
  -- ^ @x@ is a proper subset of @y@,
46
  -- but they share neither lower nor upper bounds.
47
  | Finishes
48
  -- ^ @x@ is a proper subset of @y@,
49
  -- and they share upper bounds.
50
  | Equal
51
  -- ^ Intervals are equal.
52
  | FinishedBy
53
  -- ^ Inverse of 'Finishes'.
54
  | Contains
55
  -- ^ Inverse of 'During'.
56
  | StartedBy
57
  -- ^ Inverse of 'Starts'.
58
  | OverlappedBy
59
  -- ^ Inverse of 'Overlaps'.
60
  | JustAfter
61
  -- ^ Inverse of 'JustBefore'.
62
  | After
63
  -- ^ Inverse of 'Before'.
NEW
64
  deriving (Eq, Ord, Enum, Bounded, Show, Read, Generic, Data)
×
65

66
-- | Inverts a relation, such that @'invert' ('Data.Interval.relate' x y) = 'Data.Interval.relate' y x@
67
invert :: Relation -> Relation
68
invert relation = case relation of
1✔
69
  Before       -> After
1✔
70
  JustBefore   -> JustAfter
1✔
71
  Overlaps     -> OverlappedBy
1✔
72
  Starts       -> StartedBy
1✔
73
  During       -> Contains
1✔
74
  Finishes     -> FinishedBy
1✔
75
  Equal        -> Equal
1✔
76
  FinishedBy   -> Finishes
1✔
77
  Contains     -> During
1✔
78
  StartedBy    -> Starts
1✔
79
  OverlappedBy -> Overlaps
1✔
80
  JustAfter    -> JustBefore
1✔
81
  After        -> Before
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc