Skip to content

Commit 3fb0292

Browse files
authored
Merge pull request #11 from Hypercart-Dev-Tools/rules/time-false-positive
fix: Exclude gmdate() from timezone-sensitive pattern detection to Development
2 parents e315569 + 28a0734 commit 3fb0292

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [1.0.59] - 2025-12-31
99

1010
### Fixed
11+
- **Timezone-Sensitive Pattern False Positive** - Fixed detection to exclude `gmdate()` (timezone-safe function)
12+
- **Issue:** Pattern was flagging `gmdate()` as timezone-sensitive, but `gmdate()` always returns UTC (timezone-safe)
13+
- **Root Cause:** Pattern matched any function containing "date" without distinguishing between `date()` and `gmdate()`
14+
- **Fix:** Updated pattern to use `grep -v "gmdate"` to exclude timezone-safe `gmdate()` calls
15+
- **Impact:** Reduces false positives - only flags `date()` (timezone-dependent) and `current_time('timestamp')`
16+
- **Location:** Lines 2071-2082 in check-performance.sh
17+
- **Rationale:**
18+
- `date()` - Uses PHP's configured timezone (can vary by server) - **SHOULD BE FLAGGED**
19+
- `gmdate()` - Always returns UTC/GMT (consistent across environments) - **SHOULD NOT BE FLAGGED**
20+
- WordPress stores all dates internally as UTC, so `gmdate()` is the recommended approach
21+
- **Testing:** Verified with test file containing both `date()` and `gmdate()` calls
22+
-`date('Y-m-d')` - Correctly flagged
23+
-`gmdate('Y-m-d')` - Correctly NOT flagged
24+
-`current_time('timestamp')` - Correctly flagged
25+
1126
- **Version Drift Bug** - Created single source of truth for version number to prevent version inconsistencies
1227
- **Issue:** Script had 4 different hardcoded version strings that were out of sync (header: 1.0.59, banner/logs/JSON: 1.0.58)
1328
- **Root Cause:** Version number was hardcoded in 4 different locations instead of using a single variable

dist/bin/check-performance.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,13 +2069,17 @@ text_echo "${YELLOW}━━━ WARNING CHECKS (review recommended) ━━━${NC}
20692069
text_echo ""
20702070

20712071
# Enhanced timezone check - skip lines with phpcs:ignore comments
2072+
# Note: Only flags date() (timezone-dependent), not gmdate() (timezone-safe, always UTC)
20722073
text_echo "${BLUE}▸ Timezone-sensitive patterns (current_time/date) ${YELLOW}[LOW]${NC}"
20732074
TZ_WARNINGS=0
20742075
TZ_FINDING_COUNT=0
20752076
TZ_MATCHES=$(grep -rHn $EXCLUDE_ARGS --include="*.php" \
2076-
-e "current_time[[:space:]]*([[:space:]]*['\"]timestamp" \
2077-
-e "date[[:space:]]*([[:space:]]*['\"][YmdHis-]*['\"]" \
2077+
-E "current_time[[:space:]]*\([[:space:]]*['\"]timestamp" \
20782078
$PATHS 2>/dev/null || true)
2079+
# Add date() matches but exclude gmdate() (which is timezone-safe, always UTC)
2080+
TZ_MATCHES="${TZ_MATCHES}"$'\n'$(grep -rHn $EXCLUDE_ARGS --include="*.php" \
2081+
-E "[^a-zA-Z_]date[[:space:]]*\(" \
2082+
$PATHS 2>/dev/null | grep -v "gmdate" || true)
20792083

20802084
if [ -n "$TZ_MATCHES" ]; then
20812085
# Filter out lines that have phpcs:ignore nearby (check line before)

0 commit comments

Comments
 (0)