Skip to content

feat: add {DATE} and {TIME} tokens to Auto Announce (#3382)#3383

Merged
Yeraze merged 1 commit into
mainfrom
feature/3382-announce-date-time-tokens
Jun 8, 2026
Merged

feat: add {DATE} and {TIME} tokens to Auto Announce (#3382)#3383
Yeraze merged 1 commit into
mainfrom
feature/3382-announce-date-time-tokens

Conversation

@Yeraze

@Yeraze Yeraze commented Jun 8, 2026

Copy link
Copy Markdown
Owner

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

  • Backend (src/server/meshtasticManager.ts): replaceAnnouncementTokens() now resolves {DATE} and {TIME} using the shared formatDate/formatTime helpers and the global dateFormat/timeFormat settings. The live preview endpoint (previewAnnouncementMessage) picks them up automatically.
  • Frontend (src/components/AutoAnnounceSection.tsx): added + {DATE} and + {TIME} insert buttons alongside the existing token buttons.
  • Docs (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

  • Unit tests pass (full suite: 6159 passed, 0 failures)
  • TypeScript compiles cleanly
  • New backend test meshtasticManager.announce-datetime.test.ts drives the real previewAnnouncementMessage: covers DD/MM date format, 12-hour time, combined tokens, default-format fallback, and no-token passthrough (timezone-safe).
  • Reviewer: in Settings → Auto Announce, insert {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

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>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Claude finished @Yeraze's task —— View job


PR Review: {DATE} and {TIME} Tokens for Auto Announce

🎯 Summary

This PR successfully implements {DATE} and {TIME} template tokens for the Auto Announce feature. The implementation is solid and follows established patterns in the codebase.

✅ Strengths

1. Consistent Architecture

  • Follows existing token replacement patterns in replaceAnnouncementTokens() (lines 10996-11008)
  • Properly integrates with global date/time format settings
  • Uses established formatDate/formatTime utilities (line 12)

2. Good Test Coverage

  • Comprehensive test suite in meshtasticManager.announce-datetime.test.ts
  • Tests multiple format combinations (DD/MM vs MM/DD, 12h vs 24h)
  • Tests fallback behavior when settings are undefined
  • Tests edge cases (no tokens, combined tokens)
  • Uses timezone-safe test approach with fixed time

3. UI/UX Implementation

  • Clean UI with insert buttons matching existing patterns (lines 665-694 in AutoAnnounceSection.tsx)
  • Live preview automatically picks up new tokens via existing preview endpoint
  • Documentation properly updated in automation.md

4. Proper Scoping

  • Correctly scoped to Meshtastic Auto Announce (as noted in PR scope)
  • Doesn't break MeshCore's intentionally-narrow token set

🔍 Code Quality Issues

1. 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 replaceAnnouncementTokens() instead of runtime type checking.

2. Inconsistent Error Handling
The date/time token replacement has no try/catch around formatDate/formatTime calls, unlike other token replacements that have error handling. Consider adding:

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
The date settings are fetched even when no date/time tokens are present. Consider checking for tokens first:

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 Issues

1. Skipped Frontend Tests
The AutoAnnounceSection.test.tsx has comprehensive tests but they're all skipped due to architectural changes. The skip comment (lines 58-71) mentions three specific issues:

  • SaveBar pattern change breaking save assertions
  • Label/input mismatch for broadcast channels
  • Vitest 4 deadlock with userEvent + fake timers

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
No integration test verifies the end-to-end flow: UI button → message change → preview update with actual date/time.

🔒 Security Assessment

No security concerns identified. The implementation:

  • Doesn't expose sensitive data
  • Uses existing safe formatting utilities
  • Follows established token replacement patterns
  • Doesn't introduce new attack vectors

🚀 Performance Assessment

Minimal performance impact:

  • Date/time evaluation happens once per announcement (not per token)
  • Uses existing efficient formatDate/formatTime utilities
  • Could benefit from conditional evaluation optimization noted above

📝 Documentation

Well documented:

  • Clear documentation added to automation.md (lines 587-588)
  • Follows existing token documentation format
  • Examples show proper usage

🎯 Recommendations

  1. Fix Type Safety: Strengthen parameter typing instead of runtime coercion
  2. Add Error Handling: Protect date/time formatting with try/catch
  3. Performance: Only fetch date settings when tokens are present
  4. Tests: Address the skipped frontend test suite as follow-up work
  5. Integration: Add one integration test for the full flow

📊 Overall Assessment

Approval 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.

@Yeraze Yeraze merged commit d9222b9 into main Jun 8, 2026
19 checks passed
@Yeraze Yeraze deleted the feature/3382-announce-date-time-tokens branch June 8, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add {DATE} and {TIME} template tokens to Auto Announce

1 participant