Expected DateTime and Timezone logic

Hi there,

I need to add a DateTime field to a record which will persist the chosen Timezone so I can display it on the template. I’m having trouble figuring out the right way to accomplish this:

Here are my steps to replicate:

  1. Set API Timezone to UTC -4 Eastern Time
  2. Go to record with DateTime field
  3. Update the field value to be 10/24/2024 14:00:00 UTC +1 (CET - Belgrade)
    For clarity, this CET timezone is what I want to display in my template
  4. Click Save
  5. Refresh page
  6. Field value is now changed to 10/24/2024 08:00:00 UTC -4 (Eastern Time)
  7. Content API in CDA Playground returns “2024-10-24 T08:00:00 -04:00”,

How do I know what the original chosen Timezone is if it auto-converts based on the API Timezone?

Thanks,
Colin

Hey @colin.cole,

Sorry, this is a known issue and frankly a weakness in our current DateTime implementation :frowning: I agree with you that this is not ideal, and I’ve previously tried to convince the devs to change this behavior, but it is not something they want to change right now. I’m sorry. It could be a feature request here, or as a workaround, you can make another field to store the time zone info with your own time zone strings.

To be clear, that means you would need two separate fields:

  1. The time itself (probably stored as a JSON object that you define that would have hh:mm data, rather than our native datetime field data)
  2. Another plaintext field acting as a dropdown where your editors could select one of several IANA time zone strings, like “America/Los_Angeles” or “Etc/UTC” or “Europe/Brussels” for example

Your frontend would then query these two fields and then display them accordingly. Unfortunately the UI of #1 (time entry) won’t be as nice unless you add some custom code (like via a plugin and a custom form field), or just provide good help text for what to enter.

If it would help, I can make you an example plugin that would do something like this?


Alternatively, the super-simple version (that would have no validation and can’t be easily parsed) would just to be have a plaintext field where your editors could enter the time and zone as a regular plaintext string, like “17:00 CEST”.

I’m sorry for the hassle, and please let me know if an example plugin would help.

@colin.cole,

Just wanted to check in on this. Did you manage to find a good solution? If an example would help, please let me know.

Hey @roger , sorry forgot to reply here. Thanks for the explanation, that confirms I’m not crazy lol. I think we’re gonna go ahead and create a plaintext field for the time being.

1 Like

Sounds good. You’re not crazy, as far as I can tell :wink:

It’s just a small flaw in our system. Sorry about that!