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

Create dog and dog/run packages #113

Merged
merged 13 commits into from
Jan 30, 2017
11 changes: 5 additions & 6 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,20 @@ func (taskChain *TaskChain) Run() error {
}

// formatDuration is a time formatter.
func formatDuration(d time.Duration) (s string) {
timeMsg := ""
func formatDuration(d time.Duration) (timeMsg string) {

if d.Hours() > 1.0 {
timeMsg += fmt.Sprintf("%1.0fh", d.Hours())
timeMsg = fmt.Sprintf("%1.0fh", d.Hours())
}

if d.Minutes() > 1.0 {
timeMsg += fmt.Sprintf("%1.0fm", d.Minutes())
timeMsg = fmt.Sprintf("%1.0fm", d.Minutes())
}

Choose a reason for hiding this comment

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

Concatenation was unnecessary only for hours. Because initially we had blank string. Now we always rewrite string variable which may not be the intention. Sorry for confusing you with unclear comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

True! This code was written half a year ago and I forgot how it worked. I added a better comment explaining the format.


if d.Seconds() > 1.0 {
timeMsg += fmt.Sprintf("%1.0fs", d.Seconds())
timeMsg = fmt.Sprintf("%1.0fs", d.Seconds())
} else {
timeMsg += fmt.Sprintf("%1.3fs", d.Seconds())
timeMsg = fmt.Sprintf("%1.3fs", d.Seconds())
}

return timeMsg
Expand Down