2 Commits

Author SHA1 Message Date
Mi Ramon
4e54d7edb1 fix(lua): 修正 PM / AM 的时间展示 (#1507) 2026-03-23 11:31:57 +08:00
Karlbaey
20b21a0ebe fix(lua): 修复时区问题(#1501)
* fix: 修复时区错误显示的问题
2026-03-21 03:24:58 +08:00

View File

@@ -61,11 +61,11 @@ function M.func(input, seg, env)
yield_cand(seg, os.date('%H:%M', current_time))
yield_cand(seg, os.date('%H:%M:%S', current_time))
yield_cand(seg, period_name .. " " .. os.date("%H:%M", current_time))
yield_cand(seg, os.date("%H:%M %p", current_time))
yield_cand(seg, period_name .. " " .. os.date("%I:%M", current_time))
yield_cand(seg, os.date("%I:%M %p", current_time))
-- 带上时间划分时,很少有带秒数的,暂时注释掉
-- yield_cand(seg, period_name .. " " .. os.date("%H:%M:%S", current_time))
-- yield_cand(seg, os.date("%H:%M:%S %p", current_time))
-- yield_cand(seg, period_name .. " " .. os.date("%I:%M:%S", current_time))
-- yield_cand(seg, os.date("%I:%M:%S %p", current_time))
-- 星期
elseif (input == M.week) then
@@ -76,10 +76,21 @@ function M.func(input, seg, env)
yield_cand(seg, '礼拜' .. text)
yield_cand(seg, '' .. text)
-- ISO 8601/RFC 3339 的时间格式 (固定东八区)(示例 2022-01-07T20:42:51+08:00
-- ISO 8601/RFC 3339 的时间格式
elseif (input == M.datetime) then
local current_time = os.time()
yield_cand(seg, os.date('%Y-%m-%dT%H:%M:%S+08:00', current_time))
-- 获取偏移量,例如 "+0800" 或 "+0000"
local tz = os.date("%z", current_time)
-- 格式化时区
-- 如果是零时区 (+0000/-0000),根据规范输出 "Z"
-- 否则将 "+0800" 转换为 "+08:00"
local iso_tz = (tz == "+0000" or tz == "-0000")
and "Z"
or tz:gsub("(%d%d)$", ":%1")
yield_cand(seg, os.date('%Y-%m-%dT%H:%M:%S', current_time) .. iso_tz)
yield_cand(seg, os.date('%Y-%m-%d %H:%M:%S', current_time))
yield_cand(seg, os.date('%Y%m%d%H%M%S', current_time))
@@ -116,7 +127,7 @@ function M.func(input, seg, env)
-- suffix = "rd"
-- end
yield_cand(seg, string.format("%d %s %s", day, month_names_long[month], year)) -- en_UK
yield_cand(seg, string.format("%d %s %s", day, month_names_long[month], year)) -- en_UK
yield_cand(seg, string.format("%s %d, %s", month_names_long[month], day, year)) -- en_US
end