@@ -91,6 +91,10 @@ defmodule DateTest do
91
91
assert Date . compare ( date4 , date5 ) == :gt
92
92
assert Date . compare ( date5 , date4 ) == :lt
93
93
assert Date . compare ( date5 , date5 ) == :eq
94
+
95
+ assert_raise ArgumentError ,
96
+ ~r/ cannot compare .*\n \n .* their calendars have incompatible day rollover moments/ ,
97
+ fn -> Date . compare ( date1 , % { date2 | calendar: FakeCalendar } ) end
94
98
end
95
99
96
100
test "before?/2 and after?/2" do
@@ -180,10 +184,14 @@ defmodule DateTest do
180
184
|> Date . convert! ( Calendar.Holocene )
181
185
|> Date . convert! ( Calendar.ISO ) == ~D[ 2000-01-01]
182
186
183
- assert Date . convert ( ~D[ 2016-02-03] , FakeCalendar ) == { :error , :incompatible_calendars }
184
-
185
187
assert Date . convert ( ~N[ 2000-01-01 00:00:00] , Calendar.Holocene ) ==
186
188
{ :ok , Calendar.Holocene . date ( 12000 , 01 , 01 ) }
189
+
190
+ assert Date . convert ( ~D[ 2016-02-03] , FakeCalendar ) == { :error , :incompatible_calendars }
191
+
192
+ assert_raise ArgumentError ,
193
+ "cannot convert ~D[2016-02-03] to target calendar FakeCalendar, reason: :incompatible_calendars" ,
194
+ fn -> Date . convert! ( ~D[ 2016-02-03] , FakeCalendar ) end
187
195
end
188
196
189
197
test "add/2" do
@@ -214,6 +222,10 @@ defmodule DateTest do
214
222
date2 = Calendar.Holocene . date ( 12000 , 01 , 14 )
215
223
assert Date . diff ( date1 , date2 ) == - 13
216
224
assert Date . diff ( date2 , date1 ) == 13
225
+
226
+ assert_raise ArgumentError ,
227
+ ~r/ cannot calculate the difference between .* because their calendars are not compatible/ ,
228
+ fn -> Date . diff ( date1 , % { date2 | calendar: FakeCalendar } ) end
217
229
end
218
230
219
231
test "shift/2" do
@@ -249,6 +261,10 @@ defmodule DateTest do
249
261
"unknown unit :months. Expected :year, :month, :week, :day" ,
250
262
fn -> Date . shift ( ~D[ 2012-01-01] , months: 12 ) end
251
263
264
+ assert_raise ArgumentError ,
265
+ "unsupported value nil for :day. Expected an integer" ,
266
+ fn -> Date . shift ( ~D[ 2012-02-29] , year: 1 , day: nil ) end
267
+
252
268
assert_raise ArgumentError ,
253
269
"cannot shift date by time scale unit. Expected :year, :month, :week, :day" ,
254
270
fn -> Date . shift ( ~D[ 2012-02-29] , % Duration { second: 86400 } ) end
@@ -266,4 +282,18 @@ defmodule DateTest do
266
282
Date . shift ( date , month: 1 )
267
283
end
268
284
end
285
+
286
+ test "utc_today/1" do
287
+ date = Date . utc_today ( )
288
+ assert date . year > 2020
289
+ assert date . calendar == Calendar.ISO
290
+
291
+ date = Date . utc_today ( Calendar.ISO )
292
+ assert date . year > 2020
293
+ assert date . calendar == Calendar.ISO
294
+
295
+ date = Date . utc_today ( Calendar.Holocene )
296
+ assert date . year > 12020
297
+ assert date . calendar == Calendar.Holocene
298
+ end
269
299
end
0 commit comments