LocalDate constructor validation not working #801

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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Show comment
Hide comment
@jskeet

jskeet Apr 26, 2017

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@jskeet

jskeet Apr 26, 2017

Member

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

Member

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