Skip to content

Unexpected false-positive case when validating January 1st, Year 1 (01-01-0001) #180

@emfloyd2

Description

@emfloyd2

Hello,

We ran into an unexpected issue with our Ozzo validation code (which was allowing January 1st, Year 1 to bypass our date validation).

Please see snippet below - is this a case of user error, or bug?

package main

import (
	"fmt"
	ozzo_validation "github.com/go-ozzo/ozzo-validation/v4"
	"time"
)

func main() {
	// This date shouldn't pass validation! But it does >_<
	//
	// dob in this case is less than minDob
	dob := time.Date(1, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
	minDob := ozzo_validation.Min(time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC))
	if err := ozzo_validation.Validate(
		dob,
		minDob,
	); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("No failures!")
	}

}

It appears to be specific to a dob value of time.Date(1, time.Month(1), 1, 0, 0, 0, 0, time.UTC)

If we add at least one nanosecond to DOB value of January 1st, Year 1 - Ozzo Validation correctly rejects invalid date

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions