Date: invalid date '1 hour'

I’m running the following command in an azure/CLI@V1 action, but it fails with date: invalid date ‘1 hour’

end=$(date -u -d “1 hour” ‘+%Y-%m-%dT%H:%MZ’)

using the ubuntu-latest image.

Is this expected? Running the same command on my laptop works just perfect (Developer comment there)

Hi @anderseide,

It turns out busybox date, it only accepts very specific time formats, not arbitrary ones.
image

For example, below is accepted:

      - name: Azure CLI script file
        uses: azure/CLI@v1
        with:
          inlineScript: |
            date -d "2020-09-25 15:30" '+%Y-%m-%dT%H:%MZ'

Fortunately it also supports (undocumentedly) the @seconds syntax, to get the time after 1hour, you can use below code:

      - name: Azure CLI script file
        uses: azure/CLI@v1
        with:
          inlineScript: |
            date -d "@$(( $(busybox date +%s) + 3600 ))" '+%Y-%m-%dT%H:%MZ'

Please check below link for the details:

Thanks

1 Like