/** * 纪念日相关的展示格式化工具 * Why:原本散落在 index / person-detail / add-anniversary 里的转换逻辑,统一到这里避免多份维护 */ const { TYPE_NAMES, TYPE_ICONS, IMPORTANCE_TEXTS } = require('./constants') function getTypeName(type, customTypeName) { if (type === 'other' && customTypeName) return customTypeName return TYPE_NAMES[type] || '纪念日' } function getTypeIcon(type) { return TYPE_ICONS[type] || '📅' } function getImportanceText(importance) { return IMPORTANCE_TEXTS[importance] || '一般' } // 距离 X 天的口语化展示 function formatDaysUntil(days) { if (days === 0) return '今天' if (days === 1) return '明天' if (days < 7) return `${days}天后` if (days < 30) return `还有${Math.floor(days / 7)}周` return `还有${Math.floor(days / 30)}个月` } module.exports = { getTypeName, getTypeIcon, getImportanceText, formatDaysUntil }