fix clean
[tridge/junkcode.git] / longdate.c
1 #define TIME_FIXUP_CONSTANT1 (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
2 #define TIME_FIXUP_CONSTANT2 (TIME_FIXUP_CONSTANT1)
3
4 /****************************************************************************
5 interpret an 8 byte "filetime" structure to a time_t
6 It's originally in "100ns units since jan 1st 1601"
7
8 It appears to be kludge-GMT (at least for file listings). This means
9 its the GMT you get by taking a localtime and adding the
10 serverzone. This is NOT the same as GMT in some cases. This routine
11 converts this to real GMT.
12 ****************************************************************************/
13 time_t interpret_long_date(char *p)
14 {
15   double d;
16   time_t ret;
17   uint32 tlow,thigh;
18   tlow = IVAL(p,0);
19   thigh = IVAL(p,4);
20
21   if (thigh == 0) return(0);
22
23   d = ((double)thigh)*4.0*(double)(1<<30);
24   d += (tlow&0xFFF00000);
25   d *= 1.0e-7;
26  
27   /* now adjust by 369 years to make the secs since 1970 */
28   d -= TIME_FIXUP_CONSTANT1;
29
30   if (!(TIME_T_MIN <= d && d <= TIME_T_MAX))
31     return(0);
32
33   ret = (time_t)(d+0.5);
34
35   /* this takes us from kludge-GMT to real GMT */
36   ret -= serverzone;
37   ret += LocTimeDiff(ret);
38
39   return(ret);
40 }
41
42
43 /****************************************************************************
44 put a 8 byte filetime from a time_t
45 This takes real GMT as input and converts to kludge-GMT
46 ****************************************************************************/
47 void put_long_date(char *p,time_t t)
48 {
49   uint32 tlow,thigh;
50   double d;
51
52   if (t==0) {
53     SIVAL(p,0,0); SIVAL(p,4,0);
54     return;
55   }
56
57   /* this converts GMT to kludge-GMT */
58   t -= LocTimeDiff(t) - serverzone; 
59
60   d = (double) (t);
61
62   d += TIME_FIXUP_CONSTANT2;
63
64   d *= 1.0e7;
65
66   thigh = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
67   tlow = (uint32)(d - ((double)thigh)*4.0*(double)(1<<30));
68
69   SIVAL(p,0,tlow);
70   SIVAL(p,4,thigh);
71 }
72
73 int main(int argc, char *argv[])
74 {
75
76 }