My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#Convert date formats

convert() {
awk '

function bin(t,\
r,b,i) {

r="";
b=1;
for(i = 1 ; i <= 32 ; i++ ) {
r= (and(t,b) > 0) r ;
b = lshift(b,1);
if (i%8 == 0) r = " "r;
}
if (r == "") r = 0;
return r;
}

function hex2dec(t,\
i,h) {
i = 0;
for(i = 1 ; i <= length(t) ; i++ ) {
h *= 16;
h += index("123456789abcdef",tolower(substr(t,i,1)));
}
return h;
}

# convert yyyymmddHHMMSS to bitwise yyyyyy yyyymmmm dddddhhh hhmmmmmm
function longtime(t,\
y,m,d,hr,mn,r) {
if (t != "") {
t = hex2dec(t);
mn = and(t,63);
hr = and(rshift(t,6),31);
d = and(rshift(t,11),31);
m = and(rshift(t,16),15);
y = and(rshift(t,20),1023)+1900;
print y,m,d,hr,mn
r = sprintf("%04d%02d%02d%02d%02d",y,m,d,hr,mn);
}
return r;
}

function shorttime(t,\
y,m,d,hr,mn,r) {
if (t != "") {

y = 0+substr(t,1,4)-1900;
m = 0+substr(t,5,2);
d = 0+substr(t,7,2);
hr = 0+substr(t,9,2);
mn = 0+substr(t,11,2);

r = lshift(lshift(lshift(lshift(and(y,1023),4)+m,5)+d,5)+hr,6)+mn;
r= sprintf("%x",r);
}
return r;
}

END {
gdate="'"$1"'";
if (length(gdate) <= 8 ) {
print gdate "=" longtime(gdate);
} else {
print gdate "=" shorttime(gdate);
}
}
' </dev/null
}

if [ -z "$1" ] ; then
cat <<HERE
convert date formats:

$0 yyyymmddHHMM output hhhhhh

or
$0 hhhhhh output yyyymmddHHMM
HERE
exit 1
fi


convert "$1"
# vi:syntax=awk:sw=4:et:ts=4

Change log

r665 by lordylordy on Dec 21, 2009   Diff
release r665-testing
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1600 bytes, 88 lines

File properties

svn:executable
*
svn:eol-style
LF
svn:keywords
Author Date Id Revision
Powered by Google Project Hosting