sort reverse chronological - now we have a lot more data

This commit is contained in:
Emil Lerch 2026-04-30 15:23:45 -07:00
parent 0c08cdda6c
commit 9bb0d8036b
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 9 additions and 4 deletions

View file

@ -16,11 +16,14 @@ pub fn run(allocator: std.mem.Allocator, svc: *zfin.DataService, symbol: []const
};
defer allocator.free(result.data);
// Sort chronologically (oldest first) providers may return in any order
// Sort newest-first the first row is the most recent quarter, which
// is the dominant query. Matches `git log` / `ls -lt` / `last` defaults
// and the TUI. `| head -N` gives you the N most recent quarters;
// `| tail` still works if you want oldest-first.
if (result.data.len > 1) {
std.mem.sort(zfin.EarningsEvent, result.data, {}, struct {
fn f(_: void, a: zfin.EarningsEvent, b: zfin.EarningsEvent) bool {
return a.date.days < b.date.days;
return a.date.days > b.date.days;
}
}.f);
}

View file

@ -34,11 +34,13 @@ pub fn loadData(app: *App) void {
app.earnings_data = result.data;
app.earnings_timestamp = result.timestamp;
// Sort chronologically (oldest first) providers may return in any order
// Sort newest-first this is what users expect on earnings tables
// everywhere (Yahoo, Morningstar, etc.) and keeps the most relevant
// quarter on the first visible row.
if (result.data.len > 1) {
std.mem.sort(zfin.EarningsEvent, result.data, {}, struct {
fn f(_: void, a: zfin.EarningsEvent, b: zfin.EarningsEvent) bool {
return a.date.days < b.date.days;
return a.date.days > b.date.days;
}
}.f);
}