CHANGE: added Frontend + auth
This commit is contained in:
46
Backend/models/workDay.go
Normal file
46
Backend/models/workDay.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type WorkDay struct {
|
||||
Day time.Time
|
||||
workTime time.Duration
|
||||
Bookings []Booking
|
||||
}
|
||||
|
||||
func (d WorkDay) GetWorkTime() time.Duration{
|
||||
if(d.workTime > 0) {
|
||||
return d.workTime
|
||||
}
|
||||
var lastCame Booking
|
||||
for _, booking := range d.Bookings{
|
||||
if(booking.CheckInOut == 1){//kommen
|
||||
lastCame = booking
|
||||
}else{
|
||||
d.workTime = d.workTime + booking.Timestamp.Sub(lastCame.Timestamp)
|
||||
}
|
||||
}
|
||||
if(time.Since(d.Day) < 24 * time.Hour && len(d.Bookings) % 2 == 1){
|
||||
d.workTime += time.Since(lastCame.Timestamp)
|
||||
}
|
||||
return d.workTime
|
||||
}
|
||||
|
||||
func (d WorkDay) GetWorkTimeString() string {
|
||||
str := d.GetWorkTime().Abs().Round(time.Minute).String()
|
||||
str = str[:len(str)-2] + "in"
|
||||
if(len(str) > 2){
|
||||
return str
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (d WorkDay) RequiresAction() bool {
|
||||
return d.Bookings[len(d.Bookings)-1].CheckInOut == 255
|
||||
}
|
||||
|
||||
func (d WorkDay) GetWorkDayProgress() uint8 {
|
||||
defaultWorkTime, _ := time.ParseDuration("7h42m")
|
||||
progress := (d.GetWorkTime().Seconds()/defaultWorkTime.Seconds())*100
|
||||
return uint8(progress)
|
||||
}
|
||||
Reference in New Issue
Block a user