wechaty-puppet-service
Version:
Puppet Service for Wechaty
23 lines • 991 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.timestampFromMilliseconds = exports.millisecondsFromTimestamp = void 0;
const wechaty_grpc_1 = require("wechaty-grpc");
/**
* https://github.com/protocolbuffers/protobuf/blob/b6993a90605cde15ba004e0287bcb078b0f3959d/src/google/protobuf/timestamp.proto#L86-L91
*/
function timestampFromMilliseconds(milliseconds) {
const seconds = Math.floor(milliseconds / 1000);
const nanos = (milliseconds % 1000) * 1000000;
const timestamp = new wechaty_grpc_1.Timestamp();
timestamp.setSeconds(seconds);
timestamp.setNanos(nanos);
return timestamp;
}
exports.timestampFromMilliseconds = timestampFromMilliseconds;
function millisecondsFromTimestamp(timestamp) {
const seconds = timestamp.getSeconds();
const nanos = timestamp.getNanos();
return seconds * 1000 + nanos / 1000000;
}
exports.millisecondsFromTimestamp = millisecondsFromTimestamp;
//# sourceMappingURL=timestamp.js.map
;