@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
"{{$datetime iso8601 10 d}}", this returns 17/05/2019 15:03:38, however, I would like to get this so it follows the yyyy-MM-dd format, I've tried {{$datetime iso8601 10 d d-m-y}} and variations on that, however don't seem to be able to get it to work?
It would be nice if we could do the following:
"{{$datetime yyy-MM-dd 10 d}}"
To generic a date 10 days in the future with a custom format. But as far as I can see that isn't supported.
"{{$datetime iso8601 10 d}}", this returns17/05/2019 15:03:38
@cmjchrisjones can you confirm that the {{$datetime iso8601 10 d}} returns 17/05/2019 15:03:38, in my local test, this returns 2019-05-18T02:00:44.368Z
Hi @Huachao, indeed {{$datetime iso8601 10 d}} does return a date that is 10 days further from now, however it is in the format of dd/MM/yyyy hh:mm:ss.
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 yyyy-MM-dd format without any time information.
@cmjchrisjones I still want to know how can you find out that the {{$datetime iso8601 10 d}} returns the date time in the format of dd/MM/yyyy hh:mm:ss. Thanks
@Huachao in the API I'm calling (which is private, not public so I can't share) its returning an error "message": "Supplied value could not be accepted. Supplied date '18/05/2019 09:34:21' is invalid, ensure to supply in yyyy-MM-dd format. when supplying "{{$datetime iso8601 10 d}}" as the value, this message is coming from an internal API.
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 2019-05-18T02:00:44.368Z and check the response of your internal api?
@Huachao as requested, tried sending in
{"value": "2019-05-18T02:00:44.368Z"} as requested, still the same error:
{
"message": "Supplied value could not be accepted. Supplied date '18/05/2019 02:00:44' is invalid, ensure to supply in yyyy-MM-dd format."
}
@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 :wink:
@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 yyyy-MM-dd so isn't what the current implementation provides unfortunately. This would be a nice feature to be able to specify the format that gets returned from the timestamp and datetime variables if possible
@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 registerDateTimeVariable:
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:
``` ts
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
Hi @Huachao I've raised a PR: #361
I haven't worked on a VS Code extension before so I haven't ran my changes. Is there a good guide anywhere for me to get the code running on my machine? If not would it be possible for you to run my branch and test it when you have time?
@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