forked from finos/morphir-elm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalDateTests.elm
128 lines (119 loc) · 4.85 KB
/
LocalDateTests.elm
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
module Morphir.SDK.LocalDateTests exposing (..)
{-
Copyright 2020 Morgan Stanley
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}
import Date as Date exposing (Unit(..), add, fromCalendarDate)
import Expect
import Morphir.SDK.LocalDate as LocalDate exposing (..)
import Test exposing (..)
import Time exposing (Month(..))
mathTests : Test
mathTests =
describe "date maths"
[ test "add day" <|
\_ ->
Date.fromCalendarDate 2020 Jan 1
|> LocalDate.addDays 1
|> Expect.equal (Date.fromCalendarDate 2020 Jan 2)
, test "subtract day" <|
\_ ->
Date.fromCalendarDate 2020 Jan 2
|> LocalDate.addDays -1
|> Expect.equal (Date.fromCalendarDate 2020 Jan 1)
, test "add week" <|
\_ ->
Date.fromCalendarDate 2020 Jan 7
|> LocalDate.addWeeks 1
|> Expect.equal (Date.fromCalendarDate 2020 Jan 14)
, test "subtract week" <|
\_ ->
Date.fromCalendarDate 2020 Jan 14
|> LocalDate.addWeeks -1
|> Expect.equal (Date.fromCalendarDate 2020 Jan 7)
, test "add month" <|
\_ ->
Date.fromCalendarDate 2020 Jan 1
|> LocalDate.addMonths 1
|> Expect.equal (Date.fromCalendarDate 2020 Feb 1)
, test "subtract month" <|
\_ ->
Date.fromCalendarDate 2020 Feb 1
|> LocalDate.addMonths -1
|> Expect.equal (Date.fromCalendarDate 2020 Jan 1)
, test "add year" <|
\_ ->
Date.fromCalendarDate 2020 Jan 1
|> LocalDate.addYears 1
|> Expect.equal (Date.fromCalendarDate 2021 Jan 1)
, test "subtract year" <|
\_ ->
Date.fromCalendarDate 2020 Feb 1
|> LocalDate.addYears -1
|> Expect.equal (Date.fromCalendarDate 2019 Feb 1)
]
constructorTests : Test
constructorTests =
describe "constructor tests"
[ test "valid fromISO" <|
\_ ->
LocalDate.fromISO "2020-01-01"
|> Expect.equal (Date.fromIsoString "2020-01-01" |> Result.toMaybe)
, test "invalid fromISO parsing" <|
\_ ->
LocalDate.fromISO "2020-01 hello"
|> Expect.equal Nothing
, test "invalid fromISO numeric" <|
\_ ->
LocalDate.fromISO "2020-01-55"
|> Expect.equal Nothing
, test "valid fromParts" <|
\_ ->
LocalDate.fromParts 2020 1 1
|> Expect.equal (Just (Date.fromCalendarDate 2020 Jan 1))
, test "invalid month fromParts" <|
\_ ->
LocalDate.fromParts 2020 13 1
|> Expect.equal Nothing
, test "invalid day fromParts" <|
\_ ->
LocalDate.fromParts 2020 2 30
|> Expect.equal Nothing
, test "valid fromCalendarDate" <|
\_ ->
LocalDate.fromCalendarDate 2023 December 25
|> Expect.equal (Date.fromCalendarDate 2023 Dec 25)
, test "invalid but pinned fromCalendarDate" <|
\_ ->
LocalDate.fromCalendarDate 2023 December 39
|> Expect.equal (Date.fromCalendarDate 2023 Dec 31)
, test "valid fromOrdinalDate" <|
\_ ->
LocalDate.fromOrdinalDate 2023 15
|> Expect.equal (Date.fromCalendarDate 2023 Jan 15)
, test "valid fromRataDie" <|
\_ ->
LocalDate.fromRataDie 1
|> Expect.equal (Date.fromCalendarDate 1 Jan 1)
, test "valid contemporary fromRataDie" <|
\_ ->
LocalDate.fromRataDie 738860
|> Expect.equal (Date.fromCalendarDate 2023 Dec 6)
, test "valid toRataDie" <|
\_ ->
Date.fromCalendarDate 1 Jan 1
|> LocalDate.toRataDie
|> Expect.equal 1
, test "valid contemporary toRataDie" <|
\_ ->
LocalDate.toRataDie (Date.fromCalendarDate 2023 Dec 6)
|> Expect.equal 738860
]