I will appreciate if someone can help me understand how to convert string context variables into date/time format and vice versa. Let me describe the use case as follows.
The request.http contains a query parameter "from-date" in the format of yyyy-mm-ddThh:mm:ss-hhmm (e.g. 2017-05-01T00:00:00-0400). I need to first convert it from string to date/time and then to get corresponding UTC date/time. From UTC date/time back to string and perform a query on a back end database which stores UTC date/time as string. In the output I need to covert the date/time from UTC back to local time zone as per the from-date request.
For string to date/time, I tried the following assertion. However, this assertion fails.
Alternative formats available from format: drop down like auto didn't work either.
Please share what assertion to use for string -> date and time.
what assertion to use to convert date and time -> string.
Thank you very much
I've attached a policy that will take the value you provided as the parameter then pull out the offset to be used in the set context variable and the output variable is automatically in UTC format.
Director, CA Support
The policy helps to get the offset out. But the date conversion returns in a wrong date. Why would the response be offset by several days.
Original Date String: 2017-05-01T00:00:00-0400 Modified Date that is in UTC format: 2017-04-14T08:00:00.000Z
I've just reloaded the policy above with some modification to handle the time better.
There is subtle change needed. The most recent version incorrectly deducts the time if negative time offset is provided.
Eastern DST 2017-05-09T11:50:00-0400
Corresponding UTC 2017-05-09T03:50:00+0000
However, following is the result generated by the policy.
Original Date String: 2017-05-09T11:50:00-0400 Eastern Daylight Saving time Modified Date that is in UTC format: 2017-05-09T07:50:00.000Z
Okay one more time. Original updated with the change.
Not sure the "Set Context Variable" does correct computation. Because for the following input, the output should have the time as 18:10:00. Instead it computes the morning 06:10:00 UTC.
Original Date String: 2017-05-09T11:10:00-0700 Modified Date that is in UTC format: 2017-05-09 06:10:00
I've retest the policy that I uploaded to the community post and it does provide the correct value if you use the string you set it should show 04:10 and if you switch it to +0700 then it shows at 18:10. Please try to download it again and reload the policy.
Did the final policy work for you?
Yes it did. Thank you very much.