summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aquarela/smbtime.c
blob: 3627a795b0259137289004da89c26ccd17d75c0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "headers.h"

void
smbplan9time2datetime(ulong time, int tzoff, ushort *datep, ushort *timep)
{
	Tm *tm;
	if (tzoff < 0)
		time -= (ulong)-tzoff;
	else
		time += tzoff;
	tm = gmtime(time);
	*datep = (tm->mday) | ((tm->mon + 1) << 5) | ((tm->year - 80) << 9);
	*timep = (tm->sec >> 1) | (tm->min << 5) | (tm->hour << 11);
}

ulong
smbdatetime2plan9time(ushort date, ushort time, int tzoff)
{
	Tm tm;
	strcpy(tm.zone, "GMT");
	tm.mday = date & 0x1f;
	tm.mon = ((date >> 5) & 0xf) - 1;
	tm.year = (date >> 9) + 80;
	tm.yday = 0;
	tm.sec = (time & 0x1f) << 1;
	tm.min = (time >> 5) & 0x3f;
	tm.hour = time >> 11;
	smblogprint(-1, "smbdatetime2plan9time: converting %d/%d/%d %d:%d:%d\n",
		tm.year + 1900, tm.mon + 1, tm.mday, tm.hour, tm.min, tm.sec);
	return tm2sec(&tm) - tzoff;
}

vlong
smbplan9time2time(ulong time)
{
	return ((vlong)time + 11644473600LL) * 10000000;
}

ulong
smbtime2plan9time(vlong nttime)
{
	return (nttime / 10000000 - 11644473600LL);
}

ulong
smbplan9time2utime(ulong time, int tzoff)
{
	if (tzoff < 0)
		time -= (ulong)-tzoff;
	else
		time += tzoff;
	return time;
}

ulong
smbutime2plan9time(ulong utime, int tzoff)
{
	if (tzoff < 0)
		utime += (ulong)-tzoff;
	else
		utime -= tzoff;
	return utime;
}