const duration = Duration.days(14)
const stringDuration = duration.toIsoString()
stringDuration is `P14D`
stringDuration is `PT14D`
Explanation of my use case
I am creating a Dashboard for my service using CDK. I would like the dashboard to have a time range like:
start time: ~today - 14 days
end time: ~today
I know I can do this by specifying: start: "-P14D"
However I would like to use Duration instead of a string. Something like:
const duration = Duration.days(14)
....
start: "-" + duration.toIsoString()
This is not working because duration.toIsoString() prints PT14D and not P14D .
This is :bug: Bug Report
Yeah @irborrero's absolutely right... I think I made a bug when I coded this up.
The T in the ISO8601 periods is a token that helps disambiguate the M marker (Months versus Minutes).
From this perspective, the T must be on the right of Days / left of Hours as it must sit between the day and time parts (and it is not needed if there is no time part, only a day part).
Thanks a lot for fixing this! I am quite new to CDK dev process, are you going to merge this into the older CDK versions as well?
Thanks a lot for fixing this! I am quite new to CDK dev process, are you going to merge this into the older CDK versions as well?
No, we don't modify existing released versions. You will have to upgrade your CDK version to one that contains the change (in this case, 1.61.0 or later) to get the fix.