Enabled with -alter_date times between begin of year 0 and end of year 9999
This commit is contained in:
@@ -343,27 +343,36 @@ int Decode_date_year(char *text, int flag)
|
||||
for(i= 0; text[i]!=0; i++)
|
||||
if(!isdigit(text[i]))
|
||||
return(-1);
|
||||
if(strlen(text)!=4)
|
||||
if(strlen(text) < 1)
|
||||
return(-2);
|
||||
sscanf(text, "%d", &ret);
|
||||
if(ret<0 || ret>3000)
|
||||
if(ret<0 || ret>9999)
|
||||
return(-2);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/* @return: <=0 error
|
||||
1= timezone minutes found, 2= timezone name found, 3= UTC found
|
||||
*/
|
||||
int Decode_date_timezone(char *text, struct tm *erg, int flag)
|
||||
{
|
||||
int i;
|
||||
static char tzs[][5]= {"GMT", "CET", "CEST", "0000", ""};
|
||||
static char utc_tzs[][6]= {"GMT", "UTC", "+0000", "-0000", ""};
|
||||
static char tzs[][6]= {"CET", "CEST", ""};
|
||||
|
||||
for(i= 0; tzs[i][0]!=0; i++)
|
||||
for(i= 0; utc_tzs[i][0]!=0; i++) {
|
||||
if(strcmp(text, utc_tzs[i]) == 0)
|
||||
return(3);
|
||||
}
|
||||
for(i= 0; tzs[i][0]!=0; i++) {
|
||||
if(strcmp(text,tzs[i])==0) {
|
||||
|
||||
/* ??? >>> what to do with timezone info ? Add to ->tm_hour ? */
|
||||
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
if(text[0]=='+' || text[0]=='-') {
|
||||
for(i= 1; text[i]!=0; i++)
|
||||
if(!isdigit(text[i]))
|
||||
@@ -385,12 +394,15 @@ int Decode_date_timezone(char *text, struct tm *erg, int flag)
|
||||
}
|
||||
|
||||
|
||||
/* @return: <=0 error, 1= local time, 2= UTC
|
||||
*/
|
||||
int Decode_date_output_format(struct tm *erg, char *text, int flag)
|
||||
/* Thu Nov 8 09:07:50 CET 2007 */
|
||||
/* Sat, 03 Nov 2007 08:58:30 +0100 */
|
||||
/* Nov 7 23:24 */
|
||||
{
|
||||
int ret, i, argc= 0, seen_year= 0, seen_month= 0, seen_day= 0, seen_time= 0;
|
||||
int utc= 0;
|
||||
char **argv= NULL;
|
||||
struct tm *now;
|
||||
time_t timep;
|
||||
@@ -428,18 +440,21 @@ int Decode_date_output_format(struct tm *erg, char *text, int flag)
|
||||
}
|
||||
if(!seen_year) {
|
||||
ret= Decode_date_year(argv[i], 0);
|
||||
if(ret>0) {
|
||||
if(ret >= 0) {
|
||||
erg->tm_year= ret-1900;
|
||||
seen_year= 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* ignorants have to stay at the end of the loop */
|
||||
|
||||
ret= Decode_date_timezone(argv[i], erg, 0);
|
||||
if(ret == 3)
|
||||
utc= 1;
|
||||
if(ret>=0)
|
||||
continue;
|
||||
|
||||
/* ignorants have to stay at the end of the loop */
|
||||
|
||||
ret= Decode_date_weekday(argv[i], 0);
|
||||
if(ret>=0)
|
||||
continue; /* ignore weekdays */
|
||||
@@ -454,7 +469,7 @@ int Decode_date_output_format(struct tm *erg, char *text, int flag)
|
||||
now= localtime(&timep);
|
||||
erg->tm_year= now->tm_year;
|
||||
}
|
||||
ret= 1;
|
||||
ret= 1 + utc;
|
||||
ex:
|
||||
Sfile_make_argv("", "", &argc, &argv, 2); /* release storage */
|
||||
return(ret);
|
||||
@@ -485,8 +500,6 @@ int Decode_ecma119_format(struct tm *erg, char *text, int flag)
|
||||
num= 0;
|
||||
for(i= 0; i < 4; i++)
|
||||
num= num * 10 + text[i] - '0';
|
||||
if(num < 1970 || num > 3000)
|
||||
return(0);
|
||||
erg->tm_year = num - 1900;
|
||||
erg->tm_mon= 10*(text[4]-'0')+text[5]-'0'-1;
|
||||
if(erg->tm_mon > 12)
|
||||
@@ -532,7 +545,7 @@ int Decode_xorriso_timestamp(struct tm *erg, char *code, int flag)
|
||||
return(0);
|
||||
buf[4]= 0;
|
||||
sscanf(buf, "%d", &year);
|
||||
if(year<1900 || year>3000)
|
||||
if(year < 0 || year > 9999)
|
||||
return(0);
|
||||
if(!(isdigit(buf[5]) && isdigit(buf[6]) && (buf[7] == '.' || buf[7] == '_')))
|
||||
return(0);
|
||||
@@ -588,6 +601,30 @@ done:;
|
||||
}
|
||||
|
||||
|
||||
/* For now only from local time
|
||||
*/
|
||||
static int Tm_to_seconds(struct tm *result_tm, int utc, double *seconds,
|
||||
int flag)
|
||||
{
|
||||
*seconds= mktime(result_tm);
|
||||
if(utc == 1) {
|
||||
|
||||
#ifdef HAVE_TM_GMTOFF
|
||||
*seconds+= result_tm->tm_gmtoff;
|
||||
#else
|
||||
if(result_tm->tm_isdst < 0)
|
||||
result_tm->tm_isdst = 0;
|
||||
#ifndef Libburnia_timezonE
|
||||
#define Libburnia_timezonE timezone
|
||||
#endif
|
||||
*seconds-= Libburnia_timezonE - result_tm->tm_isdst * 3600;
|
||||
#endif
|
||||
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int Decode_timestring(char *code, time_t *date, int flag)
|
||||
{
|
||||
char scale_chr;
|
||||
@@ -638,32 +675,21 @@ int Decode_timestring(char *code, time_t *date, int flag)
|
||||
seconds= mktime(&result_tm);
|
||||
seconds_valid= 1;
|
||||
goto completed;
|
||||
} else if(Decode_date_output_format(&result_tm, code, 0)>0) {
|
||||
} else if((ret= Decode_date_output_format(&result_tm, code, 0)) > 0) {
|
||||
/* Thu Nov 8 09:07:50 CET 2007 */;
|
||||
/* Sat, 03 Nov 2007 08:58:30 +0100 */;
|
||||
/* Sep 15 12:10:27 UTC 2025 */
|
||||
/* Nov 7 23:24 */;
|
||||
seconds= mktime(&result_tm);
|
||||
seconds_valid= 1;
|
||||
/* >>> enable not only local time and UTC, but also other zones */;
|
||||
/* ret==2 means that the timestring is in UTC */
|
||||
seconds_valid= Tm_to_seconds(&result_tm, (ret == 2), &seconds, 0);
|
||||
|
||||
goto completed;
|
||||
} else if((ret= Decode_ecma119_format(&result_tm, code, 0)) > 0) {
|
||||
/* YYYYMMDDhhmmsscc[LOC] */
|
||||
/* 2010040711405800LOC */
|
||||
seconds= mktime(&result_tm);
|
||||
if(ret == 1) {
|
||||
|
||||
#ifdef HAVE_TM_GMTOFF
|
||||
seconds+= result_tm.tm_gmtoff;
|
||||
#else
|
||||
if(result_tm.tm_isdst < 0)
|
||||
result_tm.tm_isdst = 0;
|
||||
#ifndef Libburnia_timezonE
|
||||
#define Libburnia_timezonE timezone
|
||||
#endif
|
||||
seconds-= Libburnia_timezonE - result_tm.tm_isdst * 3600;
|
||||
#endif
|
||||
|
||||
}
|
||||
seconds_valid= 1;
|
||||
/* ret==1 means that the timestring is in UTC, i.e. no suffix LOC */
|
||||
seconds_valid= Tm_to_seconds(&result_tm, (ret == 1), &seconds, 0);
|
||||
goto completed;
|
||||
}
|
||||
return(0);
|
||||
|
Reference in New Issue
Block a user