-
Notifications
You must be signed in to change notification settings - Fork 36
fix: use DateTime instead of Time for time data type #395
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,24 @@ | |
| module ActiveRecord | ||
| module Type | ||
| module Spanner | ||
| class Time < ActiveRecord::Type::Time | ||
| class Time < ActiveRecord::Type::DateTime | ||
| def cast_value value | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support nanoseconds precision in GoogleSQL dialect. By default cast_value is stripping the precision to 6. |
||
| if value.is_a? ::String | ||
| return if value.empty? | ||
| begin | ||
| if ActiveRecord.default_timezone == :utc | ||
| ::DateTime.parse(value).to_time.getutc | ||
| else | ||
| ::Time.parse(value).getlocal | ||
| end | ||
| rescue StandardError | ||
| super | ||
| end | ||
| else | ||
| super | ||
| end | ||
| end | ||
|
|
||
| def serialize_with_isolation_level value, isolation_level | ||
| if value == :commit_timestamp | ||
| return "PENDING_COMMIT_TIMESTAMP()" if isolation_level == :dml | ||
|
|
@@ -24,18 +41,14 @@ def serialize value | |
| val.acts_like?(:time) ? val.utc.rfc3339(9) : val | ||
| end | ||
|
|
||
| def user_input_in_time_zone value | ||
| return value.in_time_zone if value.is_a? ::Time | ||
| super value | ||
| def value_from_multiparameter_assignment values | ||
| defaults = { 1 => 2000, 2 => 1, 3 => 1 } | ||
| super defaults.merge(values) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def cast_value value | ||
| if value.is_a? ::String | ||
| value = value.empty? ? nil : ::Time.parse(value) | ||
| end | ||
|
|
||
| def apply_seconds_precision value | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support nanoseconds precision in GoogleSQL dialect. By default cast_value is stripping the precision to 6. |
||
| value | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.