mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-19 06:01:36 +03:00
c5cf6c0cc0
* Moved time functions from pkg stringz to pkg timez * Refactor options.Opt * wip: initial work on configurable time layout * wip: most printers now respect format.datetime and friends * Folded pkg timefmt into timez * Refactor options.Opt; refine options * Add 'sq config set OPTION --help' mechanism * Finished completion of OptDateFormatAsNumber and OptTimeFormatAsNumber
42 lines
979 B
Go
42 lines
979 B
Go
package csvw_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/neilotoole/sq/cli/output"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/neilotoole/sq/cli/output/csvw"
|
|
"github.com/neilotoole/sq/libsq/core/kind"
|
|
"github.com/neilotoole/sq/libsq/core/sqlz"
|
|
"github.com/neilotoole/sq/testh"
|
|
)
|
|
|
|
func TestDateTimeHandling(t *testing.T) {
|
|
var (
|
|
colNames = []string{"col_datetime", "col_date", "col_time"}
|
|
kinds = []kind.Kind{kind.Datetime, kind.Date, kind.Time}
|
|
when = time.Unix(0, 0).UTC()
|
|
)
|
|
const want = "1970-01-01T00:00:00Z\t1970-01-01\t00:00:00\n"
|
|
|
|
recMeta := testh.NewRecordMeta(colNames, kinds)
|
|
buf := &bytes.Buffer{}
|
|
|
|
pr := output.NewPrinting()
|
|
pr.ShowHeader = false
|
|
|
|
w := csvw.NewRecordWriter(buf, pr, csvw.Tab)
|
|
require.NoError(t, w.Open(recMeta))
|
|
|
|
rec := sqlz.Record{&when, &when, &when}
|
|
require.NoError(t, w.WriteRecords([]sqlz.Record{rec}))
|
|
require.NoError(t, w.Close())
|
|
|
|
require.Equal(t, want, buf.String())
|
|
t.Log(buf.String())
|
|
}
|