mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
added unit test + docs for the various sort modes.
This commit is contained in:
@@ -51,8 +51,8 @@ func sortTable(data *Tabdata, col int) {
|
||||
func compare(a string, b string) bool {
|
||||
var comp bool
|
||||
|
||||
switch {
|
||||
case SortNumeric:
|
||||
switch SortMode {
|
||||
case "numeric":
|
||||
left, err := strconv.Atoi(a)
|
||||
if err != nil {
|
||||
left = 0
|
||||
@@ -62,7 +62,7 @@ func compare(a string, b string) bool {
|
||||
right = 0
|
||||
}
|
||||
comp = left < right
|
||||
case SortAge:
|
||||
case "duration":
|
||||
left, err := str2duration.ParseDuration(a)
|
||||
if err != nil {
|
||||
left = 0
|
||||
@@ -72,7 +72,7 @@ func compare(a string, b string) bool {
|
||||
right = 0
|
||||
}
|
||||
comp = left.Seconds() < right.Seconds()
|
||||
case SortTime:
|
||||
case "time":
|
||||
left, _ := dateparse.ParseAny(a)
|
||||
right, _ := dateparse.ParseAny(b)
|
||||
comp = left.Unix() < right.Unix()
|
||||
|
||||
Reference in New Issue
Block a user