Setting Time Zones

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Setting Time Zones

Post by SeeCwriter »

In v3.x has the ability to set the time zone by 3/4 letter string. Works great. However, some of the short names are used multiple times for different posix strings. How are the various times zones to be set when they use the same short name?

Example:

Code: Select all

{"MST7MDT6",   "(GMT-07:00) Chihuahua, La Paz, Mazatlan" ,     "Mexico Standard Time 2",                "MST   ",    0   },
{"MST7MST7",   "(GMT-07:00) Arizona" ,                         "U.S. Mountain Standard Time",           "MST   ",    1   },
{"CST6CDT5",   "(GMT-06:00) Central Time (US and Canada" ,     "Central Standard Time",                 "CST   ",    1   },
{"CST6CST6",    "(GMT-06:00) Saskatchewan" ,                   "Canada Central Standard Time",          "CST   ",    1   },
How would I set an Arizona time zone when using "MST" as it will always select Mexico first?
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Setting Time Zones

Post by SeeCwriter »

Looking through the TimeZoneRecord array some more, I found more duplicate short names.
One example:

Code: Select all

{"CST-8CST-8",   "(GMT+08:00) Beijing, Chongqing, Hong Kong SAR, Urumqi" ,      "China Standard Time",    "CST",  0   },
How would I select China Standard Time, the search through the array will stop at Central Time (US and Canada)?
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Setting Time Zones

Post by TomNB »

Can you tell me which function you are using to set the time with a 3 letter string? Doing a search I found an example that does that, but there are no system functions that do. I think that is a very old example that got carried over and it needs to be updated. I think the timezones provided we only in the example and used to only be US way back when. The actual time functions example the was written for the timezone array \nburn\examples\TimeFunctions does not do that.

The timezone structure is:

struct TimeZoneRecord
{
const char *Posix;
const char *Description;
const char *Name;
const char *Short_name;
int bUsCanada;
};

So you can choose to set by anything other than Short_name. It is good to have Short_name in there, because whether someone is in the US or China, they are probably used to seeing the short name in a time display. You just can't set it that way.
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Setting Time Zones

Post by TomNB »

The list of time zones is in \nburn\nbrtos\source\timezones.cpp
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Setting Time Zones

Post by SeeCwriter »

I was using the function setTimeZoneByName() from the example program. You pass in a timezone name and beginning with the first entry in the array in timezones.cpp, it compares the short name of each timezone with the name passed in. I was just wondering how you envisioned it being used, since there are a handful of duplicate short names that set different timezones. If I pass in "CST", the first match will be Central Standard Time (U.S.). But I wouldn't be able to set China Standard Time. I looked up the abbreviations for world timezones, and there are indeed duplicate abbreviations, which makes no sense to me.
I decided the easiest way to handle this was to modify the handful of duplicate short names such that they are all unique. I put the modified file in the overload directory and it seems to work.
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Setting Time Zones

Post by TomNB »

Hi,

The example did not compensate for duplicate short names when making a global application and we will have to change that. I would avoid using short names for anything but display of the time zone along with other information if your product is global, use a different element in the TimeZoneRecord.
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Setting Time Zones

Post by SeeCwriter »

After more research into time zones, I put implementation on hold. There seems to be no standard for time zone names or abbreviations.

For my own education, could someone explain or point me to where I can find the answer about the purpose of alpha prefix to the GMT offsets used in the posix strings?

For example, Eastern Standard Time has a -5 hour offset and is set with "EST5". But there are at least 9 other time zones that have the same -5 hour offset, yet use different alpha prefixes (e.g. "CIST5" (Cayman Islands), "COT5" (Columbia Time), etc.) . Other than defining whether an offset is for standard time or daylight saving time, which could be done with the same character for all time zones, what purpose does the 3-4 alpha prefix serve?
sulliwk06
Posts: 118
Joined: Tue Sep 17, 2013 7:14 am

Re: Setting Time Zones

Post by sulliwk06 »

Wikipedia says that these abbreviations predate any kind of standard. They were created arbitrarily in each region and have been carried over since then.

https://en.wikipedia.org/wiki/List_of_t ... reviations
Time zones are often represented by alphabetic abbreviations such as "EST", "WST", and "CST", but these are not part of the international time and date standard ISO 8601 and their use as sole designator for a time zone is discouraged. Such designations can be ambiguous; for example, "CST" can mean China Standard Time (UTC+8), Cuba Standard Time (UTC−5), and (North American) Central Standard Time (UTC−6), and it is also a widely used variant of ACST (Australian Central Standard Time, UTC+9:30). Such designations predate both ISO 8601 and the internet era; in an earlier era, they were sufficiently unambiguous for many practical uses within a national context (for example, in railway timetables and business correspondence), but their ambiguity explains their deprecation in the internet era, when communications more often cannot rely on implicit geographic context to supply part of the meaning.
Post Reply