Files
Cyrene_v2/internal/runtime/loop/time.go
T
AskaEth 91e8d7a029 docs(runtime): internal/runtime/loop 44 个文件注释改中文(逐行 1:1,代码零字节改动)
主人 2026-10-03 拍板「注释一律中文」;本模块按长期分批协议(一个模块一次派工)执行。
注释行数 1329 → 1329 逐行 1:1(含中文 33 → 1304);行尾注释 5 条一并译。
校验:机械校验(非注释改动行)= 空;独立 Go AST 程序(剥注释复渲)证明 44/44 文件代码全等;
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
gofmt:capacity_loop_test.go / flow.go 改动前即未格式化,按铁律保留原样未动。
2026-10-03 22:28:21 +08:00

43 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package loop
import (
"fmt"
"log/slog"
"time"
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// weekdaysCN 把 time.Weekday(0=周日)映射为中文星期标签。
var weekdaysCN = [...]string{"周日", "周一", "周二", "周三", "周四", "周五", "周六"}
// loadTimezone 把配置的 IANA 时区解析为 *time.Location,供每轮
// 时间注入使用。空名(或加载失败的名字)返回 nil,
// 从而完全关闭注入(向后兼容,优雅降级)。
func loadTimezone(name string, log *slog.Logger) (*time.Location, string) {
if name == "" {
return nil, ""
}
loc, err := time.LoadLocation(name)
if err != nil {
log.Warn("timezone load failed; time injection disabled", "tz", name, "error", err)
return nil, ""
}
return loc, name
}
// currentTimeBlock 渲染一条每轮「当前时间」系统消息,使模型
// 每轮都知道墙上时钟时间(而非首轮快照)。它仅在配置了
// 时区时由 assembleContext 调用。它只提供原始时钟 ——
// 是否「夜深该睡了」是人格提示词的职责,不是这里的
// 硬编码规则。
func (l *Loop) currentTimeBlock() model.Message {
now := time.Now().In(l.timeLocation)
text := fmt.Sprintf("当前时间:%s %s,时区 %s",
now.Format("2006-01-02 15:04"),
weekdaysCN[now.Weekday()],
l.timeZoneName,
)
return model.TextMessage(model.RoleSystem, text)
}