-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
executable file
·142 lines (127 loc) · 2.87 KB
/
main.go
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
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/thedevsaddam/ponjika"
)
func main() {
now := time.Now()
p := ponjika.New(now)
mnthTotalDys := p.TotalDays
crntDate := p.Date
crntDateIndx := int(now.Weekday())
frstDateIndx := firstDayIndex(crntDate, crntDateIndx)
calender := [6][7]int{}
row := 0
col := frstDateIndx
for i := 1; i <= mnthTotalDys; i++ {
calender[row][col] = i
col = col + 1
if col > 6 {
row = row + 1
col = 0
}
}
isPh := flag.Bool("p", false, "show bengali calendar in english phonetic")
flag.Parse()
if *isPh {
heading := fmt.Sprintf("\t%s %s", p.BengaliMonth.Phonetic, p.BengaliYear.Phonetic)
fmt.Println(bold(heading))
phoneticBengaliCalendar(calender, crntDate)
os.Exit(0)
}
heading := fmt.Sprintf("\t %s %s", p.BengaliMonth.Bengali, p.BengaliYear.Bengali)
fmt.Println(bold(heading))
bengaliCalender(calender, crntDate)
}
func bengaliCalender(calender [6][7]int, today int) {
fmt.Println("রবি সোম মঙ্গল বুধ বৃহ শুক্র শনি")
for i := 0; i < len(calender); i++ {
for j := 0; j < 7; j++ {
dt := calender[i][j]
if dt != 0 {
if dt > 9 {
if dt == today {
fmt.Print(highlight(enToBnNumber(dt)), " ")
} else {
fmt.Print(enToBnNumber(dt), " ")
}
} else {
if dt == today {
fmt.Print(highlight(enToBnNumber(dt)), " ")
} else {
fmt.Print(enToBnNumber(dt), " ")
}
}
} else {
fmt.Print(" ")
}
}
fmt.Println()
}
}
func phoneticBengaliCalendar(calender [6][7]int, today int) {
fmt.Println("Su Mo Tu We Th Fr Sa")
for i := 0; i < len(calender); i++ {
for j := 0; j < 7; j++ {
dt := calender[i][j]
if dt != 0 {
if dt > 9 {
if dt == today {
fmt.Print(highlight(fmt.Sprintf("%d", dt)), " ")
} else {
fmt.Print(dt, " ")
}
} else {
if dt == today {
fmt.Print(highlight(fmt.Sprintf("%d", dt)), " ")
} else {
fmt.Print(dt, " ")
}
}
} else {
fmt.Print(" ")
}
}
fmt.Println()
}
}
// firstDayIndex return the months first day index
func firstDayIndex(date, dateIndex int) int {
position := (date - 1) % 7
offset := dateIndex - position
return ((offset + 7) % 7)
}
// enToBnNumber covert english number to bengali number String
func enToBnNumber(d int) string {
var o string
ds := fmt.Sprintf("%v", d)
bdmap := map[string]string{
"1": "১",
"2": "২",
"3": "৩",
"4": "৪",
"5": "৫",
"6": "৬",
"7": "৭",
"8": "৮",
"9": "৯",
"0": "০",
}
for i := 0; i < len(ds); i++ {
o += bdmap[string(ds[i])]
}
return o
}
func highlight(in string) string {
lg := "\033[1;32m" // light green
nc := "\033[0m"
return fmt.Sprintf("%s%s%s", lg, in, nc)
}
func bold(in string) string {
bld := "\033[1m" // bold
nb := "\033[0m"
return fmt.Sprintf("%s%s%s", bld, in, nb)
}