Files
suanming/tests/timezone-fix-test.cjs
patdelphi baaa50cd3d feat: 重大算法优化与系统升级
� 核心成就:
- 八字节气计算达到专业级精度(立春等关键节气精确到分钟)
- 万年历算法完全重构,集成权威数据源
- 年柱判断100%准确(立春前后切换完全正确)
- 日柱计算基于权威万年历数据,精度显著提升

� 技术改进:
- 新增权威节气时间查表法(SolarTermsCalculator优化)
- 创建专业万年历工具类(WanNianLi.cjs)
- 八字分析器算法全面升级(BaziAnalyzer.cjs)
- 易经随机性算法优化,提升卦象准确性

� 验证结果:
- 权威案例验证:1976-03-17 23:00 → 丙辰 辛卯 己巳 甲子 
- 经典案例验证:1990-01-15 14:30 → 己巳 丁丑 庚辰 癸未 
- 边界案例验证:2024-02-03 23:30 → 癸卯 乙丑 丙午 戊子 

�️ 架构升级:
- 模块化设计,节气计算与万年历分离
- 查表法+算法备用的双重保障机制
- 系统兼容性测试通过,八字与紫微斗数协同工作

� 系统状态:
- 八字系统:专业级精度,生产就绪
- 紫微斗数:基础功能正常,持续优化中
- 易经占卜:随机性算法优化完成
- 整体稳定性:显著提升,多案例验证通过
2025-08-20 12:49:58 +08:00

117 lines
3.4 KiB
JavaScript

// 易经占卜时区修复测试
// 测试时间算法是否正确使用用户当地时间
const YijingAnalyzer = require('../server/services/yijingAnalyzer.cjs');
// 创建分析器实例
const analyzer = new YijingAnalyzer();
// 测试数据
const testCases = [
{
name: '使用当地时间测试',
inputData: {
question: '今日运势如何?',
user_id: 'test_user_1',
divination_method: 'time',
local_time: '2024-01-15T14:30:00+08:00', // 北京时间下午2:30
user_timezone: 'Asia/Shanghai'
}
},
{
name: '使用时区信息测试',
inputData: {
question: '事业发展如何?',
user_id: 'test_user_2',
divination_method: 'time',
user_timezone: 'America/New_York'
}
},
{
name: '兜底服务器时间测试',
inputData: {
question: '财运如何?',
user_id: 'test_user_3',
divination_method: 'time'
// 不提供时区和当地时间,应该使用服务器时间
}
}
];
// 运行测试
function runTests() {
console.log('=== 易经占卜时区修复测试 ===\n');
testCases.forEach((testCase, index) => {
console.log(`测试 ${index + 1}: ${testCase.name}`);
console.log('输入数据:', JSON.stringify(testCase.inputData, null, 2));
try {
const result = analyzer.performYijingAnalysis(testCase.inputData);
console.log('✅ 分析成功');
console.log('占卜时间:', result.basic_info.divination_data.divination_time);
console.log('主卦:', result.basic_info.hexagram_info.main_hexagram);
console.log('变卦:', result.basic_info.hexagram_info.changing_hexagram);
console.log('动爻:', result.basic_info.hexagram_info.changing_lines);
} catch (error) {
console.log('❌ 分析失败:', error.message);
}
console.log('\n' + '='.repeat(50) + '\n');
});
}
// 时间对比测试
function timeComparisonTest() {
console.log('=== 时间对比测试 ===\n');
const baseQuestion = '测试时间差异';
const userId = 'time_test_user';
// 测试不同时间的起卦结果
const times = [
'2024-01-15T08:00:00+08:00', // 北京时间早上8点
'2024-01-15T14:00:00+08:00', // 北京时间下午2点
'2024-01-15T20:00:00+08:00', // 北京时间晚上8点
];
times.forEach((time, index) => {
console.log(`时间 ${index + 1}: ${time}`);
const inputData = {
question: baseQuestion,
user_id: userId,
divination_method: 'time',
local_time: time,
user_timezone: 'Asia/Shanghai'
};
try {
const result = analyzer.performYijingAnalysis(inputData);
console.log('主卦:', result.basic_info.hexagram_info.main_hexagram);
console.log('动爻位置:', result.basic_info.hexagram_info.changing_lines[0]);
console.log('时辰分析:', result.dynamic_guidance.time_analysis.time_of_day.name);
} catch (error) {
console.log('❌ 分析失败:', error.message);
}
console.log('\n' + '-'.repeat(30) + '\n');
});
}
// 执行测试
if (require.main === module) {
runTests();
timeComparisonTest();
console.log('测试完成!');
console.log('\n注意事项:');
console.log('1. 检查不同时间的起卦结果是否不同');
console.log('2. 验证时辰分析是否正确对应输入时间');
console.log('3. 确认时区处理是否正确');
}
module.exports = { runTests, timeComparisonTest };