support --period
parent
8ab5a0edf5
commit
62e65c47df
|
|
@ -3,7 +3,7 @@ package cli
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Files FileList
|
Files FileList
|
||||||
Query struct {
|
Query struct {
|
||||||
Period string
|
Period Period
|
||||||
Sort string
|
Sort string
|
||||||
NoRounding bool
|
NoRounding bool
|
||||||
Depth int
|
Depth int
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FlagStringArray []string
|
type FlagStringArray []string
|
||||||
|
|
@ -33,3 +34,35 @@ func (fileList *FileList) Set(s string) error {
|
||||||
}
|
}
|
||||||
return (*FlagStringArray)(fileList).Set(s)
|
return (*FlagStringArray)(fileList).Set(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Period struct {
|
||||||
|
Start time.Time
|
||||||
|
Stop time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (period Period) Empty() bool {
|
||||||
|
return period.Stop.Sub(period.Start) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (period *Period) String() string {
|
||||||
|
return fmt.Sprintf("%s..%s", period.Start, period.Stop)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (period *Period) Set(s string) error {
|
||||||
|
if result, err := time.Parse("2006", s); err == nil {
|
||||||
|
period.Start = result
|
||||||
|
period.Stop = result.AddDate(1, 0, 0).Add(-1 * time.Minute)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if result, err := time.Parse("2006-01", s); err == nil {
|
||||||
|
period.Start = result
|
||||||
|
period.Stop = result.AddDate(0, 1, 0).Add(-1 * time.Minute)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if result, err := time.Parse("2006-01-02", s); err == nil {
|
||||||
|
period.Start = result
|
||||||
|
period.Stop = result.AddDate(0, 0, 1).Add(-1 * time.Minute)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unimplemented format: %s", s)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package cli
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ func Main() {
|
||||||
|
|
||||||
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||||
fs.Var(&config.Files, "f", "paths to files")
|
fs.Var(&config.Files, "f", "paths to files")
|
||||||
fs.StringVar(&config.Query.Period, "period", "", "period")
|
fs.Var(&config.Query.Period, "period", "period")
|
||||||
fs.StringVar(&config.Query.Sort, "S", "", "sort ie date")
|
fs.StringVar(&config.Query.Sort, "S", "", "sort ie date")
|
||||||
fs.BoolVar(&config.Query.NoRounding, "no-rounding", false, "no rounding")
|
fs.BoolVar(&config.Query.NoRounding, "no-rounding", false, "no rounding")
|
||||||
fs.IntVar(&config.Query.Depth, "depth", 0, "depth grouping")
|
fs.IntVar(&config.Query.Depth, "depth", 0, "depth grouping")
|
||||||
|
|
@ -47,8 +48,14 @@ func Main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if period := config.Query.Period; period != "" {
|
if period := config.Query.Period; !period.Empty() {
|
||||||
panic(period)
|
after := period.Start.Format("2006-01-02")
|
||||||
|
before := period.Stop.Format("2006-01-02")
|
||||||
|
deltas = deltas.Like(
|
||||||
|
ledger.LikeAfter(after),
|
||||||
|
ledger.LikeBefore(before),
|
||||||
|
)
|
||||||
|
log.Printf("period=%+v after=%s before=%s", period, after, before)
|
||||||
}
|
}
|
||||||
|
|
||||||
if depth := config.Query.Depth; depth > 0 {
|
if depth := config.Query.Depth; depth > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue