-
Notifications
You must be signed in to change notification settings - Fork 1
/
timeline-sum
executable file
·74 lines (64 loc) · 2.85 KB
/
timeline-sum
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
#!/bin/bash
# This script comes with ABSOLUTELY NO WARRANTY, use at own risk
# Copyright (C) 2019 Osiris Alejandro Gomez <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# REFERENCE
#
# https://stackoverflow.com/questions/47918566/how-to-do-binary-addition-in-bash
# EXAMPLE BUSY + BUSY
#
# timeline-busy 10:00 12:00
# ▣▣▣▣▣▣ ▣▣▣▣▣▣ □□□□□□ □□□□□□ □□□□□□ □□□□□□ □□□□□□ □□□□□□ □□□□□□
# 111111 111111 000000 000000 000000 000000 000000 000000 000000
#
# timeline-busy 13:00 18:00
# 000000 000000 000000 111111 111111 111111 111111 111111 000000
#
# timeline-sum "$(timeline-busy 10:00 12:00)" "$(timeline-busy 13:00 18:00)"
# ▣▣▣▣▣▣ ▣▣▣▣▣▣ □□□□□□ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ □□□□□□
# 111111 111111 000000 111111 111111 111111 111111 111111 000000
# EXAMPLE FREE + BUSY
#
# timeline-free 12:00 13:00
# ▣▣▣▣▣▣ ▣▣▣▣▣▣ □□□□□□ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣
# 111111 111111 000000 111111 111111 111111 111111 111111 111111
#
# timeline-busy 12:30 12:40
# □□□□□□ □□□□□□ □□▣▣□□ □□□□□□ □□□□□□ □□□□□□ □□□□□□ □□□□□□ □□□□□□
# 000000 000000 001100 000000 000000 000000 000000 000000 000000
#
# timeline-sum "$(timeline-free 12:00 13:00)" "$(timeline-busy 12:30 12:40)"
# ▣▣▣▣▣▣ ▣▣▣▣▣▣ □□▣▣□□ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣ ▣▣▣▣▣▣
# 111111 111111 001100 111111 111111 111111 111111 111111 111111
bin2graph()
{
echo "$1" | fold -w 6 | sed 's/0/□/g' | sed 's/1/▣/g' | tr '\n' ' '
}
graph2bin()
{
echo "$1" | sed 's/□/0/g' | sed 's/▣/1/g' | tr -d ' '
}
[[ -z "$1" ]] && exit 1
A="$1"
[[ -z "$2" ]] && exit 1
B="$2"
BA=$(graph2bin "$A")
BB=$(graph2bin "$B")
HOURS=$(echo "$JRNL_END-$JRNL_BEGIN+1" | bc)
BOXES=$(echo "$HOURS*6" | bc)
BS=$(echo "ibase=2;obase=2; $BA+$BB" | bc -l)
BS=$(printf "%${BOXES}s" "$BS" | tr ' ' '0')
GB=$(bin2graph "$BS")
printf "%s\n" "$GB"