Date and Time Management on macOS
Manage date and time settings across your MacFleet with enterprise-grade automation, validation controls, and comprehensive monitoring capabilities.
Understanding Enterprise Date and Time Management
Enterprise date and time management requires more than basic date setting, demanding:
- Automated validation and formatting with enterprise-grade error handling
- Scheduled date/time operations with business logic integration
- Compliance tracking for audit requirements and regulatory standards
- Real-time monitoring of date/time changes and system integrity
- Integration capabilities with enterprise scheduling and workflow systems
- Security controls to prevent unauthorized time manipulation
Core Date and Time Management Process
Basic Commands
- Set Date/Time -
date MMDDhhmm[[CC]YY][.ss]
- Parameterized Setting -
date $1
(with argument passing)
Core Date Format
The format follows: MMDDhhmm[[CC]YY][.ss]
- MM - Month (01-12)
- DD - Day (01-31)
- hh - Hour (00-23)
- mm - Minutes (00-59)
- CC - Century (optional)
- YY - Year (optional)
- ss - Seconds (optional)
Basic Configuration Examples
# Basic date setting
date 120614302023.00 # December 6, 2023 2:30 PM
# Parameterized version
date $1 # Pass date as argument
Enterprise Date and Time Management System
#!/bin/bash
# MacFleet Enterprise Date and Time Management System
# Comprehensive date/time management with enterprise controls and monitoring
# Configuration
SCRIPT_NAME="MacFleet Date/Time Manager"
VERSION="1.0.0"
LOG_FILE="/var/log/macfleet_datetime.log"
AUDIT_LOG="/var/log/macfleet_datetime_audit.log"
CONFIG_DIR="/etc/macfleet/datetime"
POLICIES_DIR="/etc/macfleet/datetime/policies"
BACKUP_DIR="/var/backups/datetime"
TEMP_DIR="/tmp/macfleet_datetime"
ORGANIZATION_NAME="MacFleet Enterprise"
DEPLOYMENT_MODE="enterprise"
ENABLE_VALIDATION=true
ENABLE_AUDIT_LOGGING=true
ENABLE_BACKUP_RESTORE=true
MAX_TIME_DRIFT_HOURS=24
BUSINESS_HOURS_START="08:00"
BUSINESS_HOURS_END="18:00"
# Date/Time Validation Patterns
declare -A DATE_FORMATS=(
["macfleet"]="MMDDhhmm[[CC]YY][.ss]"
["iso8601"]="YYYY-MM-DDTHH:MM:SS"
["unix"]="seconds_since_epoch"
["readable"]="Month DD, YYYY HH:MM:SS"
)
# Enterprise Scheduling Policies
declare -A SCHEDULING_POLICIES=(
["immediate"]="execute_now"
["business_hours"]="within_business_hours_only"
["maintenance_window"]="scheduled_maintenance_only"
["emergency"]="override_all_restrictions"
)
# Compliance Standards
declare -A COMPLIANCE_REQUIREMENTS=(
["SOX"]="financial_audit_trail"
["HIPAA"]="healthcare_time_integrity"
["PCI_DSS"]="payment_transaction_accuracy"
["ISO27001"]="information_security_timestamps"
)
# Create necessary directories
mkdir -p "$CONFIG_DIR"
mkdir -p "$POLICIES_DIR"
mkdir -p "$BACKUP_DIR"
mkdir -p "$TEMP_DIR"
mkdir -p "$(dirname "$LOG_FILE")"
mkdir -p "$(dirname "$AUDIT_LOG")"
# Set secure permissions
chmod 755 "$CONFIG_DIR"
chmod 750 "$POLICIES_DIR"
chmod 750 "$BACKUP_DIR"
chmod 700 "$TEMP_DIR"
# Logging functions
log_operation() {
local level="$1"
local message="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local admin_user=$(whoami)
echo "[$timestamp] [$level] [$admin_user] $message" | tee -a "$LOG_FILE"
}
log_security_event() {
local event_type="$1"
local details="$2"
local severity="$3"
local admin_user=$(whoami)
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local source_ip=$(who am i | awk '{print $5}' | tr -d '()')
echo "SECURITY|$timestamp|$event_type|$severity|$admin_user|$source_ip|$details" >> "$AUDIT_LOG"
}
# Get current date and time information
get_current_datetime() {
local format="${1:-all}"
echo "=== Current Date and Time Information ==="
echo "Local Time: $(date '+%Y-%m-%d %H:%M:%S %Z')"
echo "UTC Time: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo "Unix Timestamp: $(date +%s)"
echo "Uptime: $(uptime | awk -F'up ' '{print $2}' | awk -F',' '{print $1}')"
case "$format" in
"macfleet")
echo "Macfleet Format: $(date '+%m%d%H%M%Y.%S')"
;;
"iso8601")
echo "ISO 8601 Format: $(date '+%Y-%m-%dT%H:%M:%S')"
;;
"detailed")
echo ""
echo "Detailed Information:"
echo " Year: $(date '+%Y')"
echo " Month: $(date '+%m') ($(date '+%B'))"
echo " Day: $(date '+%d')"
echo " Hour: $(date '+%H')"
echo " Minute: $(date '+%M')"
echo " Second: $(date '+%S')"
echo " Day of Week: $(date '+%A')"
echo " Day of Year: $(date '+%j')"
echo " Week of Year: $(date '+%U')"
;;
esac
echo ""
}
# Validate date/time format
validate_datetime_format() {
local datetime_string="$1"
local format_type="${2:-macfleet}"
echo "=== Date/Time Format Validation ==="
echo "Input: $datetime_string"
echo "Expected Format: $format_type"
echo ""
case "$format_type" in
"macfleet")
# Validate Macfleet format: MMDDhhmm[[CC]YY][.ss]
if [[ "$datetime_string" =~ ^[0-9]{8}([0-9]{4})?(\.[0-9]{2})?$ ]]; then
local month="${datetime_string:0:2}"
local day="${datetime_string:2:2}"
local hour="${datetime_string:4:2}"
local minute="${datetime_string:6:2}"
# Validate ranges
if [[ $month -ge 1 && $month -le 12 ]] && \
[[ $day -ge 1 && $day -le 31 ]] && \
[[ $hour -ge 0 && $hour -le 23 ]] && \
[[ $minute -ge 0 && $minute -le 59 ]]; then
echo "✅ Valid Macfleet format"
return 0
else
echo "❌ Invalid date/time values in Macfleet format"
return 1
fi
else
echo "❌ Invalid Macfleet format structure"
echo "Expected: MMDDhhmm[[CC]YY][.ss]"
return 1
fi
;;
"iso8601")
# Validate ISO 8601 format
if date -j -f "%Y-%m-%dT%H:%M:%S" "$datetime_string" &>/dev/null; then
echo "✅ Valid ISO 8601 format"
return 0
else
echo "❌ Invalid ISO 8601 format"
return 1
fi
;;
"unix")
# Validate Unix timestamp
if [[ "$datetime_string" =~ ^[0-9]+$ ]] && [[ $datetime_string -gt 0 ]]; then
echo "✅ Valid Unix timestamp"
return 0
else
echo "❌ Invalid Unix timestamp"
return 1
fi
;;
*)
echo "❌ Unknown format type: $format_type"
return 1
;;
esac
}
# Convert between date formats
convert_datetime_format() {
local input_datetime="$1"
local from_format="$2"
local to_format="$3"
echo "=== Date/Time Format Conversion ==="
echo "Input: $input_datetime"
echo "From: $from_format"
echo "To: $to_format"
echo ""
local converted_datetime
case "$from_format" in
"macfleet")
# Convert from Macfleet format
local month="${input_datetime:0:2}"
local day="${input_datetime:2:2}"
local hour="${input_datetime:4:2}"
local minute="${input_datetime:6:2}"
local year_part="${input_datetime:8:4}"
local seconds_part="${input_datetime:13:2}"
# Default year if not provided
if [[ -z "$year_part" ]]; then
year_part=$(date '+%Y')
fi
# Default seconds if not provided
if [[ -z "$seconds_part" ]]; then
seconds_part="00"
fi
case "$to_format" in
"iso8601")
converted_datetime="${year_part}-${month}-${day}T${hour}:${minute}:${seconds_part}"
;;
"readable")
converted_datetime=$(date -j "${month}${day}${hour}${minute}${year_part}.${seconds_part}" '+%B %d, %Y %H:%M:%S' 2>/dev/null)
;;
"unix")
converted_datetime=$(date -j "${month}${day}${hour}${minute}${year_part}.${seconds_part}" '+%s' 2>/dev/null)
;;
esac
;;
"iso8601")
# Convert from ISO 8601 format
case "$to_format" in
"macfleet")
converted_datetime=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$input_datetime" '+%m%d%H%M%Y.%S' 2>/dev/null)
;;
"readable")
converted_datetime=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$input_datetime" '+%B %d, %Y %H:%M:%S' 2>/dev/null)
;;
"unix")
converted_datetime=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$input_datetime" '+%s' 2>/dev/null)
;;
esac
;;
"unix")
# Convert from Unix timestamp
case "$to_format" in
"macfleet")
converted_datetime=$(date -r "$input_datetime" '+%m%d%H%M%Y.%S' 2>/dev/null)
;;
"iso8601")
converted_datetime=$(date -r "$input_datetime" '+%Y-%m-%dT%H:%M:%S' 2>/dev/null)
;;
"readable")
converted_datetime=$(date -r "$input_datetime" '+%B %d, %Y %H:%M:%S' 2>/dev/null)
;;
esac
;;
esac
if [[ -n "$converted_datetime" ]]; then
echo "✅ Conversion successful"
echo "Result: $converted_datetime"
echo "$converted_datetime"
return 0
else
echo "❌ Conversion failed"
return 1
fi
}
# Set date and time with enterprise validation
set_enterprise_datetime() {
local datetime_input="$1"
local format_type="${2:-macfleet}"
local policy="${3:-business_hours}"
local force="${4:-false}"
local admin_user=$(whoami)
log_security_event "DATETIME_CHANGE_ATTEMPT" "datetime=$datetime_input,format=$format_type,policy=$policy" "INFO"
echo "=== Enterprise Date/Time Configuration ==="
echo "Input: $datetime_input"
echo "Format: $format_type"
echo "Policy: $policy"
echo "Administrator: $admin_user"
echo "Force Mode: $force"
echo ""
# Validate input format
if ! validate_datetime_format "$datetime_input" "$format_type"; then
log_operation "ERROR" "Invalid date/time format: $datetime_input ($format_type)"
return 1
fi
# Check scheduling policy
if [[ "$policy" == "business_hours" && "$force" != "true" ]]; then
local current_hour=$(date '+%H')
local business_start_hour="${BUSINESS_HOURS_START:0:2}"
local business_end_hour="${BUSINESS_HOURS_END:0:2}"
if [[ $current_hour -lt $business_start_hour || $current_hour -gt $business_end_hour ]]; then
echo "⚠️ Operation requested outside business hours ($BUSINESS_HOURS_START-$BUSINESS_HOURS_END)"
echo "Use force=true to override or wait for business hours"
log_operation "WARNING" "Date/time change blocked by business hours policy"
return 1
fi
fi
# Backup current date/time
local backup_file="$BACKUP_DIR/datetime_$(date +%Y%m%d_%H%M%S).backup"
{
echo "# MacFleet Date/Time Backup"
echo "PREVIOUS_DATETIME=$(date '+%Y-%m-%d %H:%M:%S %Z')"
echo "PREVIOUS_UTC=$(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo "PREVIOUS_UNIX=$(date +%s)"
echo "BACKUP_TIMESTAMP=$(date)"
echo "CHANGED_BY=$admin_user"
echo "NEW_DATETIME=$datetime_input"
echo "FORMAT_TYPE=$format_type"
echo "POLICY=$policy"
} > "$backup_file"
log_operation "INFO" "Date/time backup created: $backup_file"
# Convert to appropriate format if needed
local macfleet_format="$datetime_input"
if [[ "$format_type" != "macfleet" ]]; then
echo "Converting $format_type to Macfleet format..."
macfleet_format=$(convert_datetime_format "$datetime_input" "$format_type" "macfleet")
if [[ $? -ne 0 ]]; then
log_operation "ERROR" "Failed to convert date/time format"
return 1
fi
echo "Converted format: $macfleet_format"
fi
# Validate time drift
local current_unix=$(date +%s)
local target_unix=$(convert_datetime_format "$macfleet_format" "macfleet" "unix")
local time_diff=$((target_unix - current_unix))
local time_diff_hours=$((time_diff / 3600))
local time_diff_abs=${time_diff_hours#-}
if [[ $time_diff_abs -gt $MAX_TIME_DRIFT_HOURS && "$force" != "true" ]]; then
echo "⚠️ Large time change detected: ${time_diff_hours} hours"
echo "This exceeds the maximum drift threshold of $MAX_TIME_DRIFT_HOURS hours"
echo "Use force=true to override this safety check"
log_operation "WARNING" "Large time drift blocked: ${time_diff_hours} hours"
return 1
fi
# Apply date/time change
echo "Setting date/time to: $macfleet_format"
if sudo date "$macfleet_format" &>/dev/null; then
echo "✅ Date/time set successfully"
log_operation "INFO" "Date/time changed to: $macfleet_format (format: $format_type)"
log_security_event "DATETIME_CHANGED" "new_datetime=$macfleet_format,drift_hours=$time_diff_hours,policy=$policy" "INFO"
# Verify the change
sleep 1
echo ""
echo "Verification:"
get_current_datetime
return 0
else
echo "❌ Failed to set date/time"
log_operation "ERROR" "Failed to set date/time: $macfleet_format"
log_security_event "DATETIME_CHANGE_FAILED" "datetime=$macfleet_format,error=date_command_failed" "ERROR"
return 1
fi
}
# Schedule date/time operations
schedule_datetime_operation() {
local operation="$1"
local target_datetime="$2"
local schedule_time="$3"
local policy="${4:-business_hours}"
echo "=== Scheduled Date/Time Operation ==="
echo "Operation: $operation"
echo "Target DateTime: $target_datetime"
echo "Schedule Time: $schedule_time"
echo "Policy: $policy"
echo ""
# Create scheduled operation file
local schedule_file="$POLICIES_DIR/scheduled_$(date +%Y%m%d_%H%M%S).sh"
cat > "$schedule_file" << EOF
#!/bin/bash
# MacFleet Scheduled Date/Time Operation
# Generated: $(date)
# Operation: $operation
# Target: $target_datetime
# Policy: $policy
# Execute the scheduled operation
case "$operation" in
"set_datetime")
$0 set "$target_datetime" macfleet "$policy" true
;;
"sync_time")
sudo systemsetup -setusingnetworktime on
;;
"backup_datetime")
$0 backup
;;
*)
echo "Unknown operation: $operation"
exit 1
;;
esac
EOF
chmod +x "$schedule_file"
# Schedule using at command (if available)
if command -v at &>/dev/null; then
echo "$schedule_file" | at "$schedule_time" 2>/dev/null
if [[ $? -eq 0 ]]; then
echo "✅ Operation scheduled successfully for $schedule_time"
log_operation "INFO" "Scheduled operation: $operation at $schedule_time"
return 0
else
echo "❌ Failed to schedule operation"
log_operation "ERROR" "Failed to schedule operation: $operation"
return 1
fi
else
echo "⚠️ 'at' command not available for scheduling"
echo "Schedule file created: $schedule_file"
echo "Execute manually or integrate with your scheduling system"
return 1
fi
}
# Monitor date/time integrity
monitor_datetime_integrity() {
local check_type="${1:-basic}"
local admin_user=$(whoami)
echo "=== Date/Time Integrity Monitoring ==="
echo "Check Type: $check_type"
echo "Monitor: $admin_user"
echo ""
local integrity_status="HEALTHY"
local issues=()
# Check system clock vs network time
if command -v ntpdate &>/dev/null; then
echo "Checking time synchronization..."
local ntp_time=$(ntpdate -q pool.ntp.org 2>/dev/null | tail -1 | grep -o "offset [+-][0-9.]*" | awk '{print $2}')
if [[ -n "$ntp_time" ]]; then
local offset_abs=${ntp_time#-}
echo "NTP offset: ${ntp_time}s"
if (( $(echo "$offset_abs > 30" | bc -l) )); then
integrity_status="WARNING"
issues+=("Large NTP offset: ${ntp_time}s")
else
echo "✅ Time synchronization within acceptable range"
fi
else
integrity_status="WARNING"
issues+=("Unable to check NTP synchronization")
fi
fi
# Check for recent large time changes
if [[ -f "$AUDIT_LOG" ]]; then
echo ""
echo "Checking recent time changes..."
local recent_changes=$(grep "DATETIME_CHANGED" "$AUDIT_LOG" | tail -5)
if [[ -n "$recent_changes" ]]; then
echo "Recent date/time changes found:"
echo "$recent_changes" | while read -r line; do
echo " $(echo "$line" | cut -d'|' -f2,6)"
done
else
echo "✅ No recent date/time changes detected"
fi
fi
# Advanced checks
if [[ "$check_type" == "comprehensive" ]]; then
echo ""
echo "Running comprehensive integrity checks..."
# Check system logs for time-related errors
local time_errors=$(log show --predicate 'subsystem == "com.apple.time"' --last 1h 2>/dev/null | grep -i error | wc -l)
if [[ $time_errors -gt 0 ]]; then
integrity_status="WARNING"
issues+=("System time errors detected: $time_errors")
fi
# Check for timezone mismatches
local system_tz=$(systemsetup -gettimezone 2>/dev/null | awk -F': ' '{print $2}')
local env_tz="$TZ"
if [[ -n "$env_tz" && "$env_tz" != "$system_tz" ]]; then
integrity_status="WARNING"
issues+=("Timezone mismatch: system=$system_tz, env=$env_tz")
fi
fi
# Generate integrity report
echo ""
echo "=== Date/Time Integrity Report ==="
echo "Overall Status: $integrity_status"
echo "Timestamp: $(date)"
if [[ ${#issues[@]} -gt 0 ]]; then
echo "Issues Found:"
printf ' - %s\n' "${issues[@]}"
else
echo "✅ All date/time systems operating normally"
fi
# Log monitoring results
log_operation "INFO" "Date/time integrity check completed: $integrity_status (${#issues[@]} issues)"
log_security_event "DATETIME_INTEGRITY_CHECK" "status=$integrity_status,issues=${#issues[@]}" "INFO"
# Return appropriate exit code
case "$integrity_status" in
"HEALTHY") return 0 ;;
"WARNING") return 1 ;;
"CRITICAL") return 2 ;;
*) return 3 ;;
esac
}
# Generate date/time management report
generate_datetime_report() {
local report_type="${1:-summary}"
local admin_user=$(whoami)
local report_file="/var/reports/datetime_report_$(date +%Y%m%d_%H%M%S).txt"
mkdir -p "$(dirname "$report_file")"
log_security_event "REPORT_GENERATION" "type=$report_type" "INFO"
{
echo "MacFleet Date/Time Management Report"
echo "==================================="
echo "Report Type: $report_type"
echo "Generated: $(date)"
echo "Generated By: $admin_user"
echo "Hostname: $(hostname)"
echo ""
case "$report_type" in
"summary")
echo "== Date/Time Summary =="
get_current_datetime "detailed"
echo "Available Formats:"
for format in "${!DATE_FORMATS[@]}"; do
echo " $format: ${DATE_FORMATS[$format]}"
done
;;
"compliance")
echo "== Compliance Assessment =="
echo "Compliance Standards:"
for standard in "${!COMPLIANCE_REQUIREMENTS[@]}"; do
echo " $standard: ${COMPLIANCE_REQUIREMENTS[$standard]}"
done
echo ""
echo "Recent Audit Events:"
if [[ -f "$AUDIT_LOG" ]]; then
tail -10 "$AUDIT_LOG"
else
echo "No audit log available"
fi
;;
"audit")
echo "== Audit Information =="
if [[ -f "$AUDIT_LOG" ]]; then
echo "Complete audit trail:"
cat "$AUDIT_LOG"
else
echo "No audit log available"
fi
;;
esac
echo ""
echo "== System Information =="
echo "Uptime: $(uptime)"
echo "Load Average: $(uptime | awk -F'load average:' '{print $2}')"
} > "$report_file"
echo "Date/time report generated: $report_file"
log_operation "INFO" "Date/time report generated: $report_file"
}
# Backup and restore date/time settings
backup_datetime_settings() {
local backup_type="${1:-full}"
echo "=== Date/Time Settings Backup ==="
echo "Backup Type: $backup_type"
echo ""
local backup_file="$BACKUP_DIR/datetime_settings_$(date +%Y%m%d_%H%M%S).backup"
{
echo "# MacFleet Date/Time Settings Backup"
echo "BACKUP_DATE=$(date)"
echo "BACKUP_TYPE=$backup_type"
echo ""
echo "# Current Settings"
echo "CURRENT_DATETIME=$(date '+%Y-%m-%d %H:%M:%S %Z')"
echo "CURRENT_UTC=$(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo "CURRENT_UNIX=$(date +%s)"
echo "CURRENT_TIMEZONE=$(systemsetup -gettimezone 2>/dev/null | awk -F': ' '{print $2}')"
echo "NETWORK_TIME=$(systemsetup -getusingnetworktime 2>/dev/null | awk -F': ' '{print $2}')"
echo "TIME_SERVER=$(systemsetup -getnetworktimeserver 2>/dev/null | awk -F': ' '{print $2}')"
echo ""
echo "# System Information"
echo "HOSTNAME=$(hostname)"
echo "UPTIME=$(uptime)"
echo "BACKUP_BY=$(whoami)"
} > "$backup_file"
echo "✅ Backup created: $backup_file"
log_operation "INFO" "Date/time settings backed up: $backup_file"
}
# Main date/time management function
main() {
local action="${1:-help}"
case "$action" in
"status"|"current")
local format="${2:-all}"
get_current_datetime "$format"
;;
"set")
local datetime_input="$2"
local format_type="${3:-macfleet}"
local policy="${4:-business_hours}"
local force="$5"
if [[ -z "$datetime_input" ]]; then
echo "Usage: $0 set <datetime> [format] [policy] [force]"
echo "Example: $0 set 120614302023.00 macfleet business_hours"
return 1
fi
set_enterprise_datetime "$datetime_input" "$format_type" "$policy" "$force"
;;
"validate")
local datetime_input="$2"
local format_type="${3:-macfleet}"
if [[ -z "$datetime_input" ]]; then
echo "Usage: $0 validate <datetime> [format]"
return 1
fi
validate_datetime_format "$datetime_input" "$format_type"
;;
"convert")
local datetime_input="$2"
local from_format="$3"
local to_format="$4"
if [[ -z "$datetime_input" || -z "$from_format" || -z "$to_format" ]]; then
echo "Usage: $0 convert <datetime> <from_format> <to_format>"
echo "Available formats: macfleet, iso8601, unix, readable"
return 1
fi
convert_datetime_format "$datetime_input" "$from_format" "$to_format"
;;
"schedule")
local operation="$2"
local target_datetime="$3"
local schedule_time="$4"
local policy="${5:-business_hours}"
if [[ -z "$operation" || -z "$target_datetime" || -z "$schedule_time" ]]; then
echo "Usage: $0 schedule <operation> <target_datetime> <schedule_time> [policy]"
echo "Operations: set_datetime, sync_time, backup_datetime"
return 1
fi
schedule_datetime_operation "$operation" "$target_datetime" "$schedule_time" "$policy"
;;
"monitor")
local check_type="${2:-basic}"
monitor_datetime_integrity "$check_type"
;;
"backup")
local backup_type="${2:-full}"
backup_datetime_settings "$backup_type"
;;
"report")
local report_type="${2:-summary}"
generate_datetime_report "$report_type"
;;
"help"|*)
echo "$SCRIPT_NAME v$VERSION"
echo "Enterprise Date and Time Management"
echo ""
echo "Usage: $0 <action> [options]"
echo ""
echo "Actions:"
echo " status [format] - Show current date/time information"
echo " set <datetime> [format] [policy] [force] - Set date/time with validation"
echo " validate <datetime> [format] - Validate date/time format"
echo " convert <datetime> <from> <to> - Convert between formats"
echo " schedule <op> <datetime> <time> [policy] - Schedule date/time operations"
echo " monitor [type] - Monitor date/time integrity"
echo " backup [type] - Backup date/time settings"
echo " report [type] - Generate date/time reports"
echo " help - Show this help message"
echo ""
echo "Date/Time Formats:"
for format in "${!DATE_FORMATS[@]}"; do
echo " $format: ${DATE_FORMATS[$format]}"
done
echo ""
echo "Scheduling Policies:"
for policy in "${!SCHEDULING_POLICIES[@]}"; do
echo " $policy: ${SCHEDULING_POLICIES[$policy]}"
done
echo ""
echo "Monitor Types:"
echo " basic - Basic integrity checks"
echo " comprehensive - Extended monitoring and validation"
echo ""
echo "Report Types:"
echo " summary - Date/time overview (default)"
echo " compliance - Compliance assessment"
echo " audit - Complete audit trail"
echo ""
echo "Examples:"
echo " $0 set 120614302023.00 - Set date/time in Macfleet format"
echo " $0 set '2023-12-06T14:30:00' iso8601 - Set using ISO 8601 format"
echo " $0 convert 120614302023.00 macfleet iso8601 - Convert formats"
echo " $0 schedule set_datetime 010108002024.00 '09:00 tomorrow' - Schedule operation"
echo " $0 monitor comprehensive - Full integrity check"
echo ""
echo "Features:"
echo " • Enterprise-grade date/time management"
echo " • Multiple format support and conversion"
echo " • Business hours and policy enforcement"
echo " • Comprehensive validation and safety checks"
echo " • Audit logging and compliance tracking"
echo " • Scheduled operations and automation"
echo " • Real-time monitoring and integrity checks"
;;
esac
}
# Execute main function with all arguments
main "$@"
Quick Reference Commands
Basic Date/Time Operations
# Check current date/time status
./datetime_manager.sh status
# Set date/time using Macfleet format (Dec 6, 2023 2:30 PM)
./datetime_manager.sh set 120614302023.00
# Set using ISO 8601 format
./datetime_manager.sh set "2023-12-06T14:30:00" iso8601
# Validate date/time format before setting
./datetime_manager.sh validate 120614302023.00 macfleet
Format Conversion
# Convert Macfleet to ISO 8601
./datetime_manager.sh convert 120614302023.00 macfleet iso8601
# Convert ISO 8601 to readable format
./datetime_manager.sh convert "2023-12-06T14:30:00" iso8601 readable
# Convert to Unix timestamp
./datetime_manager.sh convert 120614302023.00 macfleet unix
Enterprise Operations
# Set with business hours policy enforcement
./datetime_manager.sh set 120614302023.00 macfleet business_hours
# Force set outside business hours
./datetime_manager.sh set 120614302023.00 macfleet business_hours true
# Schedule future date/time operation
./datetime_manager.sh schedule set_datetime 010108002024.00 "09:00 tomorrow"
Monitoring and Compliance
# Basic integrity monitoring
./datetime_manager.sh monitor basic
# Comprehensive monitoring
./datetime_manager.sh monitor comprehensive
# Generate compliance report
./datetime_manager.sh report compliance
# Backup current settings
./datetime_manager.sh backup full
Integration Examples
JAMF Pro Integration
#!/bin/bash
# JAMF Pro script for date/time management
# Parameters: $4 = target_datetime, $5 = format, $6 = policy, $7 = force
TARGET_DATETIME="$4"
FORMAT="${5:-macfleet}"
POLICY="${6:-business_hours}"
FORCE="$7"
# Download datetime manager if not present
if [[ ! -f "/usr/local/bin/macfleet_datetime_manager.sh" ]]; then
curl -o "/usr/local/bin/macfleet_datetime_manager.sh" \
"https://scripts.macfleet.com/datetime_manager.sh"
chmod +x "/usr/local/bin/macfleet_datetime_manager.sh"
fi
# Set date/time with enterprise controls
if [[ -n "$TARGET_DATETIME" ]]; then
/usr/local/bin/macfleet_datetime_manager.sh set \
"$TARGET_DATETIME" "$FORMAT" "$POLICY" "$FORCE"
# Report status back to JAMF
if [[ $? -eq 0 ]]; then
echo "Date/time set successfully: $TARGET_DATETIME"
exit 0
else
echo "Date/time setting failed: $TARGET_DATETIME"
exit 1
fi
else
echo "No target date/time provided"
exit 1
fi
Automated Compliance Monitoring
#!/bin/bash
# Continuous date/time compliance monitoring
monitor_datetime_compliance() {
local monitoring_interval=3600 # 1 hour
local compliance_standard="SOX"
while true; do
# Run integrity monitoring
if /usr/local/bin/macfleet_datetime_manager.sh monitor comprehensive &>/dev/null; then
echo "$(date): Date/time compliance check passed"
else
echo "$(date): Date/time compliance issues detected"
# Generate compliance report
/usr/local/bin/macfleet_datetime_manager.sh report compliance
# Send alert
send_compliance_alert "Date/time integrity issues" "$compliance_standard"
fi
sleep "$monitoring_interval"
done
}
Advanced Features
Scheduled Operations
# Advanced scheduling with business logic
schedule_maintenance_datetime() {
local target_datetime="$1"
local maintenance_window="$2"
echo "=== Maintenance Window Date/Time Setting ==="
echo "Target: $target_datetime"
echo "Window: $maintenance_window"
# Schedule for next maintenance window
/usr/local/bin/macfleet_datetime_manager.sh schedule \
set_datetime "$target_datetime" "$maintenance_window" maintenance_window
}
Compliance Automation
# Automated compliance validation
validate_compliance_requirements() {
local standard="$1"
echo "=== Compliance Validation ==="
echo "Standard: $standard"
case "$standard" in
"SOX")
# Sarbanes-Oxley requires accurate timestamps
check_timestamp_accuracy_strict
verify_audit_trail_completeness
;;
"HIPAA")
# HIPAA requires time integrity for medical records
check_medical_timestamp_integrity
verify_time_source_reliability
;;
"PCI_DSS")
# PCI DSS requires accurate transaction timestamps
check_payment_timestamp_accuracy
verify_time_sync_security
;;
esac
}
Best Practices
- Validate all date/time inputs before applying changes
- Use business hours policies to prevent unauthorized changes
- Implement backup and restore for critical time changes
- Monitor time drift continuously with automated alerting
- Maintain comprehensive audit logs for compliance
- Test format conversions before production deployment
- Coordinate with network teams for time synchronization
- Document all scheduled operations for operational awareness
This enterprise date and time management system provides comprehensive date/time control with validation, scheduling, compliance tracking, and enterprise-grade automation capabilities for effective MacFleet time management.