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

Bug report: Valid ISO date notation results in error #3372

Closed
milanholemans opened this issue Jun 1, 2022 · 4 comments
Closed

Bug report: Valid ISO date notation results in error #3372

milanholemans opened this issue Jun 1, 2022 · 4 comments
Assignees
Milestone

Comments

@milanholemans
Copy link
Contributor

Description

When I'm using the planner task add command with --startDateTime option in PowerShell, I always get following error:

Error: The startDateTime is not a valid ISO date string

I'm using PowerShell, passing startDateTime like this:

m365 planner task add --planId $planId --title "Test" --startDateTime $date.ToString("o")

Using .ToString("o") is a proper way to retrieve an ISO string in PowerShell/C#. The docs are stating this is a valid ISO 8601 format.
image

This outputs the date in following format: 2021-12-16T18:28:48.6964197Z.
When I look at the code you can see that only 3 milliseconds digits are considered valid.

isValidISODateTime(dateTime: string): boolean {
const withMilliSecsPattern: RegExp = new RegExp(
/^[0-9]{4}-((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(02)-(0[1-9]|[12][0-9]))T(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])\.[0-9]{3}Z$/);
if (withMilliSecsPattern.test(dateTime)) {
return true;
}

This is the reason why the command results in an error message. An ISO string with 7 milliseconds digits is considered as invalid. This shouldn't be the case, an ISO string with 7 milliseconds digits is valid. After changing the code, it works perfectly.

image

As you can see, the result output has 7 milliseconds digits as well for createdDateTime.

Apart from that, when you check the docs of this command, you can see that the options --startDateTime and --endDateTime show an example of a date with 7 milliseconds digits. So when you use the examples from the docs, you'll receive an error message saying the date is invalid.

image

image

Steps to reproduce

Use any command with a date validation e.g. planner task add and specify a date string with 7 milliseconds digits.

Example:

m365 planner task add --planId "Isp_70BV1kOJ6rilI8NPi5cAHFre" --title "test" --bucketName "To do" --startDateTime "2021-12-16T18:28:48.6964197Z"

Expected results

The command should accept the input and execute.

Actual results

Error: The startDateTime is not a valid ISO date string

Diagnostics

No response

CLI for Microsoft 365 version

v5.3.0

nodejs version

v16.11.1

Operating system (environment)

Windows

Shell

Windows PowerShell

cli doctor

No response

Additional Info

I suggest that we add an extra validation rule so both date strings with 3 and 7 milliseconds digits are valid.

@garrytrinder
Copy link
Member

Good catch @milanholemans 👏

I agree we should update our implementation as you have suggested.

Would you like to take this?

@milanholemans
Copy link
Contributor Author

milanholemans commented Jun 3, 2022

Would you like to take this?

Yes please ☺️

@garrytrinder
Copy link
Member

Awesome, its all yours 👍

Thank you ❤️

@martinlingstuyl
Copy link
Contributor

Sharp eyes @milanholemans!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants