Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer widget #67

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Timer widget #67

wants to merge 4 commits into from

Conversation

norrs
Copy link

@norrs norrs commented Feb 3, 2022

This is continuation of #66 with a bit of refactor to support customized layouts as done with the Time widget.

Configuration also uses the time.Duration formats to provide timer configurations. See https://pkg.go.dev/time#ParseDuration

Support timer configuration by time.Duration formats such as 1h10m15s
etc.
Fixes pause and resume functionality.
if w.data.IsPaused() {
w.data.Clear()
} else if !w.data.HasDeadline() {
w.currIndex = (w.currIndex + 1) % len(w.times)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method? NextTimer() ?

Comment on lines +179 to +181
pausedDuration := time.Now().Sub(w.data.pausedTime)
w.data.startTime = w.data.startTime.Add(pausedDuration)
w.data.pausedTime = time.Time{}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method? Resume() ?

w.data.startTime = w.data.startTime.Add(pausedDuration)
w.data.pausedTime = time.Time{}
} else {
w.data.startTime = time.Now()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method? StartTimer()

Comment on lines +118 to +131
if !w.data.HasDeadline() {
str = Timespan(w.times[w.currIndex]).Format(w.formats[i])
} else {
remainingDuration := time.Until(w.data.startTime.Add(w.times[w.currIndex]))
if remainingDuration < 0 && !w.underflow {
str = Timespan(w.times[w.currIndex]).Format(w.formats[i])
w.data.Clear()
} else if remainingDuration < 0 && w.underflow {
fontColor = w.underflowColors[i]
str = Timespan(remainingDuration * -1).Format(w.formats[i])
} else {
str = Timespan(remainingDuration).Format(w.formats[i])
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be a method(s) .. not really happy about how this turned out. Its a bit hard to read.

ie line 123, this is basically rendering the current timer you can start. Ideally we should be telling the types what to do .. now we are kinda asking them for information on how to generate a string to display. Abit of data jealousy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants