Skip to content

Commit

Permalink
Merge branch 'master' into refactor/code-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelZhao21 authored Nov 18, 2023
2 parents 32b47e8 + 76cf3cc commit 8783c69
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/models/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import "time"

type ClockState struct {
StartTime int64 `json:"start_time" bson:"start_time"`
Prev int64 `json:"prev" bson:"prev"`
PauseTime int64 `json:"pause_time" bson:"pause_time"`
Running bool `json:"running" bson:"running"`
}

func NewClockState() *ClockState {
return &ClockState{
StartTime: 0,
Prev: 0,
PauseTime: 0,
Running: false,
}
}
Expand All @@ -26,7 +26,7 @@ func (c *ClockState) Pause() {
return
}
c.Running = false
c.Prev += GetCurrTime() - c.StartTime
c.PauseTime = GetCurrTime()
}

func (c *ClockState) Resume() {
Expand All @@ -39,13 +39,13 @@ func (c *ClockState) Resume() {

func (c *ClockState) Reset() {
c.StartTime = 0
c.Prev = 0
c.PauseTime = 0
c.Running = false
}

func (c *ClockState) GetDuration() int64 {
if !c.Running {
return c.Prev
return c.PauseTime
}
return c.Prev + GetCurrTime() - c.StartTime
return c.StartTime + GetCurrTime() - c.PauseTime
}

0 comments on commit 8783c69

Please sign in to comment.