This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Harry, I think I've fixed the function that does the data substitution in the "pqact" utility. It allows dates one day in the future to one month minus one day in the past. I've attached a test-suite. Can you think of any other test cases? Regards, Steve Emmerson Ticket Details =================== Ticket ID: QMJ-238932 Department: Support LDM Priority: Normal Status: On Hold
int main() { char buf[128]; time_t time = 0; struct tm tm; time_t feb28; time_t feb28leap; time_t feb29leap; time_t mar01; time_t dec31; time_t jan01; (void)openulog("date_sub", (LOG_CONS|LOG_PID), LOG_LDM, "-"); date_sub("(01:yyyy)-(01:mm)-(01:dd)", buf, 0); assert(strcmp(buf, "1970-01-01") == 0); tm = *gmtime(&time); tm.tm_mon = 1; tm.tm_mday = 28; tm.tm_sec -= timezone; feb28 = mktime(&tm); date_sub("(01:yyyy)-(01:mm)-(01:dd)", buf, feb28); assert(strcmp(buf, "1970-03-01") == 0); date_sub("(02:yyyy)-(02:mm)-(02:dd)", buf, feb28); assert(strcmp(buf, "1970-02-02") == 0); tm = *gmtime(&time); tm.tm_year = 72; tm.tm_mon = 1; tm.tm_mday = 29; tm.tm_sec -= timezone; feb29leap = mktime(&tm); date_sub("(01:yyyy)-(01:mm)-(01:dd)", buf, feb29leap); assert(strcmp(buf, "1972-03-01") == 0); date_sub("(02:yyyy)-(02:mm)-(02:dd)", buf, feb29leap); assert(strcmp(buf, "1972-02-02") == 0); date_sub("(28:yyyy)-(28:mm)-(28:dd)", buf, feb29leap); assert(strcmp(buf, "1972-02-28") == 0); tm = *gmtime(&time); tm.tm_year = 72; tm.tm_mon = 1; tm.tm_mday = 28; tm.tm_sec -= timezone; feb28leap = mktime(&tm); date_sub("(01:yyyy)-(01:mm)-(01:dd)", buf, feb28leap); assert(strcmp(buf, "1972-02-01") == 0); date_sub("(29:yyyy)-(29:mm)-(29:dd)", buf, feb28leap); assert(strcmp(buf, "1972-02-29") == 0); tm = *gmtime(&time); tm.tm_mon = 2; tm.tm_mday = 01; tm.tm_sec -= timezone; mar01 = mktime(&tm); date_sub("(28:yyyy)-(28:mm)-(28:dd)", buf, mar01); assert(strcmp(buf, "1970-02-28") == 0); date_sub("(27:yyyy)-(27:mm)-(27:dd)", buf, mar01); assert(strcmp(buf, "1970-02-27") == 0); tm = *gmtime(&time); tm.tm_mon = 11; tm.tm_mday = 31; tm.tm_sec -= timezone; dec31 = mktime(&tm); date_sub("(01:yyyy)-(01:mm)-(01:dd)", buf, dec31); assert(strcmp(buf, "1971-01-01") == 0); date_sub("(02:yyyy)-(02:mm)-(02:dd)", buf, dec31); assert(strcmp(buf, "1970-12-02") == 0); tm = *gmtime(&time); tm.tm_year = 71; tm.tm_mon = 0; tm.tm_mday = 1; tm.tm_sec -= timezone; jan01 = mktime(&tm); date_sub("(01:yyyy)-(01:mm)-(01:dd)", buf, jan01); assert(strcmp(buf, "1971-01-01") == 0); date_sub("(31:yyyy)-(31:mm)-(31:dd)", buf, jan01); assert(strcmp(buf, "1970-12-31") == 0); }