Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time zone parser bug, github #1417 #1866

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions libdispatch/nctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,23 @@ cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTi
char basetime_1[CD_MAX_CHARTIME];
char basetime_2[CD_MAX_CHARTIME];
char basetime[2 * CD_MAX_CHARTIME + 1];
int nconv1, nconv2, nconv;
int nconv;

/* Parse the relunits */
/* Allow ISO-8601 "T" date-time separator as well as blank separator */
nconv1 = sscanf(relunits,"%s since %[^T]T%s",charunits,basetime_1,basetime_2);
if(nconv1==EOF || nconv1==0){
cdError("Error on relative units conversion, string = %s\n",relunits);
return 1;
/* Parse the relunits. First parse assuming white space only. */
nconv = sscanf(relunits,"%s since %s %s",charunits,basetime_1,basetime_2);

/* Handle ISO-8601 "T" date-time separator in place of blank separator. */
if (nconv!=EOF && nconv>=2) {
if (strchr (basetime_1, 'T') != NULL) {
nconv = sscanf(relunits,"%s since %[^T]T%s",charunits,basetime_1,basetime_2);
}
}
nconv2 = sscanf(relunits,"%s since %s %s",charunits,basetime_1,basetime_2);
if(nconv2==EOF || nconv2==0){

if(nconv==EOF || nconv==0){
cdError("Error on relative units conversion, string = %s\n",relunits);
return 1;
}
if(nconv1 < nconv2) {
nconv = nconv2;
} else {
nconv = sscanf(relunits,"%s since %[^T]T%s",charunits,basetime_1,basetime_2);
}

/* Get the units */
cdTrim(charunits,CD_MAX_RELUNITS);
if(!strncasecmp(charunits,"sec",3) || !strcasecmp(charunits,"s")){
Expand Down