Hi guys,
I’m having some trouble with utc_datetime
.
So I have a form that accept start_time
and end_time
which both in utc_datetime
and inside a bookings
table.
The problem is that I’m in Malaysia so the booking that is created will be in UTC and when I convert it to "Asia/Kuala_Lumpur"
using timex
, it will show a different time.
Timex.Timezone.convert(booking.end_time, "Asia/Kuala_Lumpur")
For example:
start_time
: 2019-09-08 22:00:00
end_time
: 2019-09-08 23:00:00
when convert it using timex
to "Asia/Kuala_Lumpur"
start_time
: 2019-09-09 06:00:00
end_time
: 2019-09-09 07:00:00
Now I see that I have 2 options:
- Use
naive_datetime
instead ofutc_datetime
and store the timezone in a separate column - Manipulate the
start_time
andend_time
from the form and shift it to the UTC timezone which I already tried and failed.
changeset
|> put_change(:start_time, Timex.shift(Timex.to_datetime(start_time, "Asia/Kuala_Lumpur"), "Etc/UTC"))
|> put_change(:end_time, Timex.shift(Timex.to_datetime(end_time, "Asia/Kuala_Lumpur"), "Etc/UTC"))
I’m not sure if I did it correctly or not and I’m not sure which is the best way
Thanks for your help in advance!