Skip to content

Commit

Permalink
improve sorting entries with a single day
Browse files Browse the repository at this point in the history
  • Loading branch information
kwo committed Jan 29, 2024
1 parent 334fc58 commit 9267632
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Dayone To Markdown

## TODO
* https://github.com/ncruces/go-sqlite3

Export Dayone to Markdown.

[![tag](https://img.shields.io/github/tag/kwo/dayone2md.svg)](https://github.com/kwo/dayone2md/releases)
Expand Down
18 changes: 15 additions & 3 deletions dayone2md.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ func sortEntries(j *Journal, groupByDay, sortWithinDaysReverse bool) (map[string
filenames[e.UUID] = filename
}

// sort day entries
// sort entries within days
for _, dayEntries := range entries {
slices.SortFunc(dayEntries, func(a, b *Entry) int {
if sortWithinDaysReverse {
return b.CreationDate.Compare(a.CreationDate)
return sortEntriesWithinDays(b, a)
}
return a.CreationDate.Compare(b.CreationDate)
return sortEntriesWithinDays(a, b)
})
}

Expand All @@ -169,6 +169,18 @@ func sortEntries(j *Journal, groupByDay, sortWithinDaysReverse bool) (map[string
return entries, filenames, names
}

func sortEntriesWithinDays(a, b *Entry) int {
x := a.CreationDate.Compare(b.CreationDate)
if x != 0 {
return x
}
x = strings.Compare(a.Title, b.Title)
if x != 0 {
return x
}
return strings.Compare(a.Text, b.Text)
}

func calcFilename(dt time.Time, groupByDay bool) string {
if groupByDay {
return dt.Format("2006-01-02")
Expand Down

0 comments on commit 9267632

Please sign in to comment.