Mapper
libraries
shef
ouptime.c
Go to the documentation of this file.
1
/*
2
ouptime
3
is called to compute the number of seconds since jan 1 1980 00:00:00.
4
It returns a long integer.
5
6
*/
7
#define _POSIX_SOURCE
8
#include <time.h>
/* old time component structure */
9
10
static
int
mdays
[12] = { 0,31,59,90,120,151,181,212,243,273,304,334 } ;
11
12
long
ouptime
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute,
int
second)
13
14
{
15
int
ndays ;
16
long
times ;
17
18
/* COMPUTE TIME IN SECONDS SINCE JAN 1, 1980 00:00:00 */
19
20
/* number of seconds for years */
21
/* times = 31536000L * (long)(year - 1980) ; */
22
times = 31536000L * (long)(
year
- 1970) ;
23
/* times += 86400L * (long)((year - 1977)/4); */
/* account for leap years */
24
times += 86400L * (long)((
year
- 1969)/4);
/* account for leap years */
25
26
/* number of seconds for days in year */
27
ndays =
mdays
[
month
-1] +
day
- 1 ;
28
times += 86400L * (long)ndays ;
29
30
31
/* take into account leap years */
32
if
(
year
% 4 == 0 &&
year
% 100 != 0 ||
year
% 400 == 0 )
33
if
(
month
> 2)
34
times += 86400L ;
35
36
/* now add hours, minutes and seconds */
37
times += 3600L *
hour
;
38
times += 60L * minute ;
39
times += second ;
40
41
/* RETURN THE TIME IN SECONDS */
42
return
(times) ;
43
}
hour
int hour
Definition:
display_data.c:26
day
int day
Definition:
display_data.c:26
year
int year
Definition:
display_data.c:26
month
int month
Definition:
display_data.c:26
ouptime
long ouptime(int year, int month, int day, int hour, int minute, int second)
Definition:
ouptime.c:10
mdays
static int mdays[12]
Definition:
ouptime.c:10
Generated by
1.9.1