Currently, my team is utilizing Cucumber to define our test cases within string-based feature files. Our integration tests are executed against a wiremock stub that contains date calculations such as: "{{now offset='+15 minutes'}}"
I am seeking to verify the accuracy of the date and time retrieved from the wiremock stub, ensure the correct display of this information, and confirm that the table is correctly ordered based on these dates and times.
Presently, we have our custom implementation for obtaining the current date with an offset of +/- X days. However, this method employs regex and only supports day adjustments. While I could enhance this solution to include minute calculations, I would prefer to utilize a library or standardized code snippet capable of parsing all types of date calculations. Unfortunately, my search for such a tool has been fruitless thus far, and I would appreciate any recommendations to tackle this challenge.
To provide context, here is the function currently utilized:
function stringReplaceNow(string) {
var regex = /<now:([A-Z-]+):?((\+|-)([0-9]+))?>/gi;
return string.replace(regex, function (match, format, shouldModify, modification, modAmount) {
if (modification === '+') {
return moment().add(modAmount, 'days').format(format);
} else if (modification === '-') {
return moment().subtract(modAmount, 'days').format(format);
}
return moment().format(format);
});
}
In our cucumber tests, it is applied as follows, adjusting the current date by subtracting the specified number of days:
| Name | Datetime | State |
| Johnson | <now:DD-MM-YYYY:-2> | Processing |
| Minter | <now:DD-MM-YYYY:-3> | Processing |
| Brown | <now:DD-MM-YYYY:-5> | Done |