Skip to content

Commit

Permalink
Add tests for Date.until, Date.next and Date.previous. (#6606)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryTravis authored May 9, 2023
1 parent d8b9269 commit 7119811
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ type Date
Period.between self end

## Counts the days between self (inclusive) and the provided end date
(exclusive).
(exclusive, or inclusive if include_end_date=True).

Produces a warning for a Date that is before epoch start.
See `Date_Time.enso_epoch_start`.
Expand Down
19 changes: 19 additions & 0 deletions test/Tests/src/Data/Time/Date_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ spec_with name create_new_date parse_date =
(create_new_date 2000 7 1).end_of Date_Period.Quarter . should_equal (Date.new 2000 9 30)
(create_new_date 2000 6 30).end_of Date_Period.Quarter . should_equal (Date.new 2000 6 30)

Test.specify "should allow to compute the next Date_Period after a date" <|
create_new_date 2000 2 1 . next Date_Period.Day . should_equal <| create_new_date 2000 2 2
create_new_date 2000 2 1 . next Date_Period.Month . should_equal <| create_new_date 2000 3 1
create_new_date 2000 2 1 . next Date_Period.Year . should_equal <| create_new_date 2001 2 1

Test.specify "should allow to compute the previous Date_Period after a date" <|
create_new_date 2000 2 1 . previous Date_Period.Day . should_equal <| create_new_date 2000 1 31
create_new_date 2000 2 1 . previous Date_Period.Month . should_equal <| create_new_date 2000 1 1
create_new_date 2000 2 1 . previous Date_Period.Year . should_equal <| create_new_date 1999 2 1

Test.specify "should allow to compute the Period between two dates." <|
create_new_date 2000 2 1 . until (create_new_date 2000 2 12) . should_equal <| Period.new 0 0 11
create_new_date 2000 2 1 . until (create_new_date 2000 12 12) . should_equal <| Period.new 0 10 11
create_new_date 2000 2 1 . until (create_new_date 2010 2 12) . should_equal <| Period.new 10 0 11

create_new_date 2000 2 12 . until (create_new_date 2000 2 1) . should_equal <| Period.new 0 0 -11
create_new_date 2000 12 12 . until (create_new_date 2000 2 1) . should_equal <| Period.new 0 -10 -11
create_new_date 2010 2 12 . until (create_new_date 2000 2 1) . should_equal <| Period.new -10 0 -11

Test.specify "should allow to compute the number of days until a date" <|
create_new_date 2000 2 1 . days_until (create_new_date 2000 2 1) . should_equal 0
create_new_date 2000 2 1 . days_until (create_new_date 2000 2 2) . should_equal 1
Expand Down

0 comments on commit 7119811

Please sign in to comment.