Skip to content

Unify timestamp format used by adapter #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
```
2 changes: 1 addition & 1 deletion postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
13 changes: 13 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -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)
}