-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
google.protobuf.Timestamp #437
Comments
Reference: https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto Looks like this is just a wrapper for "seconds of UTC time since Unix epoch". It should be safe to include this file in your project and to work with Timestamp#seconds. Minimal proto: syntax = "proto3";
package google.protobuf;
message Timestamp {
int64 seconds = 1;
int32 nanos = 2;
} |
I would like to do the following.
Without the need to do something like the following on each Date object.
Can I register a encode/decode function to the Timestamp message? |
I now this was closed but wanted to know if you found a solution? I'm trying to do the same thing of using a Timestamp message and can't find a way to make it work. Thanks. |
I'm also wondering about this; Looking at Google's own implementation the JSON representation of the From https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto
|
Can this be reopened? Can't make it work :-| |
Hey.
|
I can not use const timestamp = google.protobuf.Timestamp.fromObject({
seconds: timeMS / 1000,
nanos: (timeMS % 1000) * 1e6
}) |
Why was this closed? There was no explanation. Is this a won't fix? This still doesn't work. |
@marshauf can you reopen this? |
@jontroncoso
|
I also had some issues using the The following code did the trick for me: import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
const timestamp = new Timestamp();
timestamp.fromDate(new Date()); |
I solved this issue using the below code in Javascript:
|
I also had an issue with import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
const timeMS = Date.now();
const timestamp = new Timestamp();
timestamp.setSeconds(Math.floor(timeMS / 1000)); // (timeMS / 1000) gives me a float number but setSeconds expects an integer
timestamp.setNanos((timeMS % 1000) * 1e6); or using import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
const timeMS = Date.now();
const timestamp = Timestamp.fromDate(new Date(timeMS)); |
@mkfsn I'm trying to do the opposite which is getting seconds and Nanos and converting them to valid JS dates or epoch time any Ideas ? |
@younessdev9 I see there are getter functions for seconds and Nanos, do you mean something like this? import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
function toDate(timestamp: Timestamp): Date {
return new Date(timestamp.getSeconds()*1000 + timestamp.getNanos()/1e6);
} |
@claudiohs-inditex accessing new Date(
timestamp.seconds.toNumber() * 1000 +
timestamp.nanos / 1e6
) |
Hello,
I would like to transfer a Javascript Date object. It seem google.protobuf.Timestamp is the 'standard' way of formatting it. Is it possible to register a decode/encode function on the Timestamp message, so that I can convert JS Date to Timestamp and back?
The text was updated successfully, but these errors were encountered: