Fixed #7, treating entry.Finished for running entries as time.Now()
This commit is contained in:
parent
31014917ef
commit
6e0ecbb007
2 changed files with 42 additions and 8 deletions
|
@ -40,6 +40,7 @@ func NewCalendar(entries []Entry) (Calendar, error) {
|
|||
projects := make(map[string]Project)
|
||||
|
||||
for _, entry := range entries {
|
||||
var entryFinish time.Time
|
||||
endOfBeginDay := now.With(entry.Begin).EndOfDay()
|
||||
sameDayHours := decimal.NewFromInt(0)
|
||||
nextDayHours := decimal.NewFromInt(0)
|
||||
|
@ -55,23 +56,29 @@ func NewCalendar(entries []Entry) (Calendar, error) {
|
|||
projects[projectId] = project
|
||||
}
|
||||
|
||||
if entry.Finish.IsZero() {
|
||||
entryFinish = time.Now()
|
||||
} else {
|
||||
entryFinish = entry.Finish
|
||||
}
|
||||
|
||||
/*
|
||||
* Apparently the activity end is on a new day.
|
||||
* This means we have to split the activity across two days.
|
||||
*/
|
||||
if endOfBeginDay.Before(entry.Finish) == true {
|
||||
startOfFinishDay := now.With(entry.Finish).BeginningOfDay()
|
||||
if endOfBeginDay.Before(entryFinish) == true {
|
||||
startOfFinishDay := now.With(entryFinish).BeginningOfDay()
|
||||
|
||||
sameDayDuration := endOfBeginDay.Sub(entry.Begin)
|
||||
sameDay := sameDayDuration.Hours()
|
||||
sameDayHours = decimal.NewFromFloat(sameDay)
|
||||
|
||||
nextDayDuration := entry.Finish.Sub(startOfFinishDay)
|
||||
nextDayDuration := entryFinish.Sub(startOfFinishDay)
|
||||
nextDay := nextDayDuration.Hours()
|
||||
nextDayHours = decimal.NewFromFloat(nextDay)
|
||||
|
||||
} else {
|
||||
sameDayDuration := entry.Finish.Sub(entry.Begin)
|
||||
sameDayDuration := entryFinish.Sub(entry.Begin)
|
||||
sameDay := sameDayDuration.Hours()
|
||||
sameDayHours = decimal.NewFromFloat(sameDay)
|
||||
}
|
||||
|
@ -97,7 +104,7 @@ func NewCalendar(entries []Entry) (Calendar, error) {
|
|||
}
|
||||
|
||||
if nextDayHours.GreaterThan(decimal.NewFromInt(0)) {
|
||||
month, weeknumber := GetISOWeekInMonth(entry.Finish)
|
||||
month, weeknumber := GetISOWeekInMonth(entryFinish)
|
||||
month0 := month - 1
|
||||
weeknumber0 := weeknumber - 1
|
||||
weekday := entry.Begin.Weekday()
|
||||
|
|
33
z/entry.go
33
z/entry.go
|
@ -155,13 +155,40 @@ func (entry *Entry) GetOutputForFinish() (string) {
|
|||
|
||||
func (entry *Entry) GetOutput(full bool) (string) {
|
||||
var output string = ""
|
||||
trackDiff := entry.Finish.Sub(entry.Begin)
|
||||
var entryFinish time.Time
|
||||
var isRunning string = ""
|
||||
|
||||
if entry.Finish.IsZero() {
|
||||
entryFinish = time.Now()
|
||||
isRunning = "[running]"
|
||||
} else {
|
||||
entryFinish = entry.Finish
|
||||
}
|
||||
|
||||
trackDiff := entryFinish.Sub(entry.Begin)
|
||||
trackDiffOut := time.Time{}.Add(trackDiff)
|
||||
|
||||
if full == false {
|
||||
output = fmt.Sprintf("%s %s on %s from %s to %s (%sh)", color.FgGray.Render(entry.ID), color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(entry.Finish.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(trackDiffOut.Format("15:04")))
|
||||
output = fmt.Sprintf("%s %s on %s from %s to %s (%sh) %s",
|
||||
color.FgGray.Render(entry.ID),
|
||||
color.FgLightWhite.Render(entry.Task),
|
||||
color.FgLightWhite.Render(entry.Project),
|
||||
color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")),
|
||||
color.FgLightWhite.Render(entryFinish.Format("2006-01-02 15:04 -0700")),
|
||||
color.FgLightWhite.Render(trackDiffOut.Format("15:04")),
|
||||
color.FgLightYellow.Render(isRunning),
|
||||
)
|
||||
} else {
|
||||
output = fmt.Sprintf("%s\n %s on %s\n %sh from %s to %s\n\n Notes:\n %s\n", color.FgGray.Render(entry.ID), color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), color.FgLightWhite.Render(trackDiffOut.Format("15:04")), color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(entry.Finish.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(strings.Replace(entry.Notes, "\n", "\n ", -1)) )
|
||||
output = fmt.Sprintf("%s\n %s on %s\n %sh from %s to %s %s\n\n Notes:\n %s\n",
|
||||
color.FgGray.Render(entry.ID),
|
||||
color.FgLightWhite.Render(entry.Task),
|
||||
color.FgLightWhite.Render(entry.Project),
|
||||
color.FgLightWhite.Render(trackDiffOut.Format("15:04")),
|
||||
color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")),
|
||||
color.FgLightWhite.Render(entryFinish.Format("2006-01-02 15:04 -0700")),
|
||||
color.FgLightYellow.Render(isRunning),
|
||||
color.FgLightWhite.Render(strings.Replace(entry.Notes, "\n", "\n ", -1)),
|
||||
)
|
||||
}
|
||||
|
||||
return output
|
||||
|
|
Loading…
Reference in a new issue