formatHelper

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidSexLengthError          = errors.New("Sex should be one character only")
	InvalidSexValue                = errors.New("Sex can only be <m|f|d>")
	InvalidEmailAddressFormatError = errors.New("Email address format is invalid")
	EmailAddressContainsNameError  = errors.New("Email address should not contain the name")
	EmailAddressInvalidTldError    = errors.New("Email address TLD is invalid")
	DateFormatInvalidError         = errors.New("Date format is invalid")
	DateInFutureError              = errors.New("Date is in the future")
	EmptyStringError               = errors.New("Empty String")
)

Functions

func FormatDate

func FormatDate(date string) (string, error)

FormatDate converts a date string from RFC3339 (e.g., "2003-01-17T00:00:00Z") to the format "YYYY-MM-DD".

func FormatToCentimeters

func FormatToCentimeters(input string) (int, error)

FormatToCentimeters converts inputs like "2.40 m" or "800 m" into centimeters as string.

func FormatToMilliseconds

func FormatToMilliseconds(input string) (int, error)

FormatToMilliseconds converts a time string like "03:25" or "1:02:30" into milliseconds.

func IsBefore

func IsBefore(date1 string, date2 string) error

func IsDate

func IsDate(date string) error

IsDate checks if the given date is in the required format (YYYY-MM-DD). Throws: DateFormatInvalidError

func IsDuration

func IsDuration(s string) error

IsDuration checks whether s is a valid duration in the format S, SS, M:SS or MM:SS. Seconds must be 0-59; any non-negative number can be used for minutes, but only 1 or 2 digits in the string.

func IsEmail

func IsEmail(email string) error

IsEmail validates the email address using the mail.ParseAddress function and additionally checks if it has a valid TLD to block local addresses

func IsEmpty

func IsEmpty(bodyPart string) error

func IsFuture

func IsFuture(date string) error

IsFuture checks if the given date is in the future and throws an error if it is.

func IsSex

func IsSex(sex string) error

IsSex checks if the length is one character and one of the allowed values

func NormalizeResult

func NormalizeResult(raw string, unit string) (int, error)

NormalizeResult standardizes the result into ms or cm depending on the unit. For "second" and "minute", accepts S, SS, M:SS or MM:SS and converts to milliseconds.

Types

This section is empty.

Jump to

Keyboard shortcuts

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