vTime

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Time Validators

Index

Constants

View Source
const (
	Type = "time"

	ParseErrorFormat     = "Unable to parse time."
	MandatoryErrorFormat = "Must not be left empty."
	MinErrorFormat       = "Cannot be less than '{{.min}}'."
	MaxErrorFormat       = "Cannot be more than '{{.max}}'."
	BetweenErrorFormat   = "Must be between '{{.min}}' and '{{.max}}'."
)

Variables

This section is empty.

Functions

func Must

func Must(value time.Time, err error) time.Time

func Validate

func Validate(value time.Time, rules ...ValidationRule) (time.Time, error)

func ValidateFromString

func ValidateFromString(src string, location *time.Location, rules ...ValidationRule) (time.Time, error)

func ValidateFromStringDateOnly

func ValidateFromStringDateOnly(src string, location *time.Location, rules ...ValidationRule) (time.Time, error)

func ValidateFromStringTimeOnly

func ValidateFromStringTimeOnly(src string, location *time.Location, rules ...ValidationRule) (time.Time, error)

Types

type ValidationRule

type ValidationRule func(format *string, src *string, value *time.Time, hasError bool) error

func Between

func Between(min, max time.Time) ValidationRule

Between Minimum and Maximum value

func Mandatory

func Mandatory() ValidationRule

Make sure value is set, if not set the rule return a validation error

Note: will only work while validating from string

func Max

func Max(max time.Time) ValidationRule

Maximum value, returns error if more than max.

func Min

func Min(min time.Time) ValidationRule

Minimum value, returns error if less than min.

func OverrideErrorMsg

func OverrideErrorMsg(validationError vError.ValidationError, rules ...ValidationRule) ValidationRule

Override Error Message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL