@@ -15,6 +15,7 @@ import (
15
15
"os"
16
16
"os/signal"
17
17
"path/filepath"
18
+ "strings"
18
19
"time"
19
20
20
21
"github.com/prprprus/scheduler"
@@ -161,7 +162,6 @@ func main() {
161
162
162
163
func doAbsensi (config * config.Config ) {
163
164
format := "2006-01-02 15:04"
164
-
165
165
home , err := tools .GetHomeDirectory ()
166
166
folderPath := home + "/" + ".absensi"
167
167
fileName := folderPath + "/" + "absensi.db"
@@ -179,23 +179,34 @@ func doAbsensi(config *config.Config) {
179
179
log .Panic ("Create File Error. Panic and abort the apps" )
180
180
}
181
181
}
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
185
186
}
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
+ }
199
210
}
200
211
doCron (59 , config )
201
212
}
0 commit comments