-
Notifications
You must be signed in to change notification settings - Fork 82
feat: support configuring custom time.Location for datetime encoding and decoding via DSN #260
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
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
… encoding and decoding via DSN
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #260 +/- ##
==========================================
- Coverage 75.11% 74.93% -0.19%
==========================================
Files 32 33 +1
Lines 6471 6458 -13
==========================================
- Hits 4861 4839 -22
- Misses 1325 1331 +6
- Partials 285 288 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
thx for the PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for configuring a custom time.Location
via the DSN for all DATETIME and TIMESTAMP operations
- Introduces a new
Timezone
DSN parameter and parses it intomsdsn.Config.Timezone
- Defines a global
loc
variable and swaps outtime.UTC
forloc
in all encode/decode functions - Updates bulk-copy methods and modern Go 1.19 code paths to use the configured timezone
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
types.go | Swapped hardcoded time.UTC for loc in multiple encode/decode functions |
mssql.go | Added global loc , set from Config.Timezone in createDialer |
mssql_go19.go | Updated civil.Date/DateTime/Time encoding calls to use loc |
msdsn/conn_str.go | Added Timezone constant, Config.Timezone field, and parsing |
bulkcopy.go | Renamed receiver in CreateBulk* and changed time.ParseInLocation to use loc |
Comments suppressed due to low confidence (2)
bulkcopy.go:55
- [nitpick] Receiver name
c
is ambiguous. For consistency with other methods, consider renaming it tocn
orconn
to clarify that it's a connection.
func (c *Conn) CreateBulk(table string, columns []string) (_ *Bulk) {
msdsn/conn_str.go:332
- There are no unit tests covering the new
Timezone
DSN parameter parsing. Consider adding tests for valid, invalid, and missing timezone values to ensure robust behavior.
tz, ok := params[Timezone]
I’ve tried to add some test cases, but I’m not sure if they’re correct. I’m still new to this project and not yet very familiar with how the tests are typically written. |
a270a91
to
2a8b901
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
094fd19
to
b92afbd
Compare
Hi @shueybubbles I’m now passing the timezone through the encoding parameters instead of relying on a global variable. However, despite multiple adjustments, the test continues to fail with the same error (missing Location in call to Date). I could use some help identifying what might be going wrong or if there’s a better way to ensure the timezone is correctly applied during decryption and scanning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enables specifying a custom time.Location
via the DSN so that all DATETIME and TIMESTAMP fields are encoded and decoded using that timezone rather than UTC.
- Updated all decode/encode helpers to accept a
*time.Location
. - Propagated the
Encoding.Timezone
setting throughreadFixedType
,makeParam
, and bulk-copy paths. - Extended DSN parsing (
msdsn.Parse
) and URL generation to handle atimezone
parameter, and added tests covering default vs. custom timezone behavior.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
types.go | Added loc *time.Location parameters to decode/encode funcs & wrapped reader to capture DSN timezone |
msdsn/conn_str.go | Added Timezone DSN key, parsed timezone param, and included it in URL |
mssql.go | Pulled Timezone from Config to drive encodeDateTimeOffset , encodeDateTime2 , etc. |
mssql_go19.go | Same propagation of custom timezone for Go 1.9 driver path |
bulkcopy.go | Applied custom timezone when encoding values in bulk operations |
tds_test.go | Initialized Encoding.Timezone from env var |
queries_test.go | New TestCustomTimezone covering behavior with/without custom timezone |
Comments suppressed due to low confidence (1)
queries_test.go:2826
- Instead of passing a formatted string, pass the
time.Time
value directly (sql.Named("ts", inputTime)
) to ensure the driver’s timezone encoding logic is exercised.
_, err = conn.Exec("insert into test (ts) values (@ts)", sql.Named("ts", inputTime.Format("2006-01-02 15:04:05")))
8fb2517
to
4e508fc
Compare
update the readme with directions on how to use the parameter |
Hi @shueybubbles Please let me know if there’s anything else that needs to be done from my end. I appreciate your time and effort in reviewing this. |
please resolve the comments that have been addressed |
Completed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi , @apoorvdeshmukh @stuartpa |
This improvement introduces the ability to specify a custom timezone through the DSN, enabling users to define a global timezone offset for all DATETIME and TIMESTAMP fields. It is designed to handle scenarios where the database stores datetime values in a specific local timezone rather than UTC.
By allowing a timezone parameter in the DSN, this change resolves issues such as microsoft/go-mssqldb#233, ensuring consistent parsing and encoding of datetime values. This enhancement significantly improves compatibility and flexibility, especially for applications operating across multiple timezones.
Fix issue goravel/goravel#699