Add iso8601_difference()

This commit is contained in:
Laurence Withers 2007-08-21 09:54:51 +00:00
commit f49b80de01
3 changed files with 66 additions and 4 deletions

View file

@ -159,6 +159,7 @@ void usage(void)
"Operators:\n"
" + (date, period) Advance date by elapsed time, push date.\n"
" - (date, period) Regress date by elapsed time, push date.\n"
" dp (date, date) Compute difference, print elapsed time.\n"
" < (date, date) Prints 1 if first date less than second.\n"
" <= (date, date) Prints 1 if first date less than or equal to second.\n"
" == (date, date) Prints 1 if dates equal.\n"
@ -177,8 +178,7 @@ int parse_command(char* cmd)
struct iso8601_elapsed period;
double period_d;
char date_str[40];
int ret = 0;
int ret = 0, sign;
cmd = strtok(cmd, " \n");
while(cmd) {
@ -209,6 +209,19 @@ int parse_command(char* cmd)
}
} else if(!strcmp(cmd, "dp")) {
if(date_stack_pop_date(&date, &details) || date_stack_pop_date(&date2, &details2)) {
ret = 1;
} else {
iso8601_difference(&date2, &date, &period, &sign);
printf("Difference: %c %lu.%09lu\n",
(sign < 0) ? '-' : '+',
(unsigned long)period.sec,
(unsigned long)period.nsec);
}
} else if(!strcmp(cmd, "<")) {
if(date_stack_pop_date(&date, &details) || date_stack_pop_date(&date2, &details2)) {
ret = 1;