Support automatic detection of Unix timestamp strings in date/time matcher input
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.4k
- Forks
- 1.5k
- Avg merge
- 13h 10m
- Merged PRs (30d)
- 16
Description
Proposal
Reason:
Currently, WireMock’s date/time matching (equalToDateTime) requires the user to explicitly specify actualFormat("unix") to parse Unix timestamp strings. If no format is specified, Unix timestamps are not automatically recognized and parsed but it is working for other formats like . This can cause confusion or extra implementation steps, especially when supporting APIs that may supply timestamps in multiple formats.
Use Case:
I have an API that accepts various date/time formats, including ISO-8601 strings and Unix timestamps (in seconds). When using WireMock for testing and validation, I want to seamlessly match incoming requests or responses based on their date/time values, regardless of whether they are formatted as ISO-8601 strings or Unix timestamps. Currently, this requires additional logic to specify the format or to pre-process inputs.
How to Reproduce (JSON Example for GET request):
-
Create a stub mapping with a
nowexpectation in the query parameter (noactualFormatspecified):{ "request": { "method": "GET", "urlPath": "/my-api", "queryParameters": { "timestamp": { "equalToDateTime": "now" } } }, "response": { "status": 200 } } -
Send a GET request with a Unix timestamp in the query:
GET /my-api?timestamp=1750908548This Unix timestamp represents a valid date/time, but the stub will not match the request because WireMock doesn't automatically recognize Unix timestamps unless
"actualFormat": "unix"is specified. -
Current workaround (required for matching):
{ "request": { "method": "GET", "urlPath": "/my-api", "queryParameters": { "timestamp": { "equalToDateTime": "now", "actualFormat": "unix" } } }, "response": { "status": 200 } }
Desired behavior:
WireMock should automatically recognize and parse Unix timestamp strings (like 1750908548) as valid date/time values when no actualFormat is given, falling back to other formats only if Unix parsing fails.
Proposed Enhancement:
Enhance the date/time parsing logic to automatically detect and parse Unix timestamp strings (e.g., strings containing only digits, optionally up to 10 or 13 digits for seconds or milliseconds since epoch) when no explicit actualFormat is provided. If parsing as Unix timestamp fails, fallback to the existing parsing order.
Also we can have a feature where multiple timerange can be added in actualFormat to support dynamic timeranges.
Contribution:
I want to contribute by:
- Updating the parsing logic in
AbstractDateTimePatternto attempt automatic Unix timestamp detection and parsing if no format is specified. It will allow us to match with larger timestring format including previous one like iso string etc.
References
Code Reference:
- AbstractDateTimePattern.java#L60-L73: Where the custom
actualFormatis handled. - AbstractDateTimePattern.java#L277-L303: Where parsing is attempted, including custom formats.
- AbstractDateTimePattern.java#L136-L187: The main match logic that ties together parsing and value matching.
- WireMock Documentation: DateTime Matching: Official docs on date/time matching and usage of
actualFormat.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with wiremock-common/src/main/java/com/github/tomakehurst/wiremock/matching/AbstractDateTimePattern.java, especially the actualFormat handling and parsing sections referenced in the issue. Review the DateTime Matching documentation and existing matcher behavior before deciding how Unix seconds and milliseconds should be detected and how fallback works. Done means a numeric Unix timestamp matches without actualFormat while existing explicit and other formats continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100