Skip to content

Commit 20fd195

Browse files
committed
Refactor: Move timestamp function to shared helpers (DRY cleanup)
ISSUE: - get_local_timestamp() was defined in main script - Function was not reusable by other scripts - Violated DRY principles (duplication risk) ROOT CAUSE: - Function was created before common-helpers.sh existed - Never migrated to shared library FIX: - Added timestamp_local() to dist/bin/lib/common-helpers.sh - Replaced 2 calls to get_local_timestamp() with timestamp_local() * Line 414: Log header timestamp * Line 463: Log footer timestamp - Deleted duplicate function definition from main script (line 234-236) IMPACT: - Timestamp function now reusable across all scripts - Follows DRY principles (single source of truth) - Future scripts can use timestamp_local() without duplication - Zero functional changes (output format unchanged) TESTING: - Ran script and verified log timestamps still work correctly - Format: 2025-12-31 11:32:06 PST ✓ - Appears in both log header and footer ✓ RELATED: - Part of DRY cleanup initiative (Phase 2) - Complements Phase 1 version drift fix
1 parent 8882d95 commit 20fd195

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Line 1216: Banner version (now uses `$SCRIPT_VERSION`)
2121
- **Future-Proof:** Only need to update ONE line (line 50) when bumping versions
2222

23+
- **Duplicate Timestamp Function** - Removed duplicate `get_local_timestamp()` and moved to shared helpers
24+
- **Issue:** `get_local_timestamp()` was defined in main script instead of using shared helper library
25+
- **Root Cause:** Function was created before `common-helpers.sh` existed
26+
- **Fix:**
27+
- Added `timestamp_local()` to `dist/bin/lib/common-helpers.sh` (line 23-28)
28+
- Replaced 2 calls to `get_local_timestamp()` with `timestamp_local()` (lines 414, 463)
29+
- Deleted duplicate function definition from main script
30+
- **Impact:** Timestamp function now reusable across all scripts, follows DRY principles
31+
- **Benefit:** Future scripts can use `timestamp_local()` without duplicating code
32+
2333
- **Template Loading Path** - Fixed `REPO_ROOT` variable in bash script to correctly load templates from `dist/TEMPLATES/`
2434
- **Issue:** Script was looking for templates in repository root `/TEMPLATES/` instead of `dist/TEMPLATES/`
2535
- **Root Cause:** `REPO_ROOT` was set to `$SCRIPT_DIR/../..` (repository root) instead of `$SCRIPT_DIR/..` (dist directory)

dist/bin/check-performance.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,6 @@ count_lines_of_code() {
231231
}
232232

233233
# Get local timestamp for user-friendly display
234-
get_local_timestamp() {
235-
date +"%Y-%m-%d %H:%M:%S %Z"
236-
}
237-
238234
# Detect WordPress plugin or theme information
239235
# Returns JSON object with project metadata including file/LOC counts
240236
detect_project_info() {
@@ -411,7 +407,7 @@ if [ "$ENABLE_LOGGING" = true ]; then
411407
fi
412408

413409
echo "Generated (UTC): $(date -u +"%Y-%m-%d %H:%M:%S")"
414-
echo "Local Time: $(get_local_timestamp)"
410+
echo "Local Time: $(timestamp_local)"
415411
echo "Script Version: $SCRIPT_VERSION"
416412
echo "Paths Scanned: $PATHS"
417413
echo "Strict Mode: $STRICT"
@@ -460,7 +456,7 @@ log_exit() {
460456
echo ""
461457
echo "========================================================================"
462458
echo "Completed (UTC): $(date -u +"%Y-%m-%d %H:%M:%S")"
463-
echo "Local Time: $(get_local_timestamp)"
459+
echo "Local Time: $(timestamp_local)"
464460
echo "Exit Code: $exit_code"
465461
echo "========================================================================"
466462
} >> "$LOG_FILE"

dist/bin/lib/common-helpers.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ timestamp_filename() {
1919
timestamp_iso8601() {
2020
date -u +"%Y-%m-%dT%H:%M:%SZ"
2121
}
22+
23+
# Generate local timestamp with timezone for display/logs
24+
# Usage: timestamp_local
25+
# Returns: 2025-12-31 11:27:32 PST
26+
timestamp_local() {
27+
date +"%Y-%m-%d %H:%M:%S %Z"
28+
}

0 commit comments

Comments
 (0)