跳到主要内容

时区管理

设置 RainMaker 节点的时区,以确保定时、自动化和基于时间的功能正常运行。

备注

userInstance —— 来自用户登录的 ESPRMUser 实例。

本模块的功能​

使用 IANA 时区标识符(例如 "America/New_York")通过 node.setTimeZone(timezoneString) 设置节点的本地时间。

适用场景: 用户在设置中选择时区、需要在多个节点之间同步时区,或基于时间的自动化和定时没有按本地时间执行。

或者: 可以通过 Time 服务设置时区 — 服务控制。如果只需要设置时区,而不需要设置其他服务参数,建议使用 setTimeZone()。

信息

在配网过程中,如果设备支持,SDK 可能会将用户的时区应用于新设备。

预期结果: 节点的时区更新,基于时间的行为将使用新的时区。

常见工作流​

在单个节点上设置时区​

await node.setTimeZone("America/Los_Angeles");

在所有节点上设置时区​

const { nodes } = await userInstance.getUserNodes();

for (const node of nodes) {
await node.setTimeZone("America/New_York");
}

从用户资料同步时区​

const userTimezone = "Europe/Berlin";
const { nodes } = await userInstance.getUserNodes();
await Promise.all(nodes.map((n) => n.setTimeZone(userTimezone)));

错误处理​

try {
await node.setTimeZone(timeZoneString);
} catch (error) {
console.error("Failed to set timezone:", error);
}

请使用有效的 IANA 时区标识符;无效值可能会被后端拒绝。

最佳实践​

  1. 在设置基于时间的自动化之前设置时区
  2. 用户更改配置文件中的时区后,更新所有节点的时区
  3. 在配网之前设置用户时区,以便新设备继承该时区

相关资源​

On this page