Skip to content

Commit c697f83

Browse files
authored
fix: msg date (#152)
1 parent e89a631 commit c697f83

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

wechaty-puppet-service/helper.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package puppetservice
2+
3+
import (
4+
"google.golang.org/protobuf/types/known/timestamppb"
5+
"time"
6+
)
7+
8+
func grpcTimestampToGoTime(t *timestamppb.Timestamp) time.Time {
9+
// 不同的 puppet 返回的时间格式不一致, 需要做转换兼容
10+
// padlocal 返回的是秒,puppet-service 当作是毫秒单位转为秒(除以1000),所以这里 t.Seconds 就只剩下七位,另外3为被分配到 t.Nanos 去了
11+
// https://github.com/wechaty/puppet-service/blob/4de1024ee9b615af6c44674f684a84dd8c11ae9e/src/pure-functions/timestamp.ts#L7-L17
12+
13+
// 这里我们判断 t.Seconds 是否为7位来特殊处理
14+
//TODO(dchaofei): 未来时间戳每增加一位这里就要判断加一位,那就是200多年之后的事情了,到时还有人在用 wechaty 吗?(2023-09-09)
15+
if t.Seconds/10000000 < 1 {
16+
second := t.Seconds*1000 + int64(t.Nanos)/1000000
17+
return time.Unix(second, 0)
18+
}
19+
20+
return t.AsTime().Local()
21+
}

wechaty-puppet-service/puppet_service.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"google.golang.org/grpc"
1515
"google.golang.org/grpc/connectivity"
1616
"google.golang.org/grpc/credentials/insecure"
17-
"google.golang.org/protobuf/types/known/timestamppb"
1817
"io"
1918
"time"
2019
)
@@ -645,11 +644,6 @@ func (p *PuppetService) MessageRawPayload(id string) (*schemas.MessagePayload, e
645644
return payload, nil
646645
}
647646

648-
func grpcTimestampToGoTime(t *timestamppb.Timestamp) time.Time {
649-
second := t.Seconds*1000 + int64(t.Nanos)/1000000
650-
return time.Unix(second, 0)
651-
}
652-
653647
// MessageSendText ...
654648
func (p *PuppetService) MessageSendText(conversationID string, text string, mentionIDList ...string) (string, error) {
655649
log.Tracef("PuppetService messageSendText(%s, %s)\n", conversationID, text)

0 commit comments

Comments
 (0)