conv

package
v1.1.62 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 10 Imported by: 3

Documentation

Overview

Package conv provides handy conversion functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaysSince added in v1.0.82

func DaysSince(t time.Time) int

func DefaultMaxFloat added in v1.0.84

func DefaultMaxFloat(val, def, max float64) float64

func DefaultMaxInt added in v1.0.84

func DefaultMaxInt(val, def, max int) int

DefaultMaxInt returns the default if val is < 0, max if val is > max.

func DiffInDays added in v1.0.82

func DiffInDays(a, b time.Time) int

func Env added in v1.1.5

func Env(key string) string

func FToC

func FToC(f float64) float64

FToC converts fahrenheit to celsius

func FeetToMeters

func FeetToMeters(f float64) float64

FeetToMeters converts feet to meters

func FirstNonEmptyString added in v1.1.3

func FirstNonEmptyString(list ...string) string

func FirstNonZeroFloat added in v1.1.34

func FirstNonZeroFloat(list ...float64) float64

func FirstNonZeroInt added in v1.1.4

func FirstNonZeroInt(list ...int) int

func FirstPositiveFloat added in v1.1.34

func FirstPositiveFloat(list ...float64) float64

func FirstPositiveInt added in v1.1.34

func FirstPositiveInt(list ...int) int

func FuzzInt added in v1.1.39

func FuzzInt(input int, min, max int) int

FuzzInt adds or subtracts a certain percentage from the input. Ex: FuzzInt(100, 1, 100) will have an output range between 0 and 100 Ex: FuzzInt(100, 1, 10) will have an output range between 90 and 110, and will add/remove at least 1% Ex: FuzzInt(100, 8, 10) will have an output range between 90 and 110, and will add/remove at least 8%

func IsNil added in v1.1.18

func IsNil(i interface{}) (isNil bool)

Returns true if the given interface is nil.

func MaxFloat added in v1.0.82

func MaxFloat(a, b float64) float64

func MaxInt added in v1.0.82

func MaxInt(a, b int) int

MaxInt returns the larger of a or b

func MilesToKm

func MilesToKm(m float64) float64

MilesToKm converts miles to kilometers

func MinFloat added in v1.0.84

func MinFloat(a, b float64) float64

MinFloat returns the larger of a or b

func MinInt added in v1.0.84

func MinInt(a, b int) int

MaxInt returns the larger of a or b

func MinMaxFloat added in v1.0.82

func MinMaxFloat(val, min, max float64) float64

func MinMaxInt added in v1.0.82

func MinMaxInt(val, min, max int) int

MinMaxInt returns the min if val is < min, max if val is > max.

func ParseTime added in v1.0.13

func ParseTime(input string) (time.Time, error)

ParseTime attempts to extract a valid time.Time from an input string. We prefer RFC3999. Fallback should match MSSQL's CURRENT_TIMESTAMP.

func QuoteString added in v1.0.86

func QuoteString(s string) string

QuoteString adds quotes to a string.

func RatioPercent added in v1.0.82

func RatioPercent(a, b float64) float64

func RelativeTime

func RelativeTime(dur time.Duration) string

RelativeTime takes a time.Duration and returns the largest denomination relative time. eg. 1y for a duration over 400 days.

func Round

func Round(num float64) int

Round a floating point number to the nearest integer. -0.5 becomes -1, 0.5 becomes 1.

func ToFixed

func ToFixed(num float64, precision int) float64

ToFixed will set a fixed precision on a float.

func ZeroIfNilFloat added in v1.1.37

func ZeroIfNilFloat(in *float64) float64

func ZeroIfNilInt added in v1.1.37

func ZeroIfNilInt(in *int) int

Types

This section is empty.

Jump to

Keyboard shortcuts

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