Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Fix user-session timestamp validation for IST #197

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/dbservice/utils/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ defmodule Dbservice.Utils.Util do
import Ecto.Query

def invalidate_future_date(changeset, date_field_atom) do
today = Date.utc_today()
utc_now = DateTime.utc_now()

ist_now = DateTime.add(utc_now, 5 * 60 * 60 + 30 * 60, :second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format we need is UTC as date_to_validate is also in UTC format. Using this will make ist_now format to look like: #DateTime<yyyy-mm-dd hh:mm:ss+05:30 IST Asia/Kolkata>


date_to_validate = get_field(changeset, date_field_atom)

if Date.compare(date_to_validate, today) == :gt do
if DateTime.compare(date_to_validate, ist_now) == :gt do
add_error(changeset, date_field_atom, "cannot be later than today")
else
changeset
Expand Down
Loading