CHANGE: added pause time in frontend
This commit is contained in:
@@ -135,7 +135,9 @@ func (b *Booking) GetBookingsGrouped(card_uid string, tsFrom time.Time, tsTo tim
|
||||
sort.Slice(bookings, func(i, j int) bool {
|
||||
return bookings[i].Timestamp.Before(bookings[j].Timestamp)
|
||||
})
|
||||
result = append(result, WorkDay{Day: day, Bookings: bookings})
|
||||
workDay := WorkDay{Day: day, Bookings: bookings}
|
||||
workDay.GetWorkTime()
|
||||
result = append(result, workDay)
|
||||
}
|
||||
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
|
||||
@@ -9,10 +9,11 @@ type WorkDay struct {
|
||||
Day time.Time
|
||||
Bookings []Booking
|
||||
workTime time.Duration
|
||||
pauseTime time.Duration
|
||||
}
|
||||
|
||||
// Gets the duration someone worked that day
|
||||
func (d WorkDay) GetWorkTime() time.Duration{
|
||||
func (d *WorkDay) GetWorkTime() time.Duration{
|
||||
var workTime, pauseTime time.Duration
|
||||
var lastBooking Booking
|
||||
for _, booking := range d.Bookings{
|
||||
@@ -41,37 +42,41 @@ func (d WorkDay) GetWorkTime() time.Duration{
|
||||
pauseTime += diff
|
||||
}
|
||||
}
|
||||
d.workTime = workTime
|
||||
d.pauseTime = pauseTime
|
||||
return workTime
|
||||
}
|
||||
|
||||
func formatDuration(d time.Duration) string{
|
||||
hours := int(d.Hours())
|
||||
minutes := int(d.Minutes()) % 60
|
||||
if d.Hours() > 0 {
|
||||
return fmt.Sprintf("%dh %dmin", hours, minutes)
|
||||
}
|
||||
switch{
|
||||
case hours > 0:
|
||||
return fmt.Sprintf("%dh %dmin", hours, minutes)
|
||||
case minutes >0:
|
||||
return fmt.Sprintf("%dmin", minutes)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Converts duration to string and replaces 0s with in
|
||||
//
|
||||
// -> output xhxmin
|
||||
func (d WorkDay) GetWorkTimeString() string {
|
||||
str := formatDuration(d.GetWorkTime().Abs().Round(time.Minute))
|
||||
if(len(str) > 2){
|
||||
return str
|
||||
}
|
||||
return ""
|
||||
func (d *WorkDay) GetWorkTimeString() (string, string) {
|
||||
workString := formatDuration(d.workTime)
|
||||
pauseString := formatDuration(d.pauseTime)
|
||||
return workString, pauseString
|
||||
}
|
||||
|
||||
// returns bool wheter the workday was ended with an automatic logout
|
||||
func (d WorkDay) RequiresAction() bool {
|
||||
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
|
||||
func (d *WorkDay) GetWorkDayProgress(user User) uint8 {
|
||||
defaultWorkTime := time.Duration(user.Arbeitszeit * float32(time.Hour))
|
||||
progress := (d.workTime.Seconds()/defaultWorkTime.Seconds())*100
|
||||
return uint8(progress)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user