Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/export/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/csv"
"fmt"
"os"
"slices"
"time"

"github.com/DylanDevelops/tmpo/internal/settings"
Expand All @@ -27,7 +28,7 @@ func ToCSV(entries []*storage.TimeEntry, filename string, inUtc bool) error {
return fmt.Errorf("failed to write header: %w", err)
}

for _, entry := range entries {
for _, entry := range slices.Backward(entries) {
endTime := ""
if entry.EndTime != nil {
endTime = toCorrectCsvTimestamp(*entry.EndTime, inUtc)
Expand Down
29 changes: 21 additions & 8 deletions internal/export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@ func TestToCSV(t *testing.T) {
// Verify header
assert.Equal(t, []string{"Project", "Start Time", "End Time", "Duration (hours)", "Description", "Milestone"}, records[0])

// Verify first entry
assert.Equal(t, "test-project", records[1][0])
// Verify entries are in chronological order
assert.Equal(t, "another-project", records[1][0])
assert.Equal(t, "2024-01-01 09:00:00", records[1][1])
assert.Equal(t, "2024-01-01 17:00:00", records[1][2])
assert.Equal(t, "8.00", records[1][3]) // 8 hours
assert.Equal(t, "Test work", records[1][4])
assert.Equal(t, "", records[1][5]) // No milestone
assert.Equal(t, "8.00", records[1][3])
assert.Equal(t, "More work", records[1][4])
assert.Equal(t, "", records[1][5])

assert.Equal(t, "test-project", records[2][0])
assert.Equal(t, "2024-01-01 09:00:00", records[2][1])
assert.Equal(t, "2024-01-01 17:00:00", records[2][2])
assert.Equal(t, "8.00", records[2][3])
assert.Equal(t, "Test work", records[2][4])
assert.Equal(t, "", records[2][5])
})

t.Run("handles running entries", func(t *testing.T) {
Expand Down Expand Up @@ -195,12 +202,18 @@ func TestToJson(t *testing.T) {
// Should have 2 entries
assert.Len(t, exportedEntries, 2)

// Verify first entry
assert.Equal(t, "test-project", exportedEntries[0].Project)
// Verify entries are in chronological order
assert.Equal(t, "another-project", exportedEntries[0].Project)
assert.Equal(t, "2024-01-01T09:00:00Z", exportedEntries[0].StartTime)
assert.Equal(t, "2024-01-01T17:00:00Z", exportedEntries[0].EndTime)
assert.Equal(t, 8.0, exportedEntries[0].Duration)
assert.Equal(t, "Test work", exportedEntries[0].Description)
assert.Equal(t, "More work", exportedEntries[0].Description)

assert.Equal(t, "test-project", exportedEntries[1].Project)
assert.Equal(t, "2024-01-01T09:00:00Z", exportedEntries[1].StartTime)
assert.Equal(t, "2024-01-01T17:00:00Z", exportedEntries[1].EndTime)
assert.Equal(t, 8.0, exportedEntries[1].Duration)
assert.Equal(t, "Test work", exportedEntries[1].Description)
})

t.Run("handles running entries", func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/export/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"time"

"github.com/DylanDevelops/tmpo/internal/settings"
Expand All @@ -22,7 +23,7 @@ type ExportEntry struct {
func ToJson(entries []*storage.TimeEntry, filename string, inUtc bool) error {
var exportEntries []ExportEntry

for _, entry := range entries {
for _, entry := range slices.Backward(entries) {
export := ExportEntry{
Project: entry.ProjectName,
StartTime: toCorrectJsonTimestamp(entry.StartTime, inUtc),
Expand Down
Loading