-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom timestamp format #325
Comments
@ryan-ju we already support the timestamp with datetime offset, does this fit for you? |
Sorry to jump on the back of this, is there a way, using {{$datetime}} that we can specify the format of the output? Currently, if I use
|
It would be nice if we could do the following:
To generic a date 10 days in the future with a custom format. But as far as I can see that isn't supported. |
@cmjchrisjones can you confirm that the |
Hi @Huachao, indeed It would, however, be nice we could choose the format of the output for this, for example an API I'm trying to call will only accept a date rather than a timestamp, and the date format needs to be in the |
@cmjchrisjones I still want to know how can you find out that the |
@Huachao in the API I'm calling (which is private, not public so I can't share) its returning an error I was also doing a bit of research and stumbled across this, as some further rationale: point 5 here, which says that you shouldn't use time if you don't need it. |
@cmjchrisjones can you try to replace the datetime variable with the following text |
@Huachao as requested, tried sending in |
@cmjchrisjones from the error message we can find out that the datetime variable doesn't behave incorrectly, since the string you replaced with is the actual format that datetime variable generated. So the error message of your internal api is not defined quite well, BTW you should try to figure out what's the expected date time format, I guess your api doesn't allow the time part, only wants the date part 😉 |
Indeed, the expected format of our API is |
@cmjchrisjones totally agree, it's very useful for some cases |
I can raise a proper PR later, but I'm thinking the following changes will do it inside Replace line 99: return { value: type === 'rfc1123' ? date.toString() : date.toISOString() }; With: if (type === 'rfc1123') {
return { value: date.toString() };
} else if (type === 'iso8601') {
return { value: date.toISOString() };
} else {
return { value: date.format(type) };
} We'll then have to expand the regex a little bit to allow for custom formats. So: private readonly datetimeRegex: RegExp = new RegExp(`\\${Constants.DateTimeVariableName}\\s(rfc1123|iso8601)(?:\\s(\\-?\\d+)\\s(y|Q|M|w|d|h|m|s|ms))?`); Becomes: private readonly datetimeRegex: RegExp = new RegExp(`\\${Constants.DateTimeVariableName}\\s(.*)(?:\\s(\\-?\\d+)\\s(y|Q|M|w|d|h|m|s|ms))?`); I'll need to get my local version running to verify the changes, but @Huachao are these changes you'd accept in a PR? |
@connelhooley I will be very happy that you can create a PR for this feature |
@ryan-ju @cmjchrisjones with the weird PR from @connelhooley , you could expect to specify custom datetime format in next release. @connelhooley thanks, great work. |
@ryan-ju @cmjchrisjones you can experience this feature in latest version 0.21.3 with the fantastic PR from @connelhooley |
It would be great to allow the user to specify a timestamp formatter, maybe using the moment.js standard.
This will also allow the user to get parts of the timestamp, like the hour, the minutes, etc.
The text was updated successfully, but these errors were encountered: