[Rd] proposal for use ICU for timezone convertion on windows and a draft patch
yu gong
yugong @end|ng |rom out|ook@com
Thu Jan 12 05:54:41 CET 2023
still work on it. this morning , I found the better and short sloution of this, the ucal_getDefaultTimeZone will return IANA formart zone name on windows.
so the main code for this issue listing here:
/* Longest currently is 31 chars */
static char Olson[64] = "";
/* use ucal_getDefaultTimeZone to get IANA default time zone name */
const char *getTZinfo(void)
{
UChar defaultzone[64];
UErrorCode status_default = U_ZERO_ERROR;
int32_t i = ucal_getDefaultTimeZone(defaultzone, ARRAYSIZE(defaultzone), &status_default);
if (U_SUCCESS(status_default)) {
wcstombs(Olson, defaultzone, 64);
Olson[63] = '\0';
#ifdef DEBUG
printf("TZ = %s\n", Olson);
#endif
return Olson;
}
else{
return "unknown";
}
}
I still maintain a longer version of this patch, but it should not needed if ucal_getDefaultTimeZone is reliable .
the longer version when ucal_getDefaultTimeZone fail to got IANA time zone name , it do extra step to got time zone name( 1 read current English time zone name from registry ; 2 read current region name from registry(this also affect conversion); 3 use ucal_getTimeZoneIDForWindowsID implement the conversion.)
please feel free to share your thoughts or feedbacks of this short version patch.
best regards,
Yu Gong
________________________________
From: R-devel <r-devel-bounces using r-project.org> on behalf of yu gong <yugong using outlook.com>
Sent: Wednesday, January 11, 2023 22:25
To: r-devel using r-project.org <r-devel using r-project.org>
Subject: [Rd] proposal for use ICU for timezone convertion on windows and a draft patch
Dear All,
Last week I found an issue about R Sys.timezone function on Windows and send email to this list. This week , I read quite a few docs and codes about windows time zone to IANA time zone conversion. and found in unicode.org's ICU library has a function ucal_getTimeZoneIDForWindowsID which do the time zone convert. Microsoft also use it for time zone convertion in dotnet 6 and 7.(https://github.com/dotnet/runtime/blob/main/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.c) .
IMHO, use this function to implement time zone convert on windows is better than R's hand-write conversion implementation, use the ICU , it will update the conversion when unicode org upgrade the ICU library and no more hand-write conversion code needed. Also RTools already included the ICU library,and R on windows build link ICU lib on default , so no additional library or tools need for use this function for time zone conversion.
so I wrote a quick and dirty patch use the ucal_getTimeZoneIDForWindowsID, I think maybe better discuss here before I send patch to bugs.r-project.org.
I put the patch on https://github.com/armgong/misc-r-patch/blob/main/registryTZ-ICU.diff.
this patch mainly do following three steps : 1 read current English time zone name from registry ; 2 read current region name from registry(this also affect conversion); 3 use ucal_getTimeZoneIDForWindowsID implement the conversion.
please feel free to share your thoughts or feedbacks of this patch. if it doable ,then I will modify it and send it to bugs.r-project.org
best regards,
Yu Gong
[[alternative HTML version deleted]]
______________________________________________
R-devel using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[[alternative HTML version deleted]]
More information about the R-devel
mailing list