1 #include "headers.h"
2
3 void
smbplan9time2datetime(ulong time,int tzoff,ushort * datep,ushort * timep)4 smbplan9time2datetime(ulong time, int tzoff, ushort *datep, ushort *timep)
5 {
6 Tm *tm;
7 if (tzoff < 0)
8 time -= (ulong)-tzoff;
9 else
10 time += tzoff;
11 tm = gmtime(time);
12 *datep = (tm->mday) | ((tm->mon + 1) << 5) | ((tm->year - 80) << 9);
13 *timep = (tm->sec >> 1) | (tm->min << 5) | (tm->hour << 11);
14 }
15
16 ulong
smbdatetime2plan9time(ushort date,ushort time,int tzoff)17 smbdatetime2plan9time(ushort date, ushort time, int tzoff)
18 {
19 Tm tm;
20 strcpy(tm.zone, "GMT");
21 tm.mday = date & 0x1f;
22 tm.mon = ((date >> 5) & 0xf) - 1;
23 tm.year = (date >> 9) + 80;
24 tm.yday = 0;
25 tm.sec = (time & 0x1f) << 1;
26 tm.min = (time >> 5) & 0x3f;
27 tm.hour = time >> 11;
28 smblogprint(-1, "smbdatetime2plan9time: converting %d/%d/%d %d:%d:%d\n",
29 tm.year + 1900, tm.mon + 1, tm.mday, tm.hour, tm.min, tm.sec);
30 return tm2sec(&tm) - tzoff;
31 }
32
33 vlong
smbplan9time2time(ulong time)34 smbplan9time2time(ulong time)
35 {
36 return ((vlong)time + 11644473600LL) * 10000000;
37 }
38
39 ulong
smbtime2plan9time(vlong nttime)40 smbtime2plan9time(vlong nttime)
41 {
42 return (nttime / 10000000 - 11644473600LL);
43 }
44
45 ulong
smbplan9time2utime(ulong time,int tzoff)46 smbplan9time2utime(ulong time, int tzoff)
47 {
48 if (tzoff < 0)
49 time -= (ulong)-tzoff;
50 else
51 time += tzoff;
52 return time;
53 }
54
55 ulong
smbutime2plan9time(ulong utime,int tzoff)56 smbutime2plan9time(ulong utime, int tzoff)
57 {
58 if (tzoff < 0)
59 utime += (ulong)-tzoff;
60 else
61 utime -= tzoff;
62 return utime;
63 }
64