Skip to content

Commit 9f79573

Browse files
committed
Change time validator to be before or same time
1 parent 5292ee3 commit 9f79573

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/code_corps/validators/time_validator.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ defmodule CodeCorps.Validators.TimeValidator do
1111
def validate_time_after(%{data: data} = changeset, field) do
1212
previous_time = Map.get(data, field)
1313
current_time = Changeset.get_change(changeset, field)
14-
case current_time |> Timex.after?(previous_time) do
14+
is_after = current_time |> Timex.after?(previous_time)
15+
is_equal = current_time |> Timex.equal?(previous_time)
16+
after_or_equal = is_after || is_equal
17+
case after_or_equal do
1518
true -> changeset
1619
false -> Changeset.add_error(changeset, field, "cannot be before the last recorded time")
1720
end

0 commit comments

Comments
 (0)