Skip to content

Commit

Permalink
fix: msg date (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
dchaofei authored Aug 9, 2023
1 parent e89a631 commit c697f83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 21 additions & 0 deletions wechaty-puppet-service/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package puppetservice

import (
"google.golang.org/protobuf/types/known/timestamppb"
"time"
)

func grpcTimestampToGoTime(t *timestamppb.Timestamp) time.Time {
// 不同的 puppet 返回的时间格式不一致, 需要做转换兼容
// padlocal 返回的是秒,puppet-service 当作是毫秒单位转为秒(除以1000),所以这里 t.Seconds 就只剩下七位,另外3为被分配到 t.Nanos 去了
// https://github.com/wechaty/puppet-service/blob/4de1024ee9b615af6c44674f684a84dd8c11ae9e/src/pure-functions/timestamp.ts#L7-L17

// 这里我们判断 t.Seconds 是否为7位来特殊处理
//TODO(dchaofei): 未来时间戳每增加一位这里就要判断加一位,那就是200多年之后的事情了,到时还有人在用 wechaty 吗?(2023-09-09)
if t.Seconds/10000000 < 1 {
second := t.Seconds*1000 + int64(t.Nanos)/1000000
return time.Unix(second, 0)
}

return t.AsTime().Local()
}
6 changes: 0 additions & 6 deletions wechaty-puppet-service/puppet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/types/known/timestamppb"
"io"
"time"
)
Expand Down Expand Up @@ -645,11 +644,6 @@ func (p *PuppetService) MessageRawPayload(id string) (*schemas.MessagePayload, e
return payload, nil
}

func grpcTimestampToGoTime(t *timestamppb.Timestamp) time.Time {
second := t.Seconds*1000 + int64(t.Nanos)/1000000
return time.Unix(second, 0)
}

// MessageSendText ...
func (p *PuppetService) MessageSendText(conversationID string, text string, mentionIDList ...string) (string, error) {
log.Tracef("PuppetService messageSendText(%s, %s)\n", conversationID, text)
Expand Down

0 comments on commit c697f83

Please sign in to comment.