Git Product home page Git Product logo

Comments (2)

puellanivis avatar puellanivis commented on September 28, 2024 2

The disagreement here happens because of a difference of what the zero value of a timestamppb is, vs the zero value of Golang’s time.Time value.

Note:

func main() {
	var a *timestamppb.Timestamp
	var t time.Time
	fmt.Println(a.AsTime())
	fmt.Println(t)
}

runs and prints:

1970-01-01 00:00:00 +0000 UTC
0001-01-01 00:00:00 +0000 UTC

Note that the zero value of a timestamppb is the Unix epoch, but the zero value time.Time is Jan 1st, 1 AD.

Summary: This is intended behavior, even if it is unexpected.

P.S.: Huh, after reading the whole report, you seem to understand all of this already?

from protobuf.

dsnet avatar dsnet commented on September 28, 2024

This is an unfortunate an edge-case in bridging the Go type system and the protobuf type system and there are no good answers other than being as consistent as possible across the module about how this is handled.

Of note, protoreflect.Message.IsValid says:

// IsValid reports whether the message is valid.
//
// An invalid message is an empty, read-only value.
//
// An invalid message often corresponds to a nil pointer of the concrete
// message type, but the details are implementation dependent.
// Validity is not part of the protobuf data model, and may not
// be preserved in marshaling or other operations.

That is, a nil pointer is semantically treated as an "empty, read-only value".
In the protobuf data model, reading the "seconds" and "nanos" fields of an empty Timestamp message would report 0, which results in a date of 1970-01-01.

from protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.