bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Support datetime function

Open satyavel opened this issue 6 years ago • 10 comments

Per Tao and Daniel it be useful if ARM Template and Bicep can provide a datetime function to convert to Unix datetime format?

satyavel avatar Oct 08 '20 15:10 satyavel

That's a good idea. We should do both directions (to and from unix timestamp).

majastrz avatar Oct 08 '20 17:10 majastrz

This would be really useful for setting a secret expiration.

cataggar avatar Sep 10 '21 18:09 cataggar

This would be really useful for setting a secret expiration.

Exactly! This should be implemented in bicep at least.

n-pedersen avatar Mar 22 '22 19:03 n-pedersen

For me, it would be sufficient enough if there was a toUnix() function and a now() function with addDays or something. This way you could do toUnix(now('days', 30)) and set the expiration date of a KV Secret to 30 days from now.

I would not mind if the calculated date represents 'transpile' time and not nessecarily execution time.

nikneem avatar Apr 28 '22 09:04 nikneem

We recently added dateTimeFromEpoch and dateTimeToEpoch functions in v0.5.6. Do these help you accomplish what you are looking for?

cc @bmoore-msft

alex-frankel avatar Apr 28 '22 23:04 alex-frankel

They are not yet documented unfortunately so people can know about them only if they follow some PRs.

slavizh avatar Apr 29 '22 07:04 slavizh

e not yet documented unfortunately so people can know about them only if they follow some PRs.

I will try this today, but it sure looks like a solution at first glance

nikneem avatar Apr 29 '22 07:04 nikneem

This works like a charm and totally solves my problem:

param now string = utcNow()
var expiryDate = dateTimeAdd(now, 'P14D')
resource keyVaultSecrets 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
  name: 'secretName'
  parent: keyVault
  properties: {
    value: superSecretValue
    attributes: {
      exp: dateTimeToEpoch(expiryDate)
    }
  }
}

nikneem avatar Apr 29 '22 08:04 nikneem

Thanks @nikneem for testing. Will do the same, awesome, this makes our life so much easier! Good job team!

isehuetdk avatar Apr 29 '22 10:04 isehuetdk

Closing as this looks resolved and +1 @nikneem -- thank you for testing. I also created a separate task to get the functions documented - thanks @stansz.

alex-frankel avatar Apr 29 '22 16:04 alex-frankel