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

LocalDate constructor validation not working #801

Closed
jkonecki opened this issue Apr 26, 2017 · 2 comments
Closed

LocalDate constructor validation not working #801

jkonecki opened this issue Apr 26, 2017 · 2 comments
Assignees
Labels
bug
Milestone

Comments

@jkonecki
Copy link

@jkonecki jkonecki commented Apr 26, 2017

I've noticed a bug in NodaTime 2.0 LocalDate constructor - parameter validation doesn't seem to be working. It was working as expected in version 1.3.

Example:

var date = new LocalDate(2001, 1, -1);

Expected result:
An ArgumentOutOfRangeException should be thrown as described in documentation:

<exception cref="ArgumentOutOfRangeException">The parameters do not form a valid date.</exception>

Actual result:

A LocalDate instance is created and can be used:

            var date = new LocalDate(2001, 1, -1);
            var year = date.Year; // value: 0
            var month = date.Month; // value: 32
            var day = date.Day;  // value: 63

An ArgumentOutOfRangeException is thrown from ToString() method.

@jskeet jskeet self-assigned this Apr 26, 2017
@jskeet jskeet added this to the 2.0.1 milestone Apr 26, 2017
@jskeet
Copy link
Member

@jskeet jskeet commented Apr 26, 2017

Eek, thank you. Very surprising! (Surprises me that we don't have tests, either. That must change...) Will fix for 2.0.1.

@jskeet
Copy link
Member

@jskeet jskeet commented Apr 26, 2017

Ah, found it. We validate that the day-of-month isn't too high - but not that it's not < 1!

jskeet added a commit to jskeet/nodatime that referenced this issue Apr 26, 2017
@jskeet jskeet closed this in #802 Apr 26, 2017
jskeet added a commit that referenced this issue Apr 26, 2017
@malcolmr malcolmr added the bug label May 3, 2017
jskeet added a commit to jskeet/nodatime that referenced this issue May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.