]> git.mxchange.org Git - flightgear.git/blob - src/Time/ttest.c
Fix typo
[flightgear.git] / src / Time / ttest.c
1 #include <math.h>
2 #include <stdio.h>
3 #include <time.h>
4
5 int main() {
6     time_t cur_time, start, start_gmt, now, now_gmt;
7     struct tm *gmt, mt;
8     long int offset;
9     double diff, part, days, hours, lon, lst;
10     int i;
11
12     cur_time = time(NULL);
13
14     printf("Time = %ld\n", cur_time);
15
16     gmt = gmtime(&cur_time);
17
18     printf("GMT = %d/%d/%2d %d:%02d:%02d\n", 
19            gmt->tm_mon, gmt->tm_mday, gmt->tm_year,
20            gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
21
22     mt.tm_mon = 2;
23     mt.tm_mday = 21;
24     mt.tm_year = 98;
25     mt.tm_hour = 12;
26     mt.tm_min = 0;
27     mt.tm_sec = 0;
28
29     start = mktime(&mt);
30
31     offset = -(timezone / 3600 - daylight);
32
33     printf("Raw time zone offset = %ld\n", timezone);
34     printf("Daylight Savings = %d\n", daylight);
35
36     printf("Local hours from GMT = %d\n", offset);
37
38     start_gmt = start - timezone + (daylight * 3600);
39
40     printf("March 21 noon (CST) = %ld\n", start);
41     printf("March 21 noon (GMT) = %ld\n", start_gmt);
42
43     for ( i = 0; i < 12; i++ ) {
44         mt.tm_mon = i;
45         mt.tm_mday = 21;
46         mt.tm_year = gmt->tm_year;
47         mt.tm_hour = 12;
48         mt.tm_min = 0;
49         mt.tm_sec = 0;
50
51         now = mktime(&mt);
52
53         offset = -(timezone / 3600 - daylight);
54
55         printf("Raw time zone offset = %ld\n", timezone);
56         printf("Daylight Savings = %d\n", daylight);
57         
58         printf("Local hours from GMT = %d\n", offset);
59
60         now_gmt = now - timezone + (daylight * 3600);
61
62         printf("%d/%d/%d noon (CST) = %ld\n", i+1, 21, 97, now);
63         printf("%d/%d/%d noon (GMT) = %ld\n", i+1, 21, 97, now_gmt);
64
65         diff = (now_gmt - start_gmt) / (3600.0 * 24.0);
66
67         printf("Time since 3/21/%2d GMT = %.2f\n", gmt->tm_year, diff);
68
69         part = fmod(diff, 1.0);
70         days = diff - part;
71         /* hours = gmt->tm_hour + gmt->tm_min/60.0 + gmt->tm_sec/3600.0; */
72         hours = 12;
73         lon = -112;
74
75         lst = (days + lon)/15.0 + hours - 12;
76
77         while ( lst < 0.0 ) {
78             lst += 24.0;
79         }
80
81         printf("days = %.1f  hours = %.2f  lon = %.2f  lst = %.2f\n", 
82                days, hours, lon, lst);
83     }
84
85     return(0);
86 }