Aws-cdk: [core] Duration toIsoString() not following ISO Standard

Created on 22 Aug 2020  路  3Comments  路  Source: aws/aws-cdk

Reproduction Steps

const duration = Duration.days(14)
const stringDuration = duration.toIsoString()

What did you expect to happen?

stringDuration is `P14D`

What actually happened?

 stringDuration is `PT14D`

Environment

  • CDK CLI Version: 1.32.2
  • Node.js Version: 12.18.2
  • OS: macOS Catalina
  • Language: TypeScript

Other

Link to docu

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

@aws-cdcore bug needs-triage

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kent1 picture Kent1  路  3Comments

sudoforge picture sudoforge  路  3Comments

peterdeme picture peterdeme  路  3Comments

eladb picture eladb  路  3Comments

ababra picture ababra  路  3Comments