static char *sccsid
= "@(#)time.c 1.4 (Berkeley) 3/20/86";
* Collection of routines for dealing with ASCII time strings.
* These may actually be useful in their own right.
* dtol -- convert date to long integer. This is not implicitly
* local time, or any other kind of time, for that matter. If you
* pass it a date you think is GMT, you wind up with that number of
* Parameters: "date_ascii" is in the form "yymmddhhmmss".
* Returns: Long integer containing number
* of seconds since 000000 Jan 1, 1970,
* and "date". -1 on error.
#define twodigtoi(x) (((*x++) - '0') + (*x++ - '0')*10)
#define dysize(y) ((y % 4 ? 365 : 366))
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
char date
[32], *date_str
;
int year
, month
, day
, hour
, mins
, secs
;
len
= strlen(date_ascii
);
if (len
!= sizeof("yymmddhhmmss")-1)
(void) strcpy(date
, date_ascii
);
printf("date_str = %s\n", date_str
);
rhs
= date_str
+ len
- 1;
for (; lhs
< rhs
; ++lhs
, --rhs
) {
if (!isdigit(temp
) || !isdigit(*lhs
))
printf("date_str = %s\n", date_str
);
if (month
< 1 || month
> 12 ||
if (hour
< 0 || hour
> 23)
for (i
= 1970; i
< year
; i
++)
if (dysize(year
) == 366 && month
>= 3)
seconds
+= dmsize
[month
-1];
seconds
= 24 * seconds
+ hour
;
seconds
= 60 * seconds
+ mins
;
seconds
= 60 * seconds
+ secs
;
* ltod -- convert long integer to date string.
* Parameters: "date" is in the number of seconds
* Returns: Pointer to static data in the form
sprintf(timebuf
, "%02d%02d%02d%02d%02d%02d",
tp
->tm_mon
+ 1, /* 0 to 11??? How silly. */
* local_to_gmt -- convert a local time (in form of number of
* seconds since you-know-when) to GMT.
* Parameters: "date" is date we want converted, in
* seconds since 000000 1 Jan 1970.
* Returns: Number of seconds corrected for local
(void) gettimeofday(&tv
, &tz
);
date
+= (long) tz
.tz_minuteswest
* 60;
/* now fix up local daylight time */
if (localtime((time_t *)&date
)->tm_isdst
)
* gmt_to_local -- take a GMT time expressed in seconds since
* the epoch, and convert it to local time.
* Parameters: "date" is the number of seconds...
* Returns: Number of seconds corrected to reflect
(void) gettimeofday(&tv
, &tz
);
date
-= (long) tz
.tz_minuteswest
* 60;
/* now fix up local daylight time */
if (localtime((time_t *)&date
)->tm_isdst
)