Skip to content

Commit

Permalink
fix: continue working with non UTC timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 28, 2022
1 parent 43a65a0 commit 033c413
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Main features are:

Unsupported:

- Server timezones other than UTC.
- `DateTime64`

Resources:

Expand Down
15 changes: 3 additions & 12 deletions ch/chproto/server_info.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package chproto

import (
"fmt"
)

type ServerInfo struct {
Name string
MinorVersion uint64
Expand All @@ -25,18 +21,13 @@ func (srv *ServerInfo) ReadFrom(rd *Reader) (err error) {
return err
}

timezone, err := rd.String()
if err != nil {
if _, err := rd.String(); err != nil { // timezone
return err
}
if timezone != "UTC" {
return fmt.Errorf("ch: ClickHouse server uses timezone=%q, expected UTC", timezone)
}

if _, err = rd.String(); err != nil { // display name
if _, err := rd.String(); err != nil { // display name
return err
}
if _, err = rd.Uvarint(); err != nil { // server version patch
if _, err := rd.Uvarint(); err != nil { // server version patch
return err
}

Expand Down
5 changes: 4 additions & 1 deletion ch/chschema/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ func AppendString(b []byte, s string) []byte {
}

func AppendTime(b []byte, tm time.Time) []byte {
return tm.UTC().AppendFormat(b, "'2006-01-02 15:04:05'")
b = append(b, "toDateTime('"...)
b = tm.UTC().AppendFormat(b, "2006-01-02 15:04:05")
b = append(b, "', 'UTC')"...)
return b
}

func AppendBytes(b []byte, bytes []byte) []byte {
Expand Down

0 comments on commit 033c413

Please sign in to comment.