Skip to content
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

A formatted string in Date-Time in ISO-8601 format without time zone suffix is automatically converted to ISO-8601 format with time zone #15697

Open
mtessier84 opened this issue Nov 28, 2024 · 4 comments
Labels
intermediate language Related to the intermediate language Needs: Upvote This issue requires more votes to be considered

Comments

@mtessier84
Copy link

Bicep version
0.31.92

Describe the bug
A formatted string in Date-Time in ISO-8601 format without time zone suffix is automatically converted to ISO-8601 format with time zone suffix: dateTimeAdd(dateTime, 'P1D', 'yyyy-MM-ddTHH:mm:ss') is automatically converted to "2024-11-29T21:09:59Z".

The issue is that not all ARM properties take Date-Time in ISO-8601 format with time zone. For example,
Microsoft.AlertsManagement/actionRules has a property called effectiveFrom that requires a Date-Time in ISO-8601 format without timezone suffix. and a property for the time zone itself. The deployment fails if I pass 2024-11-29T21:09:59Z to effectiveFrom.

https://learn.microsoft.com/en-us/azure/templates/microsoft.alertsmanagement/actionrules?pivots=deployment-language-bicep#schedule

To Reproduce

param dateTime string = utcNow()
var startTime = dateTimeAdd(dateTime, 'P1D', 'yyyy-MM-ddTHH:mm:ss')
var startTime2 = '2024-11-29T21:15:04'
output result string = startTime
output result2 string = startTime2
Parameters              : 
                          Name             Type                       Value     
                          ===============  =========================  ==========
                          dateTime         String                     "20241128T212109Z"
                          
Outputs                 : 
                          Name             Type                       Value     
                          ===============  =========================  ==========
                          result           String                     "2024-11-29T21:21:09Z"
                          result2          String                     "2024-11-29T21:15:04Z"

Additional context
In the case of Action Rules, it is fair to require the current UTC time + X Hours/Minutes to suppress Alerts as part of a maintenance. For this reason, the effective start time must be dynamically generated.

Potential Workaround
I was not able to get rid of the Z at the end of the string. I tried many different ways like substring, replace, concat, format, etc... but the bicep engine seems to detect the date format and automatically convert to Date-Time in ISO-8601 format with time zone

@github-project-automation github-project-automation bot moved this to Todo in Bicep Nov 28, 2024
@stephaniezyen stephaniezyen added the intermediate language Related to the intermediate language label Dec 4, 2024
@stephaniezyen stephaniezyen added Needs: Upvote This issue requires more votes to be considered and removed Needs: Triage 🔍 labels Dec 11, 2024
@jeskew
Copy link
Contributor

jeskew commented Dec 12, 2024

This problem is unfortunately inherent to the JSON library used by ARM. While the library does allow this behavior to be disabled, it's likely that changing the behavior now would cause other template deployments to break. And since this particular transformation is applied very early in the JSON reading process, we can't make it customizable via anything specified in the request body (since the request body is JSON).

@jeskew
Copy link
Contributor

jeskew commented Dec 12, 2024

I am a bit confused as to why the timezone suffix is not desired in this case, since from the docs it sounds like action rules should expect a specific instant in time.

@mtessier84
Copy link
Author

@jeskew In the link I provided, it says:
effectiveFrom | Scheduling effective from time. Date-Time in ISO-8601 format without timezone suffix.
effectiveUntil | Scheduling effective until time. Date-Time in ISO-8601 format without timezone suffix.

The reason is because the time zone is passed independantly of the date time format in the timeZone property

@jeskew
Copy link
Contributor

jeskew commented Dec 12, 2024

The reason is because the time zone is passed independantly of the date time format in the timeZone property

Makes sense, though I'm surprised that made it through the API review process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
intermediate language Related to the intermediate language Needs: Upvote This issue requires more votes to be considered
Projects
Status: Todo
Development

No branches or pull requests

3 participants