Skip to content

Commit c4630cb

Browse files
Merge pull request #12 from JankariTech/sortTimeEntries
sort timeentries better
2 parents c50b006 + 5dbef79 commit c4630cb

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

cmd/diff.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"golang.org/x/term"
2929
"os"
3030
"path"
31-
"sort"
3231
"strconv"
3332
"strings"
3433
"time"
@@ -96,9 +95,6 @@ var diffCmd = &cobra.Command{
9695
_, _ = fmt.Fprint(os.Stderr, err)
9796
os.Exit(1)
9897
}
99-
sort.Slice(tmetricTimeEntries, func(i, j int) bool {
100-
return tmetricTimeEntries[i].Note < tmetricTimeEntries[j].Note
101-
})
10298

10399
var openProjectUser openproject.User
104100
if userNameFromCmd != "" {
@@ -115,9 +111,6 @@ var diffCmd = &cobra.Command{
115111
_, _ = fmt.Fprint(os.Stderr, err)
116112
os.Exit(1)
117113
}
118-
sort.Slice(openProjectTimeEntries, func(i, j int) bool {
119-
return openProjectTimeEntries[i].Comment.Raw < openProjectTimeEntries[j].Comment.Raw
120-
})
121114

122115
start, _ := time.Parse("2006-01-02", startDate)
123116
end, _ := time.Parse("2006-01-02", endDate)

openproject/openproject.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func GetAllTimeEntries(config *config.Config, user User, startDate string, endDa
4242
SetBasicAuth("apikey", config.OpenProjectToken).
4343
SetHeader("Content-Type", "application/json").
4444
SetQueryParam("pageSize", "3000").
45-
SetQueryParam("sortBy", "[[\"updated_at\",\"desc\"]]").
45+
SetQueryParam("sortBy", "[[\"updated_at\",\"asc\"]]").
4646
// the operator is '<>d' and means between the dates
4747
SetQueryParam("filters", fmt.Sprintf(
4848
`[{"user":{"operator":"=","values":["%v"]}},{"spent_on":{"operator":"\u003c\u003ed","values":["%v","%v"]}}]`,

tmetric/tmetric.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"github.com/JankariTech/OpenProjectTmetricIntegration/config"
77
"github.com/go-resty/resty/v2"
8+
"sort"
89
)
910

1011
func GetAllTimeEntries(config *config.Config, tmetricUser User, startDate string, endDate string) ([]TimeEntry, error) {
@@ -39,6 +40,10 @@ func GetAllTimeEntries(config *config.Config, tmetricUser User, startDate string
3940
timeEntriesOfTheSelectedClient = append(timeEntriesOfTheSelectedClient, entry)
4041
}
4142
}
43+
sort.Slice(timeEntriesOfTheSelectedClient, func(i, j int) bool {
44+
return timeEntriesOfTheSelectedClient[i].StartTime < timeEntriesOfTheSelectedClient[j].StartTime
45+
})
46+
4247
return timeEntriesOfTheSelectedClient, nil
4348
}
4449

0 commit comments

Comments
 (0)