Skip to content

Commit

Permalink
date and timezone issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Aug 12, 2023
1 parent c43a92b commit c13617f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
14 changes: 13 additions & 1 deletion v2/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strconv"
"strings"
"sync"
"time"
)

type ConnectionState int
Expand Down Expand Up @@ -86,7 +87,8 @@ type Connection struct {
date int
timestamp int
}
bad bool
bad bool
dbTimeLoc *time.Location
}

type OracleConnector struct {
Expand Down Expand Up @@ -535,9 +537,19 @@ func (conn *Connection) OpenWithContext(ctx context.Context) error {
return err
}
}
conn.getDBTimeZone()
return nil
}

func (conn *Connection) getDBTimeZone() {
var current time.Time
err := conn.QueryRowContext(context.Background(), "SELECT SYSTIMESTAMP FROM DUAL", nil).Scan(&current)
if err != nil {
conn.dbTimeLoc = time.UTC
}
conn.dbTimeLoc = current.Location()
}

// Begin a transaction
func (conn *Connection) Begin() (driver.Tx, error) {
conn.connOption.Tracer.Print("Begin transaction")
Expand Down
12 changes: 9 additions & 3 deletions v2/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ func (par *ParameterInfo) load(conn *Connection) error {
case ROWID:
par.MaxLen = 128
case DATE:
par.MaxLen = 7
par.MaxLen = converters.MAX_LEN_DATE
case IBFloat:
par.MaxLen = 4
case IBDouble:
par.MaxLen = 8
case TimeStampTZ_DTY:
par.MaxLen = 13
par.MaxLen = converters.MAX_LEN_TIMESTAMP
case IntervalYM_DTY:
fallthrough
case IntervalDS_DTY:
Expand Down Expand Up @@ -996,10 +996,16 @@ func (par *ParameterInfo) decodePrimValue(conn *Connection, udt bool) error {
case TimeStampDTY, TimeStampeLTZ, TimeStampLTZ_DTY, TIMESTAMPTZ, TimeStampTZ_DTY:
fallthrough
case TIMESTAMP, DATE:
par.oPrimValue, err = converters.DecodeDate(par.BValue)
tempTime, err := converters.DecodeDate(par.BValue)
if err != nil {
return err
}
if par.DataType == DATE && conn.dbTimeLoc != time.UTC {
par.oPrimValue = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(),
tempTime.Hour(), tempTime.Minute(), tempTime.Second(), tempTime.Nanosecond(), conn.dbTimeLoc)
} else {
par.oPrimValue = tempTime
}
case OCIClobLocator, OCIBlobLocator:
var locator []byte
if !udt {
Expand Down

0 comments on commit c13617f

Please sign in to comment.