M
Michael B Allen
Are there any localized facilites for performing date arithmetic that
properly considers leap years, daylight savings time, and whatever
other peculiarities of the gregorian lunar calendar?
Specifically, considering the following program and it's output below
can someone provide a suitable body for the time_subtract function?
Mike
--8<-- program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
time_t *
time_subtract(time_t *timep, struct tm *adj)
{
/* ???? */
}
int
main(int argc, char *argv[])
{
struct tm adj;
time_t now;
time_t *time3hoursago;
memset(&adj, 0, sizeof adj);
adj.tm_hour = 3; /* 3 hours, not 3rd hour */
now = time(NULL);
time3hoursago = time_subtract(&now, &adj);
puts(ctime(time3hoursago));
return EXIT_SUCCESS;
}
--8<-- output
$ date
Sat Nov 1 02:36:09 EST 2003
$ ./time_sub
Fri Oct 31 23:36:09 2003
properly considers leap years, daylight savings time, and whatever
other peculiarities of the gregorian lunar calendar?
Specifically, considering the following program and it's output below
can someone provide a suitable body for the time_subtract function?
Mike
--8<-- program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
time_t *
time_subtract(time_t *timep, struct tm *adj)
{
/* ???? */
}
int
main(int argc, char *argv[])
{
struct tm adj;
time_t now;
time_t *time3hoursago;
memset(&adj, 0, sizeof adj);
adj.tm_hour = 3; /* 3 hours, not 3rd hour */
now = time(NULL);
time3hoursago = time_subtract(&now, &adj);
puts(ctime(time3hoursago));
return EXIT_SUCCESS;
}
--8<-- output
$ date
Sat Nov 1 02:36:09 EST 2003
$ ./time_sub
Fri Oct 31 23:36:09 2003