source: buchla-68k/orig/DATE/TOTIME.C@ c93e44d

Last change on this file since c93e44d was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.2 KB
Line 
1/*
2 =============================================================================
3 totime.c -- translate a time.h structure to Unix internal time format
4 Version 2 -- 1989-01-09 -- D.N. Lynx Crowe
5
6 Unix(tm) keeps its time in seconds since 1970-01-01 00:00:00 GMT.
7 =============================================================================
8*/
9
10#include "stddefs.h"
11#include "time.h"
12
13static char mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
14
15static
16int
17days(y)
18register int y;
19{
20 if (y < 1970)
21 y += 1900;
22
23 if (((y % 4) EQ 0) AND ((y % 100) OR ((y % 400) EQ 0)))
24 y = 366;
25 else
26 y = 365;
27
28 return(y);
29}
30
31long
32totime(tp, timezn)
33register struct tm *tp; /* pointer to tm structure */
34long timezn; /* minutes local time is offset from GMT */
35{
36 long ret;
37 int i, j;
38
39 ret = 0L;
40
41 if (tp->tm_year < 70)
42 return(0L);
43
44 for (i = 1970, j = tp->tm_year + 1900; i < j; i++)
45 ret += days(i) ;
46
47 for(i = 1; i < tp->tm_mon; i++)
48 ret += mdays[i - 1] ;
49
50 if((days(tp->tm_year) EQ 366) AND (tp->tm_mon > 2))
51 ++ret ;
52
53 ret += (tp->tm_mday - 1);
54 ret *= 24;
55 ret += tp->tm_hour;
56 ret *= 60;
57 ret += (tp->tm_min + timezn);
58 ret *= 60;
59 ret += tp->tm_sec;
60
61 return(ret);
62}
Note: See TracBrowser for help on using the repository browser.