all repos

clerk @ b238a8c852e3f47486117f346684c4e92f7b98b1

missing tooling for ledger/hledger
3 files changed, 16 insertions(+), 20 deletions(-)
extact all ast.Date to string code into .String() method
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-08-16 12:25:42 +0300
Authored at: 2026-08-15 18:59:40 +0300
Change ID: oqupqktlmooxryxuwyvuvvomzlnslwuk
Parent: b457e3f
M internal/analyzer/build.go
···
        1
        1
         package analyzer

      
        2
        2
         

      
        3
        3
         import (

      
        4
        
        -	"fmt"

      
        5
        4
         	"sort"

      
        6
        5
         	"strings"

      
        7
        6
         

      ···
        45
        44
         

      
        46
        45
         func TxDuplicateKey(tx *ast.Transaction) string {

      
        47
        46
         	var b strings.Builder

      
        48
        
        -	fmt.Fprintf(&b, "%04d-%02d-%02d|", tx.Date.Year, tx.Date.Month, tx.Date.Day)

      
        
        47
        +	b.WriteString(tx.Date.String())

      
        
        48
        +	b.WriteByte('|')

      
        49
        49
         	if tx.Payee != nil {

      
        50
        50
         		b.WriteString(tx.Payee.Name)

      
        51
        51
         	}

      ···
        82
        82
         		}

      
        83
        83
         		key := TxDuplicateKey(e)

      
        84
        84
         		a.TransactionsByKey[key] = append(a.TransactionsByKey[key], e)

      
        85
        
        -		a.TransactionsCountByDate[formatDate(e.Date)]++

      
        
        85
        +		a.TransactionsCountByDate[e.Date.String()]++

      
        86
        86
         	case *ast.PeriodicTransaction:

      
        87
        87
         		a.PeriodicTransactions = append(a.PeriodicTransactions, e)

      
        88
        88
         		a.addPostings(fileIndex, e.Postings, nil)

      ···
        260
        260
         func (a *Analysis) collectDates() {

      
        261
        261
         	seen := make(map[string]bool)

      
        262
        262
         	for _, tx := range a.Transactions {

      
        263
        
        -		s := formatDate(tx.Date)

      
        
        263
        +		s := tx.Date.String()

      
        264
        264
         		if s != "" && !seen[s] {

      
        265
        265
         			seen[s] = true

      
        266
        266
         			a.Dates = append(a.Dates, tx.Date)

      ···
        306
        306
         

      
        307
        307
         // CountTransactionsOnDate returns the number of transactions on d.

      
        308
        308
         func (a *Analysis) CountTransactionsOnDate(d ast.Date) int {

      
        309
        
        -	return a.TransactionsCountByDate[formatDate(d)]

      
        310
        
        -}

      
        311
        
        -

      
        312
        
        -func formatDate(d ast.Date) string {

      
        313
        
        -	if d.Year == 0 && d.Month == 0 && d.Day == 0 {

      
        314
        
        -		return ""

      
        315
        
        -	}

      
        316
        
        -	if d.Month < 1 || d.Month > 12 || d.Day < 1 || d.Day > 31 {

      
        317
        
        -		return ""

      
        318
        
        -	}

      
        319
        
        -	return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)

      
        
        309
        +	return a.TransactionsCountByDate[d.String()]

      
        320
        310
         }

      
        321
        311
         

      
        322
        312
         func (a *Analysis) addCommodityUsage(fileIndex int, am *ast.Amount, date *ast.Date) {

      
M internal/linter/rule_orderdate.go
···
        25
        25
         				finds = append(finds, Find{

      
        26
        26
         					Code:     o.ID(),

      
        27
        27
         					Severity: o.Severity(),

      
        28
        
        -					Message:  fmt.Sprintf("transaction is out of chronological order (date %s before %s)", o.dateString(txn.Date), o.dateString(*anchor)),

      
        
        28
        +					Message:  fmt.Sprintf("transaction is out of chronological order (date %s before %s)", txn.Date, *anchor),

      
        29
        29
         					Span:     txn.Date.Span,

      
        30
        30
         				})

      
        31
        31
         				continue

      ···
        35
        35
         	}

      
        36
        36
         	return finds

      
        37
        37
         }

      
        38
        
        -

      
        39
        
        -func (o OrderDate) dateString(d ast.Date) string {

      
        40
        
        -	return fmt.Sprintf("%d-%02d-%02d", d.Year, d.Month, d.Day)

      
        41
        
        -}

      
M journal/ast/ast.go
···
        1
        1
         package ast

      
        2
        2
         

      
        3
        3
         import (

      
        
        4
        +	"fmt"

      
        4
        5
         	"strings"

      
        5
        6
         

      
        6
        7
         	"olexsmir.xyz/clerk/journal/token"

      ···
        53
        54
         		return 1

      
        54
        55
         	}

      
        55
        56
         	return 0

      
        
        57
        +}

      
        
        58
        +

      
        
        59
        +// String renders d as "YYYY-MM-DD", or "" for an unset or invalid date.

      
        
        60
        +func (d Date) String() string {

      
        
        61
        +	if (d.Year == 0 && d.Month == 0 && d.Day == 0) ||

      
        
        62
        +		(d.Month < 1 || d.Month > 12 || d.Day < 1 || d.Day > 31) {

      
        
        63
        +		return ""

      
        
        64
        +	}

      
        
        65
        +	return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)

      
        56
        66
         }

      
        57
        67
         

      
        58
        68
         type Time struct {