Hey all, I’m trying to do a timestamp matcher, and...
# pact-js
w
Hey all, I’m trying to do a timestamp matcher, and my timestamp looks like
2023-01-05T10:38:01.611240928Z
, and the pact-js docs require a format string to match against in java simple date format. I’m currently using the format string
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
Where I believe SSS is just meant to represent milliseconds in general. However this returns an error from the verifier that reads
Error(Nom("171690Z", Tag))
. If I update the format string to include 9 S’s, to represent the amount of milliseconds we return in the response, I then get the error
Error(InvalidMillisecond("294910091"))
. Does anyone have any idea how I could alter my format string to get it working? To add, it seems like java SimpleDateTime doesn’t handle nanoseconds, so I’m wondering if my next best solution is to just write a regex for it instead.
t
I don’t think your timestamp matches that format string.
Where I believe SSS is just meant to represent milliseconds in general.
That’s my understanding too. However, your string seems to say 611240928 milliseconds, I think? That doesn’t match
SSS
, as it’s not in the range 0-999.
If I update the format string to include 9 S’s, to represent the amount of milliseconds we return in the response
A millisecond is a thousandth of a second. 611,240,928 milliseconds is nearly a week of time.
A simpler example: You wouldn’t have
HH:mm:ss.SSS
format any time as
12:00:00.1500
, because that would more correctly be formatted as
12:00:01.500
If your server really is emitting nanoseconds, I think you can use
HH:mm:ss.nnnnnnnnn
Also, if you have the time, it might be worth opening up an issue on https://github.com/pact-foundation/pact-js/issues about this error message. It’s certainly not helpful 😕
w
Hey Timothy, apologies for the delayed response, but thanks a lot for your response! It turns out your suggestion for using nanoseconds as
nnnnnnnnn
was exactly what was needed! Slightly frustrating that that Java documentation didn’t mention this, and that all the stackoverflow questions I saw said it wasn’t supported or something. I guess in retrospect the error does sort of make sense. I’m not exactly sure what else I’d expect Pact to respond with tbf, it’s expecting milliseconds based on the format string I gave it, and the bit at the end certainly wasn’t in milliseconds 🤔
🙌 1
t
Awesome! Glad you got it sorted