Skip to content

Timestamp struct used in models.go seems incoherent with the used date format #26

Description

@florianBillot

Hi guys, I’m implementing a webhook handler that listens to GetStream Call events. To ease events payload unmarshaling, I’m trying to use the events structs in getstream-go/models.go.
But it seems that the date type Timestamp is not coherent with the date format sent by Getstream in the events payloads.

type Timestamp struct {
	Time *time.Time
}

func (t Timestamp) MarshalJSON() ([]byte, error) {
	return json.Marshal(t.Time)
}

func (t *Timestamp) UnmarshalJSON(data []byte) error {
	strData := string(data)
	if strData == "null" {
		return nil
	}

	ns, err := strconv.ParseInt(strData, 10, 64)
	if err != nil {
		return fmt.Errorf("failed to parse timestamp: %w", err)
	}

	utcT := time.Unix(0, ns).UTC()
	t.Time = &utcT
	return nil
}

With this implementation from getstream/rfc3339.go, the date format should be something like « 1739803521 » but the GetStream events payload contains the dates in that format: « 2025-02-13T16:45:22.746736895Z ».
So the UnmarshalJSON method can’t be used right away.

Is it the expected behavior?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions