|
|
| version 1.95, 2015/09/18 00:08:12 | version 1.97, 2015/09/22 13:53:04 |
|---|---|
| Line 80 static int to_month(int imonth) { | Line 80 static int to_month(int imonth) { |
| return max(1, min(imonth, 12)) -1; | return max(1, min(imonth, 12)) -1; |
| } | } |
| static const char *skip_number_throw(char *string, char c, const char *valid){ | |
| if(!valid[0]) | |
| throw Exception("date.format", 0, "invalid character '%c' after number in '%s'", c, string); | |
| if(!strcmp(valid, "+-Z")) | |
| throw Exception("date.format", 0, "invalid timezone character '%c' after number in '%s'", c, string); | |
| throw Exception("date.format", 0, "number delimiter '%c'%s expected, but found '%c' in date '%s'", | |
| valid[0], valid[strlen(valid)-1] == 'Z' ? " or timezone":"", c, string); | |
| } | |
| static char *skip_number(char* string, const char *valid_delim, char *delim) { | static char *skip_number(char* string, const char *valid_delim, char *delim) { |
| if(string) { | if(string) { |
| char *str=string; | char *str=string; |
| Line 88 static char *skip_number(char* string, c | Line 98 static char *skip_number(char* string, c |
| // skipping +- | // skipping +- |
| if(str[0]=='-' || str[0]=='+') str++; | if(str[0]=='-' || str[0]=='+') str++; |
| // at least one digit should be present | // at least one digit should be present |
| if(!isdigit(*(str++))) | if(!str[0]) |
| throw Exception("date.format", 0, "invalid number in date specification '%s'", string); | throw Exception("date.format", 0, "number expected in date '%s'", string); |
| if(!isdigit(str[0])) | |
| throw Exception("date.format", 0, "'%c' must be number in date '%s'", str[0], string); | |
| str++; | |
| // skipping digits | // skipping digits |
| while(isdigit(str[0])) str++; | while(isdigit(str[0])) str++; |
| // skipping trailing whitespace | // skipping trailing whitespace |
| Line 98 static char *skip_number(char* string, c | Line 111 static char *skip_number(char* string, c |
| // delimiter check | // delimiter check |
| if(char c=str[0]){ | if(char c=str[0]){ |
| if(!strchr(valid_delim, c)) | if(!strchr(valid_delim, c)) |
| throw Exception("date.format", 0, "invalid character '%c' in date specification '%s'", c, string); | skip_number_throw(string, c, valid_delim); |
| if(delim) | if(delim) |
| *delim=c; | *delim=c; |
| str[0]=0; | str[0]=0; |
| Line 147 static char *numeric_tz(char prefix, cha | Line 160 static char *numeric_tz(char prefix, cha |
| char *buf=new(PointerFreeGC) char[size]; | char *buf=new(PointerFreeGC) char[size]; |
| strcpy(buf, prefix=='+' ? "SUB-":"SUB+"); | strcpy(buf, prefix=='+' ? "SUB-":"SUB+"); |
| strncpy(buf+4, tz, cur-tz); | strncpy(buf+4, tz, cur-tz); |
| buf[size]=0; | buf[size-1]=0; |
| return buf; | return buf; |
| } | } |
| Line 172 tm cstr_to_time_t(char *cstr, const char | Line 185 tm cstr_to_time_t(char *cstr, const char |
| const char *year, *month, *mday; | const char *year, *month, *mday; |
| const char *hour, *min, *sec, *msec; | const char *hour, *min, *sec, *msec; |
| year=skip_number(&cur, ":-", &delim); | year=skip_number(&cur, "-:", &delim); |
| if(delim != ':' || delim == ':' && strlen(year) >=4 ){ | if(delim != ':' || delim == ':' && strlen(year) >=4 ){ |
| // year present | // year present |
| month=skip_number(&cur, delim == ':' ? ":" : "-"); | month=skip_number(&cur, delim == ':' ? ":" : "-"); |
| Line 194 tm cstr_to_time_t(char *cstr, const char | Line 207 tm cstr_to_time_t(char *cstr, const char |
| const char *tz = delim == 'Z' ? (skip_writespace(cur) ? 0 : "UTC") : (cur ? numeric_tz(delim, cur) : 0); | const char *tz = delim == 'Z' ? (skip_writespace(cur) ? 0 : "UTC") : (cur ? numeric_tz(delim, cur) : 0); |
| if(!tz){ | if(!tz){ |
| if(!delim) | if(!delim) |
| throw Exception("date.format", 0, "empty timezone specification"); | throw Exception("date.format", 0, "empty timezone"); |
| throw Exception("date.format", 0, "invalid timezone specification '%c%s'", cur ? cur : ""); | throw Exception("date.format", 0, "invalid timezone '%c%s'", delim, cur ? cur : ""); |
| } | } |
| *tzOut=tz; | *tzOut=tz; |
| } | } |