Skip to content

Commit

Permalink
Merge pull request #39 from mirza-s/main
Browse files Browse the repository at this point in the history
time.Time: test for zero value using IsZero()
  • Loading branch information
200sc committed Mar 16, 2024
2 parents 568459e + d6bc82f commit e846d30
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 60 deletions.
12 changes: 6 additions & 6 deletions gen_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ func (f File) typeMarshallers() map[string]string {
}
out[typeString] = "iohelp.WriteUint32(w, uint32(len(%ASGN)))\n" +
"w.Write([]byte(%ASGN))"
out[typeDate] = "if %ASGN != (time.Time{}) {\n" +
"\tiohelp.WriteInt64(w, ((%ASGN).UnixNano() / 100))\n" +
"} else {\n" +
out[typeDate] = "if (%ASGN).IsZero() {\n" +
"\tiohelp.WriteInt64(w, 0)\n" +
"} else {\n" +
"\tiohelp.WriteInt64(w, ((%ASGN).UnixNano() / 100))\n" +
"}"
for _, st := range f.Structs {
out[st.Name] = fmtEncode + fmtErrReturn
Expand Down Expand Up @@ -279,10 +279,10 @@ func (f File) typeByters() map[string]string {
out[typeString] = "iohelp.WriteUint32Bytes(buf[at:], uint32(len(%ASGN)))\n" +
"copy(buf[at+4:at+4+len(%ASGN)], []byte(%ASGN))\n" + fmtAdd4PlusLenToAt

out[typeDate] = "if %ASGN != (time.Time{}) {\n" +
"\tiohelp.WriteInt64Bytes(buf[at:], ((%ASGN).UnixNano() / 100))\n" +
"} else {\n" +
out[typeDate] = "if (%ASGN).IsZero() {\n" +
"\tiohelp.WriteInt64Bytes(buf[at:], 0)\n" +
"} else {\n" +
"\tiohelp.WriteInt64Bytes(buf[at:], ((%ASGN).UnixNano() / 100))\n" +
"}\n" +
"at += 8"
for _, st := range f.Structs {
Expand Down
12 changes: 6 additions & 6 deletions testdata/generated-always-pointers/basic_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions testdata/generated-always-pointers/date.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions testdata/generated-private/basic_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions testdata/generated-private/date.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions testdata/generated/basic_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions testdata/generated/date.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e846d30

Please sign in to comment.