BUG: Timestamp.toObject() returning zeroed value

Open
#222 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
backend

Research direction

Start at Timestamp.toObject() and compare its result with getSeconds() and getNanos() when the value is created through fromDate(), using the dateToTs() example from the report. Reproduce the zeroed fields on version 3.21.4; done when toObject() returns the populated seconds and milliseconds values.

Written by the indexing model from the issue text.

Description

question

In the latest version, 3.21.4, the Timestamp.toObject() function isn't working correctly.

Previously it would return the timestamp as an object with keys for seconds and milliseconds. However now it is returning zero values for both.

This is a function where I noticed the issue, I've added some logging which pointed out toObject() as being the problem.

function dateToTs(date: Date): Timestamp {
  const ts = new Timestamp();
  ts.fromDate(date);
  console.log(
    "date:",
    date,
    "timestamp:",
    ts.getSeconds(),
    ts.getNanos(),
    ts.toObject(),
  );
  return ts;
}

See the screenshot below for the resulting console log, where you can see the seconds and milliseconds are set, but the toObject return is zeroed
image

Dominant language
JavaScript
Stars
471
Forks
92
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from protocolbuffers/protobuf-javascript

All issues in protocolbuffers/protobuf-javascript

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.