Date Patterns
Comprehensive date and timestamp validation patterns.
MCP Aegis provides sophisticated date and timestamp pattern matching capabilities for validating temporal data in your MCP server responses. These patterns support various date formats, time ranges, age validation, and format checking.
Flexible Date Input Formats
Date patterns automatically handle multiple input formats including ISO 8601 strings, Unix timestamps (numbers or strings), and common date formats like "6/15/2023" or "June 15, 2023".
Date Validation
Use dateValid to verify that a value represents a valid date or timestamp.
# Basic date validation
expect:
response:
result:
createdAt: "match:dateValid" # Must be a valid date/timestamp
updatedAt: "match:dateValid" # Supports various formats
publishDate: "match:dateValid" # ISO, timestamp, or date string
# Negation - should NOT be valid dates
invalidDate: "match:not:dateValid" # Should be invalid
nullDate: "match:not:dateValid" # null values are invalidSupported Date Formats
- ISO 8601: "2023-06-15T14:30:00.000Z", "2023-06-15"
- Unix Timestamps: 1687686600000 (number or string)
- Common Formats: "6/15/2023", "June 15, 2023"
Date Comparisons
Compare dates against specific points in time using temporal comparison patterns.
Date After
# Validate dates are after a specific point
expect:
response:
result:
createdAt: "match:dateAfter:2023-01-01" # After Jan 1, 2023
publishDate: "match:dateAfter:2023-06-15T14:30:00.000Z" # After specific timestamp
lastLogin: "match:dateAfter:1687686600000" # After Unix timestamp
# Can use with any supported date format
eventTime: "match:dateAfter:6/1/2023" # After June 1st, 2023Date Before
# Validate dates are before a specific point
expect:
response:
result:
expireDate: "match:dateBefore:2025-01-01" # Before Jan 1, 2025
deadline: "match:dateBefore:2024-12-31T23:59:59.999Z"
archiveDate: "match:dateBefore:1735689599999" # Before Unix timestampDate Between
# Validate dates fall within a range
expect:
response:
result:
eventDate: "match:dateBetween:2023-01-01:2024-12-31"
validPeriod: "match:dateBetween:2023-06-01T00:00:00Z:2023-06-30T23:59:59Z"
campaignDates: "match:dateBetween:1687686600000:1719309999000"
# Mix different date formats (both boundaries and value can use any format)
promotionEnd: "match:dateBetween:6/1/2023:6/30/2023"Date Age Validation
Validate how recent or old dates are using the dateAge pattern with duration units.
# Validate dates are within specific age limits
expect:
response:
result:
# Recent timestamps
currentActivity: "match:dateAge:1d" # Within last day
hourlyUpdate: "match:dateAge:2h" # Within last 2 hours
minuteCheck: "match:dateAge:30m" # Within last 30 minutes
secondCheck: "match:dateAge:45s" # Within last 45 seconds
millisCheck: "match:dateAge:1000ms" # Within last 1000ms
# Weekly/monthly validations
weeklyReport: "match:dateAge:7d" # Within last week
monthlyBackup: "match:dateAge:30d" # Within last 30 days
# Negation - should NOT be recent
oldArchive: "match:not:dateAge:1d" # NOT within last day (older)Duration Units
Supported units: ms (milliseconds), s (seconds), m (minutes), h (hours), d (days)
Examples: "1000ms", "30s", "5m", "2h", "7d"
Exact Date Matching
Match exact date and timestamp values using dateEquals.
# Exact date matching
expect:
response:
result:
# Fixed dates and timestamps
fixedEvent: "match:dateEquals:2023-06-15T14:30:00.000Z"
unixTimestamp: "match:dateEquals:1687686600000"
dateString: "match:dateEquals:2023-06-15"
# Can match across different formats
# (both the expected and actual values are parsed before comparison)
eventDate: "match:dateEquals:6/15/2023" # Matches "2023-06-15"
timestampStr: "match:dateEquals:1687686600" # Matches 1687686600000Date Format Validation
Validate that date strings conform to specific formats using dateFormat.
# Format-specific validation
expect:
response:
result:
# ISO 8601 formats
fullIso: "match:dateFormat:iso" # "2023-06-15T14:30:00.000Z"
dateOnly: "match:dateFormat:iso-date" # "2023-06-15"
timeOnly: "match:dateFormat:iso-time" # "14:30:00.000"
# Regional formats
usFormat: "match:dateFormat:us-date" # "6/15/2023" or "06/15/2023"
euFormat: "match:dateFormat:eu-date" # "15/6/2023" or "15/06/2023"
# Numeric timestamps
timestampStr: "match:dateFormat:timestamp" # "1687686600000"
# Negation - should NOT match format
notIso: "match:not:dateFormat:iso" # Should not be ISO formatReal-World Examples
Practical examples from production MCP server testing.
# API response with mixed date formats
- it: "should validate API timestamps and dates"
request:
jsonrpc: "2.0"
id: "api-dates"
method: "tools/call"
params:
name: "get_user_activity"
arguments:
userId: "12345"
expect:
response:
jsonrpc: "2.0"
id: "api-dates"
result:
# Recent activity should be within reasonable time
lastSeen: "match:dateAge:1d"
lastLogin: "match:dateAge:30d"
# Registration should be after service launch
registeredAt: "match:dateAfter:2020-01-01"
# Account shouldn't expire too soon
expiresAt: "match:dateAfter:2024-12-31"
# Validate specific date formats
created: "match:dateFormat:iso"
lastUpdate: "match:dateValid"
# Ensure no invalid dates
suspendedAt: "match:not:dateValid" # Should be null/invalid
# File system timestamps
- it: "should validate file timestamps"
request:
jsonrpc: "2.0"
id: "file-info"
method: "tools/call"
params:
name: "get_file_info"
arguments:
path: "/data/logs/app.log"
expect:
response:
result:
# File should be recently modified
lastModified: "match:dateAge:1d"
# Creation time should be valid
createdAt: "match:dateValid"
# Access time should be recent
lastAccessed: "match:dateAge:1h"
# Backup timestamp should be older than 1 day
lastBackup: "match:not:dateAge:1d"
# Event scheduling validation
- it: "should validate event scheduling"
request:
jsonrpc: "2.0"
id: "schedule"
method: "tools/call"
params:
name: "schedule_event"
arguments:
title: "Team Meeting"
startTime: "2024-01-15T10:00:00Z"
expect:
response:
result:
# Event should be scheduled for future
scheduledFor: "match:dateAfter:2023-12-31"
# Should be within reasonable future range
scheduledFor: "match:dateBefore:2025-12-31"
# Combined: should be in 2024
scheduledFor: "match:dateBetween:2024-01-01:2024-12-31"
# Created timestamp should be very recent
createdAt: "match:dateAge:1m"
# Should have proper ISO format
scheduledFor: "match:dateFormat:iso"Best Practices
✅ Do
- Use
dateValidfirst to ensure you have valid dates - Use
dateAgefor testing recent timestamps - Use
dateFormatwhen format consistency is important - Combine patterns with negation for comprehensive validation
- Use reasonable time ranges for
dateAgepatterns
❌ Don't
- Don't use very short age durations (like "1ms") in CI environments
- Don't forget timezone considerations with exact date matching
- Don't use
dateEqualsfor dynamic timestamps - Don't assume all date strings will parse correctly
- Don't use
dateAgefor fixed historical dates