SCP: Add DATE_19XX_YY and DATE_19XX_YYYY variable insertion.
These variables can be used in SEND scripts which are setting the date/time on non Y2K compliant operating systems.
This commit is contained in:
parent
aadd66c7c7
commit
445bc9935b
2 changed files with 28 additions and 2 deletions
|
@ -291,8 +291,8 @@ Command Aliases
|
|||
Omitted parameters result in null-string substitutions.
|
||||
|
||||
A Tokens preceeded and followed by % characters are expanded as environment
|
||||
variables, and if one isn't found then can be one of several special
|
||||
variables:
|
||||
variables, and if an environment variable isn't found then it can be one of
|
||||
several special variables:
|
||||
|
||||
%DATE% yyyy-mm-dd
|
||||
%TIME% hh:mm:ss
|
||||
|
@ -303,11 +303,16 @@ Command Aliases
|
|||
%DATE_YYYY% yyyy (0000-9999)
|
||||
%DATE_YY% yy (00-99)
|
||||
%DATE_MM% mm (01-12)
|
||||
%DATE_MMM% mmm (JAN-DEC)
|
||||
%DATE_DD% dd (01-31)
|
||||
%DATE_WW% ww (01-53) ISO 8601 week number
|
||||
%DATE_WYYYY% yyyy (0000-9999) ISO 8601 week year number
|
||||
%DATE_D% d (1-7) ISO 8601 day of week
|
||||
%DATE_JJJ% jjj (001-366) day of year
|
||||
%DATE_19XX_YY% yy A year prior to 2000 with the same
|
||||
calendar days as the current year
|
||||
%DATE_19XX_YYYY% yyyy A year prior to 2000 with the same
|
||||
calendar days as the current year
|
||||
%TIME_HH% hh (00-23)
|
||||
%TIME_MM% mm (00-59)
|
||||
%TIME_SS% ss (00-59)
|
||||
|
|
21
scp.c
21
scp.c
|
@ -3061,10 +3061,31 @@ for (; *ip && (op < oend); ) {
|
|||
sprintf (rbuf, "%d", (tmnow->tm_year + 1900)/100);
|
||||
ap = rbuf;
|
||||
}
|
||||
else if ((!strcmp ("DATE_19XX_YY", gbuf)) || /* Year with same calendar */
|
||||
(!strcmp ("DATE_19XX_YYYY", gbuf))) {
|
||||
int year = tmnow->tm_year + 1900 + 22;
|
||||
int days = year - 2001;
|
||||
int leaps = days/4 - days/100 + days/400;
|
||||
int lyear = ((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0));
|
||||
int selector = ((days + leaps + 7) % 7) + lyear * 7;
|
||||
static int years[] = {90, 91, 97, 98, 99, 94, 89,
|
||||
96, 80, 92, 76, 88, 72, 84};
|
||||
int cal_year = years[selector];
|
||||
|
||||
if (!strcmp ("DATE_19XX_YY", gbuf))
|
||||
sprintf (rbuf, "%d", cal_year); /* 2 digit year */
|
||||
else
|
||||
sprintf (rbuf, "%d", cal_year + 1900); /* 4 digit year */
|
||||
ap = rbuf;
|
||||
}
|
||||
else if (!strcmp ("DATE_MM", gbuf)) {/* Month number (01-12) */
|
||||
strftime (rbuf, sizeof(rbuf), "%m", tmnow);
|
||||
ap = rbuf;
|
||||
}
|
||||
else if (!strcmp ("DATE_MMM", gbuf)) {/* Month number (01-12) */
|
||||
strftime (rbuf, sizeof(rbuf), "%b", tmnow);
|
||||
ap = rbuf;
|
||||
}
|
||||
else if (!strcmp ("DATE_DD", gbuf)) {/* Day of Month (01-31) */
|
||||
strftime (rbuf, sizeof(rbuf), "%d", tmnow);
|
||||
ap = rbuf;
|
||||
|
|
Loading…
Add table
Reference in a new issue