diff --git a/README.md b/README.md index b6a823b..e0b27b9 100644 --- a/README.md +++ b/README.md @@ -83,5 +83,5 @@ docker run -it --rm -p 5433:5432 -e "POSTGRES_USER=rel" -e "POSTGRES_PASSWORD=te ### Run tests ```console -POSTGRESQL_DATABASE="postgres://rel:test@localhost:5433/rel_test?timezone=Asia/Jakarta" go test ./... +POSTGRESQL_DATABASE="postgres://rel:test@localhost:5433/rel_test" go test ./... ``` diff --git a/postgres.go b/postgres.go index 077bed4..1e74b9e 100644 --- a/postgres.go +++ b/postgres.go @@ -170,7 +170,7 @@ func columnMapper(column *rel.Column) (string, int, int) { case rel.DateTime: typ = "TIMESTAMPTZ" if t, ok := column.Default.(time.Time); ok { - column.Default = t.Format("2006-01-02 15:04:05") + column.Default = FormatTime(t) } case rel.Int, rel.BigInt, rel.Text: column.Limit = 0 diff --git a/quote.go b/quote.go index 3b3a05f..3f45ce4 100644 --- a/quote.go +++ b/quote.go @@ -45,6 +45,6 @@ func (c ValueConvert) ConvertValue(v interface{}) (driver.Value, error) { default: return v, nil case time.Time: - return v.Truncate(time.Microsecond).Format("2006-01-02 15:04:05.999999999Z07:00:00"), nil + return FormatTime(v), nil } } diff --git a/util.go b/util.go new file mode 100644 index 0000000..4f5527b --- /dev/null +++ b/util.go @@ -0,0 +1,13 @@ +package postgres + +import ( + "time" +) + +// TimeLayout used by PostgreSQL adapter. +const TimeLayout = "2006-01-02 15:04:05.999999999Z07:00:00" + +// FormatTime formats time to PostgreSQL format. +func FormatTime(t time.Time) string { + return t.Truncate(time.Microsecond).Format(TimeLayout) +}