Recently we got a requirement that we have to get the current system timezone and send as a POSIX formatted string(PST8PDT,M3.2.0/2,M11.1.0/2).
We are in windows environment and using C++ language.
TIME_ZONE_INFORMATION tzInfo; GetTimeZoneInformation(&tzInfo);
By using the above code, we got the current timezone information and it has standard name and day light name(gives full description not a abbreviate name), UTC bias(minutes)
But how to get the formatted POSIX formatted timezone string ?
POSIX formatted string = Abbreviated DST off timezone+UTC offset+Abbreviated DST on timezone+rule for DST change
We checked in chrono and POCO libraries not able to find any APIs which does this conversion.
Reason we need this conversion is we are communicating to ONVIF complaint device where we have to set current system time and timezone to the device.
So we are calling SetSystemDateAndTime(refer the below wsdl file) API which needs this timezone information https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl
Please share your inputs
In general, this won't be possible. Some time zones are not sufficiently regular with respect to the Gregorian calendar in order for a POSIX timezone to represent more than a single year.
For example "Asia/Gaza" is based on the Islamic calendar. The POSIX timezone "EET-2EEST,M3.5.6,M10.5.6" will represent it only from 2023-2026. And "EET-2EEST,M3.5.0/0,M10.5.6" worked for this timezone only during 2022.
Another problem is that some time zones are on "permanent DST" and there is no way to represent this in POSIX timezones (without an extension to the POSIX syntax).
Finally, almost no timezone can be represented by a single POSIX timezone over the span of decades.
For example the POSIX timezone you reference may represent "America/Los_Angeles", but only since 2007-03-11 (the past 17 years). Before that it was "PST8PDT,M4.1.0,M10.5.0" (compared to "PST8PDT,M3.2.0,M11.1.0").
The best you can do is transmit a POSIX timezone string that will represent this year, but possibly not last year or next year. And even that will be an approximation for those timezones on permanent DST.
Due to these complications and compromises, no such conversion exists that I am aware of. I have attempted to create such a utility, and gave up after running into these hurdles to a completely accurate solution.
Your best bet is to refine your requirement to a limited number of time zones over a limited range of time, and build the map manually.