wiremock / wiremock/wiremock

Support automatic detection of Unix timestamp strings in date/time matcher input

Open
#3,085 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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):

  1. Create a stub mapping with a now expectation in the query parameter (no actualFormat specified):

    {
      "request": {
        "method": "GET",
        "urlPath": "/my-api",
        "queryParameters": {
          "timestamp": {
            "equalToDateTime": "now"
          }
        }
      },
      "response": {
        "status": 200
      }
    }
    
  2. Send a GET request with a Unix timestamp in the query:

    GET /my-api?timestamp=1750908548
    

    This 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.

  3. 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 AbstractDateTimePattern to 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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.