mirror of
https://codeberg.org/scip/ts.git
synced 2025-12-17 12:31:06 +01:00
fixed format tests
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/knadh/koanf/providers/posflag"
|
"github.com/knadh/koanf/providers/posflag"
|
||||||
"github.com/knadh/koanf/v2"
|
"github.com/knadh/koanf/v2"
|
||||||
@@ -80,7 +81,7 @@ Example durations for second parameter:
|
|||||||
ModeDiff int = iota
|
ModeDiff int = iota
|
||||||
ModeAdd
|
ModeAdd
|
||||||
|
|
||||||
DefaultFormat string = "Mon Jan 02 15:04:05 MST"
|
DefaultFormat string = "Mon Jan 02 15:04:05 MST 2006"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -95,7 +96,10 @@ type Config struct {
|
|||||||
Args []string
|
Args []string
|
||||||
Output io.Writer
|
Output io.Writer
|
||||||
Mode int
|
Mode int
|
||||||
TZ string // for unit tests
|
|
||||||
|
// internal flags for [unit] tests
|
||||||
|
tz string
|
||||||
|
refTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitConfig(output io.Writer) (*Config, error) {
|
func InitConfig(output io.Writer) (*Config, error) {
|
||||||
|
|||||||
@@ -73,9 +73,9 @@ func (tp *TimestampProccessor) Parse(timestamp string) (time.Time, error) {
|
|||||||
return ts, err
|
return ts, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if tp.TZ != "" {
|
if tp.tz != "" {
|
||||||
// apply custom timezone
|
// apply custom timezone
|
||||||
zone, _ := time.LoadLocation(tp.TZ)
|
zone, _ := time.LoadLocation(tp.tz)
|
||||||
ts = ts.In(zone)
|
ts = ts.In(zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func TestParseTimestamps(t *testing.T) {
|
|||||||
testname := fmt.Sprintf("parsetimestamp-%s", strings.ReplaceAll(tt.input, " ", "-"))
|
testname := fmt.Sprintf("parsetimestamp-%s", strings.ReplaceAll(tt.input, " ", "-"))
|
||||||
t.Run(testname, func(t *testing.T) {
|
t.Run(testname, func(t *testing.T) {
|
||||||
var writer bytes.Buffer
|
var writer bytes.Buffer
|
||||||
tp := NewTP(&Config{Args: []string{tt.input}, Output: &writer, TZ: "UTC"}, now)
|
tp := NewTP(&Config{Args: []string{tt.input}, Output: &writer, tz: "UTC"}, now)
|
||||||
|
|
||||||
// writer.String()
|
// writer.String()
|
||||||
ts, err := tp.Parse(tt.input)
|
ts, err := tp.Parse(tt.input)
|
||||||
@@ -82,7 +82,7 @@ func TestParseTimestamps(t *testing.T) {
|
|||||||
|
|
||||||
err = tp.ProcessTimestamps()
|
err = tp.ProcessTimestamps()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, tt.want.String()+"\n", writer.String())
|
assert.EqualValues(t, tt.want.Format(DefaultFormat)+"\n", writer.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ func TestAddTimestamps(t *testing.T) {
|
|||||||
|
|
||||||
err := tp.ProcessTimestamps()
|
err := tp.ProcessTimestamps()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, tt.want.String()+"\n", writer.String())
|
assert.EqualValues(t, tt.want.Format(DefaultFormat)+"\n", writer.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func TestDatetime(t *testing.T) {
|
|||||||
{"date", now, "2025-09-25"},
|
{"date", now, "2025-09-25"},
|
||||||
{"time", now, "12:30:00"},
|
{"time", now, "12:30:00"},
|
||||||
{"unix", now, "1758803400"},
|
{"unix", now, "1758803400"},
|
||||||
{"datetime", now, "2025-09-25 12:30:00 +0000 UTC"},
|
{"datetime", now, "Thu Sep 25 12:30:00 UTC 2025"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ exec ts -e
|
|||||||
stdout 'yesterday'
|
stdout 'yesterday'
|
||||||
|
|
||||||
exec ts 3/1/2014
|
exec ts 3/1/2014
|
||||||
stdout 2014-01-03
|
stdout 'Fri Jan 03'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user