Skip to content
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

reminder的时间与系统时间不一致 #239

Closed
SEAFHMC opened this issue Aug 24, 2021 · 10 comments
Closed

reminder的时间与系统时间不一致 #239

SEAFHMC opened this issue Aug 24, 2021 · 10 comments
Labels
question Further information is requested

Comments

@SEAFHMC
Copy link

SEAFHMC commented Aug 24, 2021

  1. Bug 描述
    服务器地区为美国洛杉矶,已更改系统时间为东8区。但reminder似乎仍旧使用的是美国时间。
  2. 截图、日志、配置
    IMG_20210824_090713
    IMG_20210824_090131
  3. 运行环境
    • 系统:CentOS 8
    • node.js 版本:14.17.5
    • go-cqhttp 版本:1.0.0-beta6
    • cq-picsearcher-bot 版本:2.29.15
@Tsuk1ko
Copy link
Owner

Tsuk1ko commented Aug 24, 2021

更改时区后有试过重启 bot 吗

我也是用的洛杉矶服务器调了时区,是正常的

@SEAFHMC
Copy link
Author

SEAFHMC commented Aug 24, 2021

更改时区后有试过重启 bot 吗

我也是用的洛杉矶服务器调了时区,是正常的

刚刚重启了一遍bot,还是不行,我试试把系统重启一遍。

@SEAFHMC
Copy link
Author

SEAFHMC commented Aug 24, 2021

更改时区后有试过重启 bot 吗
我也是用的洛杉矶服务器调了时区,是正常的

刚刚重启了一遍bot,还是不行,我试试把系统重启一遍。

emmm,重启系统也没效果。

@Tsuk1ko
Copy link
Owner

Tsuk1ko commented Aug 24, 2021

更改时区后有试过重启 bot 吗

我也是用的洛杉矶服务器调了时区,是正常的

噢噢我之前记错了,我换了服务器之后就没用过这个功能了

看了下 cron-parser 确实有个时区选项,我加个自动检测时区

@Tsuk1ko Tsuk1ko added the enhancement New feature or request label Aug 24, 2021
@SEAFHMC
Copy link
Author

SEAFHMC commented Aug 24, 2021

更改时区后有试过重启 bot 吗
我也是用的洛杉矶服务器调了时区,是正常的

噢噢我之前记错了,我换了服务器之后就没用过这个功能了

看了下 cron-parser 确实有个时区选项,我加个自动检测时区

嗯!谢啦,期待后续版本。

@Tsuk1ko
Copy link
Owner

Tsuk1ko commented Aug 24, 2021

不对,怪了,我又测试了一下,确实默认就是符合时区的

image

而且 cron-parse 的默认表现也没问题

image

你试一下在项目目录下执行 node 然后跟上面一样执行这个代码看看会输出什么

const parser = require('cron-parser')
parser.parseExpression('0 0 * * *').next().toString()

顺便看一下 Date() 的输出

image

@Tsuk1ko Tsuk1ko added question Further information is requested and removed enhancement New feature or request labels Aug 24, 2021
@SEAFHMC
Copy link
Author

SEAFHMC commented Aug 25, 2021

不对,怪了,我又测试了一下,确实默认就是符合时区的

image

而且 cron-parse 的默认表现也没问题

image

你试一下在项目目录下执行 node 然后跟上面一样执行这个代码看看会输出什么

const parser = require('cron-parser')
parser.parseExpression('0 0 * * *').next().toString()

顺便看一下 Date() 的输出

image

刚开始说没有安装cron-parse,安装并运行代码之后显示确实差了12小时
IMG_20210825_130707

@Tsuk1ko
Copy link
Owner

Tsuk1ko commented Aug 25, 2021

在 node 里面分别执行这两句

process.env.TZ
Intl.DateTimeFormat().resolvedOptions().timeZone

看看输出结果


以及执行

process.env.TZ = 'Asia/Shanghai'

之后,重复之前 cron-parser 那个操作看看输出

@SEAFHMC
Copy link
Author

SEAFHMC commented Aug 25, 2021

IMG_20210825_215105
OH~ 变成中国时间了

Tsuk1ko added a commit that referenced this issue Aug 25, 2021
@Tsuk1ko
Copy link
Owner

Tsuk1ko commented Aug 25, 2021

看来你这个问题是 node 读取到的系统时区不正确引起的,node 默认认为你的时区是纽约,我也不清楚原因,只能通过环境变量指定时区了

更新至 v2.30.0 后,在项目根目录创建一个 .env 文件,往里面写入

TZ=Asia/Shanghai

就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants