Convert zone time code in zone number
Hi all,
We're developing a medical appointment app that connects doctors' schedules to an appointment provider.
The provider is returning us the appointment in the following format:
Thu Jul 03 08:20:00 CEST 2025
It means, 03 july 2025 at 08:20:00 Central European Summer Time (UTC+2)
But we need the following format:
2025-07-03 08:20:00+02:00
Is there any option to convert zone time code (CEST) to a UTC+x ?
How to convert zone time code (CEST, CET, ET, EDT, etc..) in its zone time in UTC (UTC+2, UTC+1, UTC-5, etc..) ?
Best regards
Comments
I think it is a good use-case for embedded python. I asked gpt and it suggested the following python code:
from datetime import datetime
from zoneinfo import ZoneInfo
# Original string
input_str = "Thu Jul 03 08:20:00 CEST 2025"# Strip the abbreviation since it's not useful for parsing# Replace it with an IANA timezone# Let's assume "CEST" corresponds to Europe/Paris
input_str_cleaned = input_str.replace("CEST", "").strip()
# Parse the datetime
dt_naive = datetime.strptime(input_str_cleaned, "%a %b %d %H:%M:%S %Y")
# Localize to the correct zone
dt_aware = dt_naive.replace(tzinfo=ZoneInfo("Europe/Paris"))
# Format in ISO format with UTC offset
print(dt_aware.isoformat()) # e.g., '2025-07-03T08:20:00+02:00'Also it suggested to make a mapping for CEST/CET:
tz_abbreviation_map = {
"CEST": "Europe/Paris",
"CET": "Europe/Paris",
"EDT": "America/New_York",
"EST": "America/New_York",
"PST": "America/Los_Angeles",
# Add more mappings as needed
}
Thanks, Evgeny, as always.
It's not a bad idea to use an abbreviation map and Python for this. I can create a table with the code name and replace it with the UTC value.
https://www.timeanddate.com/time/zones/
This is a complete list of time zone codes and their UTC values.
What's the problem? Some are duplicated.
According to this list, Thursday, July 3rd at 08:20:00 AST, 2025 could be:
AST: Arabia Standard Time - UTC+03
AST: Atlantic Standard Time - UTC-04
Perhaps there's a mistake in the list.
If you're looking to simply convert timezone codes to the UTC offset, I'd setup a simple utility that returns the desired string based on a case statement.
Something like:
ClassMethod DisplayTimezoneToUTCOffset(pInput as%String) As%String{
Quit$CASE($ZCONVERT(pInput,"U"),
"CEST":"+02:00",
"CET":"+01:00",
"BST":"+01:00",
:"")
}If you then want to build the entire string, you could do similar to above for the months, and then have the following:
Class Demo.Utils.ExampleUtils.TimeConvert
{
ClassMethod DisplayDateTimeToLiteral(pInput as%String) As%String{
// Deconstruct the input string into it's logical parts.// Variables starting d are "display" values that will be converted later.Set DayOfWeek = $P(pInput," ",1) //Not usedSet dMonth = $P(pInput," ",2)
Set Day = $P(pInput," ",3)
Set Time = $P(pInput," ",4)
Set dTimeZone = $P(pInput," ",5)
Set Year = $P(pInput," ",6)
//Return final timestampQuit Year_"-"_..DisplayMonthToLiteral(dMonth)_"-"_Day_" "_Time_..DisplayTimezoneToUTCOffset(dTimeZone)
}
ClassMethod DisplayTimezoneToUTCOffset(pInput as%String) As%String{
Quit$CASE($ZCONVERT(pInput,"U"),
"CEST":"+02:00",
"CET":"+01:00",
"BST":"+01:00",
:"")
}
ClassMethod DisplayMonthToLiteral(pInput as%String) As%String{
Quit$CASE($ZCONVERT(pInput,"U"),
"JAN":"01",
"FEB":"02",
"MAR":"03",
//etc. etc."JUL":"07",
:"")
}
}
Which then gives the following:
.png)