File: ConvertBack.hs

package info (click to toggle)
ghc 8.0.1-17
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 55,080 kB
  • ctags: 9,332
  • sloc: haskell: 363,120; ansic: 54,900; sh: 4,782; makefile: 974; perl: 542; asm: 315; python: 306; xml: 154; lisp: 7
file content (40 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Test.ConvertBack where

import Data.Time.Calendar.OrdinalDate
import Data.Time.Calendar.Julian
import Data.Time.Calendar.WeekDate
import Data.Time.Calendar
import Test.TestUtil

checkDay :: (Show t) => (Day -> t) -> (t -> Day) -> (t -> Maybe Day) -> Day -> String
checkDay encodeDay decodeDay decodeDayValid day = let
    st    = encodeDay day
    day'  = decodeDay st
    mday' = decodeDayValid st

    a = if day /= day'
          then unwords [ show day, "-> "
                           , show st,  "-> "
                           , show day'
                           , "(diff", show (diffDays day' day) ++ ")" ]
          else ""

    b = if Just day /= mday'
          then unwords [show day, "->", show st, "->", show mday']
          else ""
    in a ++ b

checkers :: [Day -> String]
checkers
  = [ checkDay toOrdinalDate (\(y,d) -> fromOrdinalDate y d) (\(y,d) -> fromOrdinalDateValid y d)
    , checkDay toWeekDate (\(y,w,d) -> fromWeekDate y w d) (\(y,w,d) -> fromWeekDateValid y w d)
    , checkDay toGregorian (\(y,m,d) -> fromGregorian y m d) (\(y,m,d) -> fromGregorianValid y m d)
    , checkDay toJulian (\(y,m,d) -> fromJulian y m d) (\(y,m,d) -> fromJulianValid y m d) ]

days :: [Day]
days = [ModifiedJulianDay 50000 .. ModifiedJulianDay 50200] ++
    (fmap (\year -> (fromGregorian year 1 4)) [1980..2000])

convertBack :: Test
convertBack = pureTest "convertBack" $
    diff "" $ concatMap (\ch -> concatMap ch days) checkers