-
Notifications
You must be signed in to change notification settings - Fork 1
[NotReady] Invert zero state for null fields. #52
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
Open
kevpie
wants to merge
1
commit into
master
Choose a base branch
from
null_zero_state_inversion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,9 +96,9 @@ func (t *TimeDate) UnmarshalJSON(data []byte) error { | |
| // NullTime time that can be nil | ||
| type NullTimeDate struct { | ||
| nullTime | ||
| validNull bool | ||
| shadow null.Time | ||
| shadowValidNull bool | ||
| invalidNull bool | ||
| shadow null.Time | ||
| shadowInvalidNull bool | ||
| ShadowInit | ||
| } | ||
|
|
||
|
|
@@ -109,41 +109,39 @@ func (nt *NullTimeDate) Scan(value interface{}) error { | |
| case time.Time: | ||
| if v.IsZero() { | ||
| nt.Valid = false | ||
| nt.validNull = true | ||
| nt.invalidNull = true | ||
|
Contributor
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. Is this bool not being flipped because of invalidity?
Contributor
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. Also in this location! 👍 |
||
|
|
||
| } else { | ||
| nt.Time, nt.Valid = v, true | ||
| nt.validNull = false | ||
| nt.invalidNull = true | ||
| } | ||
| break | ||
| case []byte: | ||
| nt.Time, err = parseTimeDate(string(v)) | ||
| if nt.Time.IsZero() == true { | ||
| nt.Valid = false | ||
| nt.validNull = false | ||
| nt.invalidNull = true | ||
| return ErrorCouldNotScan("NullTimeDate", value) | ||
| } | ||
| nt.Valid = (err == nil) | ||
| if err == nil { | ||
| nt.validNull = false | ||
| nt.invalidNull = true | ||
| } | ||
| break | ||
| case string: | ||
| nt.Time, err = parseTimeDate(v) | ||
| if nt.Time.IsZero() == true { | ||
| nt.Valid = false | ||
| nt.validNull = false | ||
| nt.invalidNull = true | ||
| return ErrorCouldNotScan("NullTimeDate", value) | ||
| } | ||
| nt.Valid = (err == nil) | ||
| if err == nil { | ||
| nt.validNull = false | ||
| nt.invalidNull = true | ||
| } | ||
| break | ||
| default: | ||
| if value == nil { | ||
| nt.Valid = false | ||
| nt.validNull = true | ||
| nt.invalidNull = false | ||
| } else { | ||
| err = ErrorCouldNotScan("NullTimeDate", value) | ||
| } | ||
|
|
@@ -152,26 +150,24 @@ func (nt *NullTimeDate) Scan(value interface{}) error { | |
| // load shadow on first scan only | ||
| nt.DoInit(func() { | ||
| _ = nt.shadow.Scan(nt.Time) | ||
| if value == nil { | ||
| nt.shadowValidNull = true | ||
| } | ||
| nt.shadowInvalidNull = (value != nil) | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| // Value return the value of this field | ||
| func (nt NullTimeDate) Value() (driver.Value, error) { | ||
| if nt.validNull { | ||
| if !nt.invalidNull { | ||
| return nil, nil | ||
| } | ||
| return nt.Time, nil | ||
| } | ||
|
|
||
| // IsDirty if the shadow value does not match the field value | ||
| func (nt *NullTimeDate) IsDirty() bool { | ||
| if nt.validNull && nt.shadowValidNull { | ||
| if !nt.invalidNull && !nt.shadowInvalidNull { | ||
| return false | ||
| } else if nt.validNull == false && nt.shadowValidNull == false { | ||
| } else if nt.invalidNull && nt.shadowInvalidNull { | ||
| return !nt.Time.Equal(nt.shadow.Time) | ||
| } | ||
| return true | ||
|
|
@@ -185,7 +181,7 @@ func (nt NullTimeDate) IsSet() bool { | |
| // ShadowValue return the initial value of this field | ||
| func (nt NullTimeDate) ShadowValue() (driver.Value, error) { | ||
| if nt.InitDone() { | ||
| if nt.shadowValidNull { | ||
| if !nt.shadowInvalidNull { | ||
| return nil, nil | ||
| } | ||
| return nt.shadow.Value() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Same true false flip for this. Is it because it is invalid?
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.
Good question, this checks to see if it is a legitimate Zero time, 12AM which should not be considered...
Ok, now I see I need to change this. Probably remove the Zero Check altogether.