CHANGE: finalized user auth + added booking edit view
This commit is contained in:
@@ -1,31 +1,34 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type WorkDay struct {
|
||||
Day time.Time
|
||||
workTime time.Duration
|
||||
Bookings []Booking
|
||||
workTime time.Duration
|
||||
}
|
||||
|
||||
// Gets the duration someone worked that day
|
||||
func (d WorkDay) GetWorkTime() time.Duration{
|
||||
if(d.workTime > 0) {
|
||||
return d.workTime
|
||||
d.workTime = 0
|
||||
for i := 0; i < len(d.Bookings) - (1 + len(d.Bookings)%2); i += 2{
|
||||
start := d.Bookings[i].Timestamp
|
||||
end := d.Bookings[i+1].Timestamp
|
||||
d.workTime += end.Sub(start)
|
||||
}
|
||||
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)
|
||||
|
||||
// checks if booking is today and has no gehen yet, so the time since last kommen booking is added to workTime
|
||||
if(d.Day.Equal(time.Now().Truncate(24 * time.Hour)) && len(d.Bookings) % 2 == 1){
|
||||
d.workTime += time.Since(d.Bookings[len(d.Bookings)-1].Timestamp)
|
||||
}
|
||||
return d.workTime
|
||||
}
|
||||
|
||||
// Converts duration to string and replaces 0s with in
|
||||
//
|
||||
// -> output xhxmin
|
||||
func (d WorkDay) GetWorkTimeString() string {
|
||||
str := d.GetWorkTime().Abs().Round(time.Minute).String()
|
||||
str = str[:len(str)-2] + "in"
|
||||
@@ -35,10 +38,12 @@ func (d WorkDay) GetWorkTimeString() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// returns bool wheter the workday was ended with an automatic logout
|
||||
func (d WorkDay) RequiresAction() bool {
|
||||
return d.Bookings[len(d.Bookings)-1].CheckInOut == 255
|
||||
}
|
||||
|
||||
// returns a integer percentage of how much day has been worked of
|
||||
func (d WorkDay) GetWorkDayProgress() uint8 {
|
||||
defaultWorkTime, _ := time.ParseDuration("7h42m")
|
||||
progress := (d.GetWorkTime().Seconds()/defaultWorkTime.Seconds())*100
|
||||
|
||||
Reference in New Issue
Block a user