Skip to content

Commit 6b33dfc

Browse files
authored
Unify timestamp format used by adapter (#12)
* Unify timestamp format used by adapter * Refactor and move time formating to reusable function
1 parent 873dc18 commit 6b33dfc

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ docker run -it --rm -p 5433:5432 -e "POSTGRES_USER=rel" -e "POSTGRES_PASSWORD=te
8383
### Run tests
8484

8585
```console
86-
POSTGRESQL_DATABASE="postgres://rel:test@localhost:5433/rel_test?timezone=Asia/Jakarta" go test ./...
86+
POSTGRESQL_DATABASE="postgres://rel:test@localhost:5433/rel_test" go test ./...
8787
```

postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func columnMapper(column *rel.Column) (string, int, int) {
170170
case rel.DateTime:
171171
typ = "TIMESTAMPTZ"
172172
if t, ok := column.Default.(time.Time); ok {
173-
column.Default = t.Format("2006-01-02 15:04:05")
173+
column.Default = FormatTime(t)
174174
}
175175
case rel.Int, rel.BigInt, rel.Text:
176176
column.Limit = 0

quote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ func (c ValueConvert) ConvertValue(v interface{}) (driver.Value, error) {
4545
default:
4646
return v, nil
4747
case time.Time:
48-
return v.Truncate(time.Microsecond).Format("2006-01-02 15:04:05.999999999Z07:00:00"), nil
48+
return FormatTime(v), nil
4949
}
5050
}

util.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package postgres
2+
3+
import (
4+
"time"
5+
)
6+
7+
// TimeLayout used by PostgreSQL adapter.
8+
const TimeLayout = "2006-01-02 15:04:05.999999999Z07:00:00"
9+
10+
// FormatTime formats time to PostgreSQL format.
11+
func FormatTime(t time.Time) string {
12+
return t.Truncate(time.Microsecond).Format(TimeLayout)
13+
}

0 commit comments

Comments
 (0)