refactor(date): use getDbDateStr() utility for consistent date formatting

Replace inline `.toISOString().split('T')[0]` pattern with getDbDateStr()
utility across production code, tests, and plugin examples.

Changes:
- Production: 6 files (plugin-bridge, metrics, counters, task-repeat-cfg)
- Tests: 4 spec files (helper functions and direct uses)
- Plugin example: Added formatDateStr() helper matching main app pattern

This ensures consistent local timezone handling for all user-facing date
operations and provides a single source of truth for date string formatting.
This commit is contained in:
Johannes Millan 2026-01-16 12:53:47 +01:00
parent 1b47d463a1
commit 59292abacb
11 changed files with 41 additions and 36 deletions

View file

@ -94,6 +94,16 @@
</div>
<script>
// Format date to YYYY-MM-DD in local timezone
// Note: This matches the getDbDateStr() utility used in the main app
function formatDateStr(date) {
const d = date || new Date();
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
// Helper function to get date range for a specific day
function getDateRange(daysBack = 1) {
const now = new Date();
@ -112,7 +122,7 @@
start: startOfDay.getTime(),
end: endOfDay.getTime(),
date: targetDate,
dateKey: targetDate.toISOString().split('T')[0],
dateKey: formatDateStr(targetDate),
};
}