feat: add {DATE} and {TIME} tokens to Auto Announce (#3382)#3383
Conversation
Auto Announce messages can now include {DATE} and {TIME} tokens, which
expand to the current date/time at send time, formatted per the global
dateFormat/timeFormat preferences (mirroring the acknowledgement path).
Adds the two insert buttons to the editor and documents the tokens.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: {DATE} and {TIME} Tokens for Auto Announce🎯 SummaryThis PR successfully implements ✅ Strengths1. Consistent Architecture
2. Good Test Coverage
3. UI/UX Implementation
4. Proper Scoping
🔍 Code Quality Issues1. Type Safety Concern // Line 10840 - meshtasticManager.ts
let result: string = typeof message === 'string' ? message : String(message);This defensive coercion suggests the type system isn't catching potential non-string inputs. Consider strengthening the type signature of 2. Inconsistent Error Handling try {
if (result.includes('{DATE}')) {
result = result.replace(/{DATE}/g, encode(formatDate(now, dateFormat as 'MM/DD/YYYY' | 'DD/MM/YYYY')));
}
if (result.includes('{TIME}')) {
result = result.replace(/{TIME}/g, encode(formatTime(now, timeFormat as '12' | '24')));
}
} catch (error) {
logger.warn('Failed to format date/time tokens:', error);
// Could leave tokens unreplaced or use defaults
}3. Minor Performance Optimization if (result.includes('{DATE}') || result.includes('{TIME}')) {
const now = new Date();
const dateFormat = await databaseService.settings.getSetting('dateFormat') || 'MM/DD/YYYY';
const timeFormat = await databaseService.settings.getSetting('timeFormat') || '24';
// ... rest of implementation
}🧪 Test Issues1. Skipped Frontend Tests
While there are tests for the new token buttons (lines 246-262), they can't run. This reduces confidence in the UI changes. 2. Test Coverage Gap 🔒 Security AssessmentNo security concerns identified. The implementation:
🚀 Performance AssessmentMinimal performance impact:
📝 DocumentationWell documented:
🎯 Recommendations
📊 Overall AssessmentApproval Recommended ✅ This is a solid, well-implemented feature that follows established patterns. The functionality works correctly and the test coverage for the core logic is excellent. The identified issues are minor improvements rather than blocking problems. The implementation correctly addresses issue #3382 by providing current date/time tokens that respect user formatting preferences, exactly as requested. |
Summary
Adds
{DATE}and{TIME}template tokens to the Auto Announce message editor, as requested in #3382. They expand to the current date/time at the moment the announcement is sent, so periodic announcements can carry a timestamp (e.g. "online as of {DATE} {TIME}"). Formatting honors the global Date Format / Time Format preferences, consistent with how the acknowledgement and welcome paths already render timestamps.Changes
src/server/meshtasticManager.ts):replaceAnnouncementTokens()now resolves{DATE}and{TIME}using the sharedformatDate/formatTimehelpers and the globaldateFormat/timeFormatsettings. The live preview endpoint (previewAnnouncementMessage) picks them up automatically.src/components/AutoAnnounceSection.tsx): added+ {DATE}and+ {TIME}insert buttons alongside the existing token buttons.docs/features/automation.md): documented the two new tokens in the Auto-Announce token reference.Issues Resolved
Fixes #3382
Documentation Updates
docs/features/automation.md— added{DATE}and{TIME}to the Auto-Announce token list.Testing
meshtasticManager.announce-datetime.test.tsdrives the realpreviewAnnouncementMessage: covers DD/MM date format, 12-hour time, combined tokens, default-format fallback, and no-token passthrough (timezone-safe).{DATE}/{TIME}, confirm the live preview renders the current date/time matching your Date/Time Format preferences.Scope note
Scoped to the Meshtastic Auto Announce (the editor referenced in the issue). MeshCore has a separate, intentionally-narrow announce token set; extending it there can be a follow-up if parity is desired.
🤖 Generated with Claude Code