Purpose
This document explains the operating principles of the SecurityHelper::validate_date method and the date normalization standards used across the Rentiva ecosystem.
π Date Validation and Normalization
Dates in Rentiva can arrive in various formats (UI, API, DatePicker). The SecurityHelper::validate_date method acts as a "Secure Gate" that converts all these inputs into the standard ISO (YYYY-MM-DD) format.
π οΈ Validation Hierarchyβ
The method attempts to normalize incoming data in the following order:
- ISO Check: If the value is already in
YYYY-MM-DDformat, it is returned directly. - WP Date Format: Attempts to parse using the
date_formatvalue from WordPress settings (e.g.d/m/Y). - Common Formats: Iterates through
d/m/Y,m/d/Y,d-m-Y,Y/m/din a loop. - Normalization & Fallback: Converts separators (
.,/,) to-and makes a final attempt withstrtotime.
π Flow Diagramβ
π» Usage Exampleβ
use MHMRentiva\Admin\Core\SecurityHelper;
try {
// Validation with different formats
$date1 = SecurityHelper::validate_date('2026-01-01'); // Returns '2026-01-01'
$date2 = SecurityHelper::validate_date('31/12/2025'); // Returns '2025-12-31'
$date3 = SecurityHelper::validate_date('2025.05.20'); // Returns '2025-05-20'
} catch (\InvalidArgumentException $e) {
// Invalid format handling
AdvancedLogger::error('Invalid date attempt: ' . $e->getMessage());
}
π‘οΈ Security and Error Handlingβ
- Strict Validation: If no format matches, the method throws an
InvalidArgumentException. - Null Safety: If the input is empty or null, it is cleaned via
sanitize_text_field_safeand an exception is thrown. - Timezone: The final output is always produced as UTC-based via
gmdate('Y-m-d').
Section Summaryβ
- All date inputs must pass through the
validate_datefilter. - The output is always a string in ISO (YYYY-MM-DD) format.
- On failure, an
Exceptionis thrown that interrupts the application flow.
Changelogβ
| Date | Version | Note |
|---|---|---|
| 23.04.2026 | 4.27.2 | English translation added. |
| 19.03.2026 | 4.21.2 | Updated to reflect SecurityHelper::validate_date normalization and fallback logic. |