Form for utc_datetime

You have it mostly correct.

TzDatetime.handle_datetime(cs, input_datetime: :start_time, datetime: :start_time)

I’d suggest a virtual field for the input separate to the field storing the utc_datetime, but this should work. Also you don’t need to require TzDatetime. There are no macros involved here so just calling the functions is enough.

The timezone field you’ll need to set somehow either by letting the user submit the value or adding it to the changeset based on other information your system has.

As for the original_offset: You shouldn’t need to care about that at all. It’s set by handle_datetime/2 and read by original_datetime/2. The latter will return different values if there’s a missmatch detected between the stored offset and the offset based on your current timezone database.

1 Like