source: buchla-68k/orig/DATE/UTIME.C@ c79db87

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

Imported original source code.

  • Property mode set to 100755
File size: 1.4 KB
RevLine 
[3ae31e9]1/*
2 =============================================================================
3 time.c -- translate GEMDOS time format to Unix internal time format
4 Version 2 -- 1989-01-10 -- 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#define TIMEZONE 8 /* PST */
11
12#include "osbind.h"
13#include "stddefs.h"
14
15static char mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
16
17static
18int
19days(y)
20register int y;
21{
22 if (y < 1970)
23 y += 1900;
24
25 if (((y % 4) EQ 0) AND ((y % 100) OR ((y % 400) EQ 0)))
26 y = 366;
27 else
28 y = 365;
29
30 return(y);
31}
32
33long
34time(tloc)
35long *tloc;
36{
37 long _time;
38 int i, j, year, month, day, hour, minute, second, t;
39
40 t = Gettime();
41
42 year = ((short)(t >> 25) & 0x007F) + 1980;
43 month = (short)(t >> 21) & 0x000F;
44 day = (short)(t >> 16) & 0x001F;
45
46 hour = (short)(t >> 11) & 0x001F;
47 minute = (short)(t >> 5) & 0x003F;
48 second = ((short)t & 0x001F) << 1;
49
50 _time = 0L;
51
52 for (i = 1970, j = year; i < j; i++)
53 _time += days(i) ;
54
55 for(i = 1; i < month; i++)
56 _time += mdays[i - 1] ;
57
58 if((days(year) EQ 366) AND (month > 2))
59 ++_time ;
60
61 _time += (day - 1);
62 _time *= 24;
63 _time += hour + TIMEZONE;
64 _time *= 60;
65 _time += minute;
66 _time *= 60;
67 _time += second;
68
69 if (tloc)
70 *tloc = _time;
71
72 return(_time);
73}
Note: See TracBrowser for help on using the repository browser.