diff --git a/double_pinyin.schema.yaml b/double_pinyin.schema.yaml index 1620890..ec3be05 100644 --- a/double_pinyin.schema.yaml +++ b/double_pinyin.schema.yaml @@ -101,6 +101,8 @@ date_translator: week: week # 星期: 星期二 datetime: datetime # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: timestamp # 时间戳: 1669716794 + datezh: datezh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: dateen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字 diff --git a/double_pinyin_abc.schema.yaml b/double_pinyin_abc.schema.yaml index c09a44d..ffaccb9 100644 --- a/double_pinyin_abc.schema.yaml +++ b/double_pinyin_abc.schema.yaml @@ -101,6 +101,8 @@ date_translator: week: week # 星期: 星期二 datetime: datetime # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: timestamp # 时间戳: 1669716794 + datezh: datezh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: dateen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字 diff --git a/double_pinyin_flypy.schema.yaml b/double_pinyin_flypy.schema.yaml index 63c509e..14e4004 100644 --- a/double_pinyin_flypy.schema.yaml +++ b/double_pinyin_flypy.schema.yaml @@ -101,6 +101,8 @@ date_translator: week: week # 星期: 星期二 datetime: datetime # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: timestamp # 时间戳: 1669716794 + datezh: datezh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: dateen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字 diff --git a/double_pinyin_jiajia.schema.yaml b/double_pinyin_jiajia.schema.yaml index 1af7928..3726126 100644 --- a/double_pinyin_jiajia.schema.yaml +++ b/double_pinyin_jiajia.schema.yaml @@ -101,6 +101,8 @@ date_translator: week: week # 星期: 星期二 datetime: datetime # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: timestamp # 时间戳: 1669716794 + datezh: datezh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: dateen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字 diff --git a/double_pinyin_mspy.schema.yaml b/double_pinyin_mspy.schema.yaml index d3ec617..5958c37 100644 --- a/double_pinyin_mspy.schema.yaml +++ b/double_pinyin_mspy.schema.yaml @@ -101,6 +101,8 @@ date_translator: week: week # 星期: 星期二 datetime: datetime # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: timestamp # 时间戳: 1669716794 + datezh: datezh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: dateen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字 diff --git a/double_pinyin_sogou.schema.yaml b/double_pinyin_sogou.schema.yaml index b2c2275..b137189 100644 --- a/double_pinyin_sogou.schema.yaml +++ b/double_pinyin_sogou.schema.yaml @@ -101,6 +101,8 @@ date_translator: week: week # 星期: 星期二 datetime: datetime # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: timestamp # 时间戳: 1669716794 + datezh: datezh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: dateen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字 diff --git a/double_pinyin_ziguang.schema.yaml b/double_pinyin_ziguang.schema.yaml index d726cc9..b6c4db9 100644 --- a/double_pinyin_ziguang.schema.yaml +++ b/double_pinyin_ziguang.schema.yaml @@ -101,6 +101,8 @@ date_translator: week: week # 星期: 星期二 datetime: datetime # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: timestamp # 时间戳: 1669716794 + datezh: datezh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: dateen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字 diff --git a/lua/convert_ar_num_to_zh.lua b/lua/convert_ar_num_to_zh.lua new file mode 100644 index 0000000..a5b19a4 --- /dev/null +++ b/lua/convert_ar_num_to_zh.lua @@ -0,0 +1,120 @@ +--[[ + Lua 阿拉伯数字转中文实现 https://blog.csdn.net/lp12345678910/article/details/121396243 +--]] +-- 数字转中文: + +local numerical_units = { + "", + "十", + "百", + "千", + "万", + "十", + "百", + "千", + "亿", + "十", + "百", + "千", + "兆", + "十", + "百", + "千", +} + +local numerical_names = { + "零", + "一", + "二", + "三", + "四", + "五", + "六", + "七", + "八", + "九", +} + +local function convert_arab_to_chinese(number) + local n_number = tonumber(number) + assert(n_number, "传入参数非正确number类型!") + + -- 0 ~ 9 + if n_number < 10 then + return numerical_names[n_number + 1] + end + -- 一十九 => 十九 + if n_number < 20 then + local digit = string.sub(n_number, 2, 2) + if digit == "0" then + return "十" + else + return "十" .. numerical_names[digit + 1] + end + end + + --[[ + 1. 最大输入9位 + 超过9位,string的len加2位(因为有.0的两位) + 零 ~ 九亿九千九百九十九万九千九百九十九 + 0 ~ 999999999 + 2. 最大输入14位(超过14位会四舍五入) + 零 ~ 九十九兆九千九百九十九亿九千九百九十九万九千九百九十九万 + 0 ~ 99999999999999 + --]] + local len_max = 9 + local len_number = string.len(number) + assert( + len_number > 0 and len_number <= len_max, + "传入参数位数" .. len_number .. "必须在(0, " .. len_max .. "]之间!" + ) + + -- 01,数字转成表结构存储 + local numerical_tbl = {} + for i = 1, len_number do + numerical_tbl[i] = tonumber(string.sub(n_number, i, i)) + end + + local pre_zero = false + local result = "" + for index, digit in ipairs(numerical_tbl) do + local curr_unit = numerical_units[len_number - index + 1] + local curr_name = numerical_names[digit + 1] + if digit == 0 then + if not pre_zero then + result = result .. curr_name + end + pre_zero = true + else + result = result .. curr_name .. curr_unit + pre_zero = false + end + end + result = string.gsub(result, "零+$", "") + return result +end + +-- 数字转数位 +-- 例如 2026 -> alt_zero ? 二〇二六 : 二零二六 +local function convert_digits(number, alt_zero) + local num_str = tostring(number) + local result = {} + + for i = 1, #num_str do + local ch = num_str:sub(i, i) + local digit = tonumber(ch) + + if digit == 0 then + table.insert(result, alt_zero and "〇" or "零") + else + table.insert(result, numerical_names[digit + 1]) + end + end + + return table.concat(result) +end + +return { + convert = convert_arab_to_chinese, + digits = convert_digits +} diff --git a/lua/date_translator.lua b/lua/date_translator.lua index 2c55f36..29d6075 100644 --- a/lua/date_translator.lua +++ b/lua/date_translator.lua @@ -1,5 +1,8 @@ -- 日期时间,可在方案中配置触发关键字。 +local convert_num = require("convert_ar_num_to_zh").convert +local convert_digits = require("convert_ar_num_to_zh").digits + -- 提高权重的原因:因为在方案中设置了大于 1 的 initial_quality,导致 rq sj xq dt ts 产出的候选项在所有词语的最后。 local function yield_cand(seg, text) local cand = Candidate('', seg.start, seg._end, text, '') @@ -9,6 +12,11 @@ end local M = {} +-- 月份名称表 +local month_names_short = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } +local month_names_long = { "January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December" } + function M.init(env) local config = env.engine.schema.config env.name_space = env.name_space:gsub('^*', '') @@ -17,6 +25,8 @@ function M.init(env) M.week = config:get_string(env.name_space .. '/week') or 'xq' M.datetime = config:get_string(env.name_space .. '/datetime') or 'dt' M.timestamp = config:get_string(env.name_space .. '/timestamp') or 'ts' + M.date_zh = config:get_string(env.name_space .. '/datezh') or 'rqzh' + M.date_en = config:get_string(env.name_space .. '/dateen') or 'rqen' end function M.func(input, seg, env) @@ -27,34 +37,87 @@ function M.func(input, seg, env) yield_cand(seg, os.date('%Y/%m/%d', current_time)) yield_cand(seg, os.date('%Y.%m.%d', current_time)) yield_cand(seg, os.date('%Y%m%d', current_time)) - yield_cand(seg, os.date('%Y年%m月%d日', current_time):gsub('年0', '年'):gsub('月0','月')) + yield_cand(seg, os.date('%Y年%m月%d日', current_time):gsub('年0', '年'):gsub('月0', '月')) - -- 时间 + -- 时间 elseif (input == M.time) then local current_time = os.time() + + local hour = tonumber(os.date("%H", current_time)) + local period_name + + -- 时间段划分(可根据生活习惯自定义) + if hour >= 5 and hour < 11 then + period_name = "早上" + elseif hour >= 11 and hour < 13 then + period_name = "中午" + elseif hour >= 13 and hour < 18 then + period_name = "下午" + elseif hour >= 18 and hour < 24 then + period_name = "晚上" + else + period_name = "凌晨" + end + 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("%H:%M:%S", current_time)) + -- yield_cand(seg, os.date("%H:%M:%S %p", current_time)) - -- 星期 + -- 星期 elseif (input == M.week) then local current_time = os.time() - local week_tab = {'日', '一', '二', '三', '四', '五', '六'} + local week_tab = { '日', '一', '二', '三', '四', '五', '六' } local text = week_tab[tonumber(os.date('%w', current_time) + 1)] yield_cand(seg, '星期' .. text) yield_cand(seg, '礼拜' .. text) yield_cand(seg, '周' .. text) - -- ISO 8601/RFC 3339 的时间格式 (固定东八区)(示例 2022-01-07T20:42:51+08:00) + -- ISO 8601/RFC 3339 的时间格式 (固定东八区)(示例 2022-01-07T20:42:51+08:00) 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)) 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)) - -- 时间戳(十位数,到秒,示例 1650861664) + -- 时间戳(十位数,到秒,示例 1650861664) elseif (input == M.timestamp) then local current_time = os.time() yield_cand(seg, string.format('%d', current_time)) + + -- 中文日期 + elseif (input == M.date_zh) then + local current_time = os.time() + local year_0 = convert_digits(tonumber(os.date('%Y', current_time)), true) + local year_zero = convert_digits(tonumber(os.date('%Y', current_time)), false) + local month = convert_num(tonumber(os.date('%m', current_time))) + local day = convert_num(tonumber(os.date('%d', current_time))) + + yield_cand(seg, string.format('%s年%s月%s日', year_0, month, day)) + yield_cand(seg, string.format('%s年%s月%s日', year_zero, month, day)) + yield_cand(seg, os.date('%Y年%m月%d日', current_time):gsub('年0', '年'):gsub('月0', '月')) + + -- 英文日期 + elseif (input == M.date_en) then + local current_time = os.time() + local day = tonumber(os.date("%d", current_time)) + local month = tonumber(os.date("%m", current_time)) + local year = os.date("%Y", current_time) + -- 计算日期序数后缀 + -- local suffix = "th" + -- if day % 10 == 1 and day ~= 11 then + -- suffix = "st" + -- elseif day % 10 == 2 and day ~= 12 then + -- suffix = "nd" + -- elseif day % 10 == 3 and day ~= 13 then + -- suffix = "rd" + -- end + + 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 -- -- 显示内存 diff --git a/lua/lunar.lua b/lua/lunar.lua index 4a849fa..533d2b2 100755 --- a/lua/lunar.lua +++ b/lua/lunar.lua @@ -1,102 +1,10 @@ --[[ - Lua 阿拉伯数字转中文实现 https://blog.csdn.net/lp12345678910/article/details/121396243 农历功能复制自 https://github.com/boomker/rime-fast-xhup --]] -- -- 农历,可在方案中配置触发关键字。 --- 数字转中文: - -local numerical_units = { - "", - "十", - "百", - "千", - "万", - "十", - "百", - "千", - "亿", - "十", - "百", - "千", - "兆", - "十", - "百", - "千", -} - -local numerical_names = { - "零", - "一", - "二", - "三", - "四", - "五", - "六", - "七", - "八", - "九", -} - -local function convert_arab_to_chinese(number) - local n_number = tonumber(number) - assert(n_number, "传入参数非正确number类型!") - - -- 0 ~ 9 - if n_number < 10 then - return numerical_names[n_number + 1] - end - -- 一十九 => 十九 - if n_number < 20 then - local digit = string.sub(n_number, 2, 2) - if digit == "0" then - return "十" - else - return "十" .. numerical_names[digit + 1] - end - end - - --[[ - 1. 最大输入9位 - 超过9位,string的len加2位(因为有.0的两位) - 零 ~ 九亿九千九百九十九万九千九百九十九 - 0 ~ 999999999 - 2. 最大输入14位(超过14位会四舍五入) - 零 ~ 九十九兆九千九百九十九亿九千九百九十九万九千九百九十九万 - 0 ~ 99999999999999 - --]] - local len_max = 9 - local len_number = string.len(number) - assert( - len_number > 0 and len_number <= len_max, - "传入参数位数" .. len_number .. "必须在(0, " .. len_max .. "]之间!" - ) - - -- 01,数字转成表结构存储 - local numerical_tbl = {} - for i = 1, len_number do - numerical_tbl[i] = tonumber(string.sub(n_number, i, i)) - end - - local pre_zero = false - local result = "" - for index, digit in ipairs(numerical_tbl) do - local curr_unit = numerical_units[len_number - index + 1] - local curr_name = numerical_names[digit + 1] - if digit == 0 then - if not pre_zero then - result = result .. curr_name - end - pre_zero = true - else - result = result .. curr_name .. curr_unit - pre_zero = false - end - end - result = string.gsub(result, "零+$", "") - return result -end +local convert_arab_to_chinese = require("convert_ar_num_to_zh").convert -- 农历: diff --git a/others/CHANGELOG.md b/others/CHANGELOG.md index 8455972..ca4ad36 100644 --- a/others/CHANGELOG.md +++ b/others/CHANGELOG.md @@ -2,24 +2,29 @@ 除日常更新词库外的一些主要更新 🆕、破坏性变更 ⚠️。 +## 2026-03-08 + +- feat: 加入一些时间和日期的自定义展示 [#1485](https://github.com/iDvel/rime-ice/pull/1485) + - 中英日期触发关键字,全拼默认为 `rqzh` 和 `rqen`,双拼默认为 `datezh` 和 `dateen` + --- *2025.12.08 Release* -### 2025-12-08 +## 2025-12-08 - 修正了 lua 注释中的引入错误 [#1405](https://github.com/iDvel/rime-ice/issues/1405) -### 2025-10-31 +## 2025-10-31 - `uuid.lua` 生成符合 RFC 4122 标准的 UUID v4 [#1383](https://github.com/iDvel/rime-ice/pull/1383) -### 2025-10-23 +## 2025-10-23 - 以词定字长句输入支持 ([#1252](https://github.com/iDvel/rime-ice/issues/1252)) - 计算器百分号支持([#1298](https://github.com/iDvel/rime-ice/pull/1298)) -### 2025-06-09 +## 2025-06-09 - 添加拼音加加双拼方案 [#1228](https://github.com/iDvel/rime-ice/pull/1228) diff --git a/rime_ice.schema.yaml b/rime_ice.schema.yaml index ac8a92a..bbfcb2d 100644 --- a/rime_ice.schema.yaml +++ b/rime_ice.schema.yaml @@ -6,7 +6,7 @@ schema: schema_id: rime_ice name: 雾凇拼音 - version: "2026-01-29" + version: "2026-03-08" author: - Dvel description: | @@ -92,6 +92,8 @@ date_translator: week: xq # 星期: 星期二 datetime: dt # ISO 8601: 2022-11-29T18:13:11+08:00 timestamp: ts # 时间戳: 1669716794 + datezh: rqzh # 中文日期: 二〇二六年二月二十五日 | 二零二六年二月二十五日 + dateen: rqen # 英文日期: 英式 8 March 2026 | 美式 March 8, 2026 # Lua 配置:农历的触发关键字