mirror of
https://github.com/iDvel/rime-ice.git
synced 2026-05-14 00:30:37 +08:00
fix: lunar.db 年份、生肖、繁简错误
- 星期默认置于注释。 - 犬年 => 狗年;按国家标准,干支随生肖更替 - 修正 2051 年星期偏移和数据缺失
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
-- 将今天或者指定的公历日期转换为农历和二十四节气,支持1900-2100之间的日期。输入格式为YYYYMMDD,例如20240101。
|
||||
|
||||
-- 默认格式示例:丙午马年正月初一
|
||||
-- 标准:GB/T 33661-2017 《农历的编算和颁行》附录 D;GB/T 15835-2011 《出版物上数字用法》4.2.1;参考:人民日报,新华社
|
||||
-- 数据:https://www.hko.gov.hk/tc/index.html
|
||||
-- 标准:GB/T 33661-2017 《农历的编算和颁行》;GB/T 15835-2011 《出版物上数字用法》4.2.1;参考:人民日报,新华社
|
||||
-- 数据:https://www.hko.gov.hk/tc/gts/time/conversion1_text.htm (注:修正源数据 2051 年星期偏移,修正农历年份偏移)
|
||||
-- ================================
|
||||
-- 安装:
|
||||
-- lunar.lua --> lua/lunar.lua
|
||||
@@ -13,7 +12,7 @@
|
||||
-- - lua_translator@*lunar
|
||||
-- recognizer/gregorian_to_lunar: "^N[0-9]{1,8}" # 输入N19700101输出对应的农历信息
|
||||
-- lunar: lunar # 输入此字符输出今日农历信息
|
||||
-- lunar_template: "{干支年}{生肖}年{俗称农历月}{农历日}" # 可用字段:{干支年} {农历月} {农历日} {星期} {生肖} {俗称农历月} {简记农历日}
|
||||
-- lunar_template: "{干支年}{生肖}年{俗称农历月}{农历日}" # 可用字段:{干支年} {农历月} {农历日} {生肖} {俗称农历月} {简记农历日}
|
||||
-- ```
|
||||
-- =================================
|
||||
local lunar_translator = {}
|
||||
@@ -22,30 +21,32 @@ local function new_lunar_cand( lunar_info, env, seg )
|
||||
local values = {}
|
||||
local i = 1
|
||||
for part in string.gmatch( lunar_info, '[^-]+' ) do
|
||||
values[LUNAR_KEYS[i]] = part; i = i + 1
|
||||
values[LUNAR_KEYS[i]] = part;
|
||||
i = i + 1
|
||||
end
|
||||
values['俗称农历月'] = values['农历月']:gsub( '十二月', '腊月' )
|
||||
values['简记农历日'] = values['农历日']:gsub( '^二十([一二三四五六七八九])$', '廿%1' )
|
||||
local args = {}
|
||||
for _, field in ipairs( env.lunar_template_fields ) do
|
||||
args[#args + 1] = values[field] or ''
|
||||
end
|
||||
local cand = Candidate( 'lunar', seg.start, seg._end, string.format( env.lunar_format, table.unpack( args ) ), '' )
|
||||
for _, field in ipairs( env.lunar_template_fields ) do args[#args + 1] = values[field] or '' end
|
||||
local cand = Candidate(
|
||||
'lunar', seg.start, seg._end, string.format( env.lunar_format, table.unpack( args ) ),
|
||||
values['星期']
|
||||
)
|
||||
cand.quality = 99999
|
||||
if values['节气'] then cand.comment = values['节气'] end
|
||||
if values['节气'] then cand.comment = values['星期'] .. ' ' .. values['节气'] end
|
||||
return cand
|
||||
end
|
||||
|
||||
function lunar_translator.init( env )
|
||||
local ns = env.name_space:gsub( '^*', '' )
|
||||
if ns == '' then ns = 'lunar' end
|
||||
local config = env.engine.schema.config
|
||||
|
||||
env.db = ReverseDb( 'lua/lunar.db' )
|
||||
env.lunar_call_prefix = config:get_string( ns ) or 'lunar'
|
||||
env.seg_tag = 'gregorian_to_lunar'
|
||||
|
||||
local lunar_template = config:get_string( ns .. '_template' ) or '{干支年}{生肖}年{俗称农历月}{农历日}'
|
||||
local lunar_template = config:get_string( ns .. '_template' ) or
|
||||
'{干支年}{生肖}年{俗称农历月}{农历日}'
|
||||
local template_fields = {}
|
||||
env.lunar_format = lunar_template:gsub(
|
||||
'{([^}]+)}', function( field )
|
||||
@@ -58,7 +59,8 @@ end
|
||||
|
||||
function lunar_translator.func( input, seg, env )
|
||||
local date
|
||||
if input == env.lunar_call_prefix then date = os.date( '%Y%m%d' )
|
||||
if input == env.lunar_call_prefix then
|
||||
date = os.date( '%Y%m%d' )
|
||||
elseif seg:has_tag( env.seg_tag ) then
|
||||
date = input:match( '%d+' )
|
||||
if date and #date < 8 then
|
||||
|
||||
Reference in New Issue
Block a user