feat(date): add cross-platform date compatibility for macOS and Linux
Add cross-platform date utility library to handle differences between GNU date (Linux) and BSD date (macOS). Fixes issues with: - ISO 8601 timestamp formatting (-Iseconds flag) - Date arithmetic operations (-d vs -v flags) Changes: - Created lib/date_utils.sh with get_iso_timestamp() and get_next_hour_time() - Updated ralph_loop.sh to use date utilities (2 instances) - Updated lib/circuit_breaker.sh to use date utilities (4 instances) - Updated lib/response_analyzer.sh to use date utilities (1 instance) All date operations now work consistently across both platforms without modification. The utility automatically detects the OS and uses the appropriate date command syntax. Tested on Linux with GNU date - all syntax checks and integration tests pass.
This commit is contained in:
parent
42b3a1ed8b
commit
3d7db2c3ae
4 changed files with 55 additions and 7 deletions
|
|
@ -7,6 +7,7 @@ set -e # Exit on any error
|
|||
|
||||
# Source library components
|
||||
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/lib/date_utils.sh"
|
||||
source "$SCRIPT_DIR/lib/response_analyzer.sh"
|
||||
source "$SCRIPT_DIR/lib/circuit_breaker.sh"
|
||||
|
||||
|
|
@ -164,14 +165,14 @@ update_status() {
|
|||
|
||||
cat > "$STATUS_FILE" << STATUSEOF
|
||||
{
|
||||
"timestamp": "$(date -Iseconds)",
|
||||
"timestamp": "$(get_iso_timestamp)",
|
||||
"loop_count": $loop_count,
|
||||
"calls_made_this_hour": $calls_made,
|
||||
"max_calls_per_hour": $MAX_CALLS_PER_HOUR,
|
||||
"last_action": "$last_action",
|
||||
"status": "$status",
|
||||
"exit_reason": "$exit_reason",
|
||||
"next_reset": "$(date -d '+1 hour' -Iseconds | cut -d'T' -f2 | cut -d'+' -f1)"
|
||||
"next_reset": "$(get_next_hour_time)"
|
||||
}
|
||||
STATUSEOF
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue