blob: 949341b72b72d815f4abcdb33f7b65f10060a618 (
plain) (
blame)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#!/usr/bin/env bash
# this script was created in 3BBE.81[sft].
# usage:
# to convert to sfttime:
# $0 [c date] [digitcount] [nodate]
# if date is given, converts the given date to sfttime.
# if date is not given, converts the current date to sfttime.
# digitcount specifies the accuracy for the time part.
# nodate hides the date part.
# to convert from sfttime:
# $0 r sfttime [unix]
# converts the given sfttime to 'standard' time.
# if 'unix' is provided, the output will be in unix time.
# to show info about sfttime units
# $0 i [[sft]]$num
# displays name of unit [sft]$num, as well as it's value
# in both days and 'standard' units.
SFT_EPOCH_UNIX=49020
case $1 in
"c")
unixtime=$(date --date="$2" +%s.%N)
shift
shift
mode=fw
;;
"r")
shift
sfttime=$1
if [[ $sfttime =~ ^([0-9A-F]*(.[0-9A-F]+)?)(\[[sS][fF][tT]\])?$ ]] && [[ $sfttime ]]; then
sfttime=${BASH_REMATCH[1]}
else
echo "error" 2>&1
exit 1
fi
shift
mode=bw
;;
"i")
shift
inforeq=$1
if [[ $inforeq =~ ^(\[[sS][fF][tT]\])?(-?[0-9]+)$ ]]; then
inforeq=${BASH_REMATCH[2]}
let inforeq=$inforeq
mode=in
elif [[ $inforeq =~ ^(\[[sS][fF][tT]\])?[eE][pP][oO][cC][hH]$ ]]; then
echo "[sft]epoch:"
echo "unix time $SFT_EPOCH_UNIX"
echo "1970-01-01 13:37:00 UTC"
exit 0
else
echo "error" 2>&1
exit 1
fi
shift
mode=in
;;
*)
unixtime=$(date +%s.%N)
mode=fw
;;
esac
case $mode in
"fw")
sfttime=$(echo "obase=16; ($unixtime-$SFT_EPOCH_UNIX)/86400" | bc -l)
if [[ $1 -ge 1 ]]; then
digits=$1
shift
elif [[ ! $1 ]] || [[ $1 == nodate ]]; then
digits=3
else
digits=0
fi
if [[ $sfttime =~ ^([0-9A-F]+)[.]([0-9A-F]{$digits}).*$ ]]; then
date=${BASH_REMATCH[1]}
time=${BASH_REMATCH[2]}
else
echo "Error" &1>2
exit 1
fi
if [[ $digits -eq 0 ]]; then
echo "$date[sft]"
else
if [[ $1 == nodate ]]; then
echo ".$time[sft]"
shift
else
echo "$date.$time[sft]"
fi
fi
;;
"bw")
unixtime=$(echo "ibase=16; $sfttime*15180+BF7C" | bc -l)
case $1 in
unix)
shift
echo $unixtime
;;
*)
date --date="1970-01-01 $unixtime sec"
;;
esac
;;
"in")
name="[sft]$inforeq"
case $inforeq in
-4) newname="[sft]tick";;
-3) newname="[sft]tentacle";;
-2) newname="[sft]schinken";;
-1) newname="[sft]major";;
0) newname="day";;
1) newname="[sft]vergil";;
2) newname="[sft]stallman";;
3) newname="[sft]odin";;
esac
if [[ $newname ]]; then
echo "alternative name for $name: $newname"
name="$newname"
fi
one="1 $name"
echo "$one after [sft]epoch:"
sfttime=$(echo "obase=16; 16^$inforeq" | bc -l)[sft]
echo $sfttime
echo "time equivalent of $one:"
echo "the duration of $(echo 794243384928000*16^$inforeq | bc -l) periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom"
echo "standard time units equivalent:"
seconds=$(echo "86400*16^$inforeq" | bc -l)
if [[ $(echo "$seconds < 60" | bc -l) == 1 ]]; then
echo "$seconds seconds"
elif [[ $(echo "$seconds < 3600" | bc -l) == 1 ]]; then
echo "$(echo $seconds/60 | bc -l) minutes"
elif [[ $(echo "$seconds < 86400" | bc -l) == 1 ]]; then
echo "$(echo $seconds/3600 | bc -l) hours"
elif [[ $(echo "$seconds < 86400*365.2425" | bc -l) == 1 ]]; then
echo "$(echo $seconds/86400 | bc -l) days"
else
echo "$(echo $seconds/86400/365.2425 | bc -l) years"
fi
;;
esac
|