Skip to content

Commit 9beaf6f

Browse files
Merge 09e5733 into 5cd4021
2 parents 5cd4021 + 09e5733 commit 9beaf6f

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ absensi
22
test.db
33
bin/Kira_Yamato_003.jpg
44
bin/.env
5-
.env
5+
.env
6+
bin/absensi.dmg

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Description=
1414
Region=Asia/Jakarta
1515
```
1616
Tips: Dont change for BaseURL and Region, Picture only filename with extension
17-
1817
4. Run absensi.exe or absensi (in linux)
1918

2019
# Cara Kerja

source/cmd/main.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os"
1616
"os/signal"
1717
"path/filepath"
18+
"strings"
1819
"time"
1920

2021
"github.com/prprprus/scheduler"
@@ -161,7 +162,6 @@ func main() {
161162

162163
func doAbsensi(config *config.Config) {
163164
format := "2006-01-02 15:04"
164-
165165
home, err := tools.GetHomeDirectory()
166166
folderPath := home + "/" + ".absensi"
167167
fileName := folderPath + "/" + "absensi.db"
@@ -179,23 +179,34 @@ func doAbsensi(config *config.Config) {
179179
log.Panic("Create File Error. Panic and abort the apps")
180180
}
181181
}
182-
daftar, err := checkAndCreateSchedule(fileName)
183-
if err != nil {
184-
log.Panic("Create File Error. Panic and abort the apps")
182+
currentDay := time.Now().Format("Mon")
183+
isWeekend := false
184+
if currentDay == "Sun" || currentDay == "Sat" {
185+
isWeekend = true
185186
}
186-
log.Printf("Login: %s,Logout: %s,Now: %s",
187-
daftar.LoginDateTime.Format(format),
188-
daftar.LogoutDateTime.Format(format),
189-
time.Now().Format(format))
190-
if daftar.LoginDateTime.Format(format) == time.Now().Format(format) {
191-
token := Login(config)
192-
doLoginOrLogout(config, token, true)
193-
doLoginOrLogoutDB(fileName, true)
194-
}
195-
if daftar.LogoutDateTime.Format(format) == time.Now().Format(format) {
196-
token := Login(config)
197-
doLoginOrLogout(config, token, false)
198-
doLoginOrLogoutDB(fileName, false)
187+
log.Debugf("hari sabtu minggu %t", isWeekend)
188+
currentDate := time.Now().Format("2006-01-02")
189+
hariLibur := tools.Get("https://gist.githubusercontent.com/reski-rukmantiyo/36bbd55e056e2159a736143b94b78795/raw/c1a4deaea0ac6f961cb92b22650bf8de952da6a0/2021.txt")
190+
if existHariLibur := strings.Contains(hariLibur, currentDate); !existHariLibur && !isWeekend {
191+
log.Debugf("bukan termasuk hari libur %t", existHariLibur)
192+
daftar, err := checkAndCreateSchedule(fileName)
193+
if err != nil {
194+
log.Panic("Create File Error. Panic and abort the apps")
195+
}
196+
log.Printf("Login: %s,Logout: %s,Now: %s",
197+
daftar.LoginDateTime.Format(format),
198+
daftar.LogoutDateTime.Format(format),
199+
time.Now().Format(format))
200+
if daftar.LoginDateTime.Format(format) == time.Now().Format(format) {
201+
token := Login(config)
202+
doLoginOrLogout(config, token, true)
203+
doLoginOrLogoutDB(fileName, true)
204+
}
205+
if daftar.LogoutDateTime.Format(format) == time.Now().Format(format) {
206+
token := Login(config)
207+
doLoginOrLogout(config, token, false)
208+
doLoginOrLogoutDB(fileName, false)
209+
}
199210
}
200211
doCron(59, config)
201212
}

0 commit comments

Comments
 (0)