Categorygithub.com/bjbigler/utils
modulepackage
0.0.0-20240801033401-fce07f1a8c16
Repository: https://github.com/bjbigler/utils.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# Functions

AcademicYear returns the academic year of *dte* Assumes a July 1 beginning year.
AcademicYears returns a slice of ints from *start* to dte.
AcademicYearsAgo returns now.Year - n + 1 to account for full academic years.
AcademicYearView returns 2019-20 when given 2020.
Alpha returns A-Z, capitalized.
AlphaIndex returns the 0-based index where a letter appears in the English alphabet.
AppendIfMissing appends a string to a string slice if not already there.
AppendIfMissingInt64 appends an int64 to a int64 slice if not already there.
BeginningOfDay returns 12AM of the supplied time.
BeginningOfHour returns :00 of the supplied time.
Caller returns the name of the calling function.
Conjoin joins a string with commas and the conjunction,e.g., ["bill", "sue", "jill"] => "bill, sue, and jill".
CreateFolder ...
CurrentAcademicYear returns Now()'s academic year.
DateEqual compares date equality regardless of the time.
DaysIn returns the number of days in a month for a given year.
DownloadFromURL ...
DownloadImage downloads the url to the destination path.
EasternTime returns current Eastern Time (Princeton), including DST as appropriate.
EmojiClockFace returns the clock face for times from 8:00 through 21:30 in half-hour increments.
EndOfAcademicYear is.
EndOfDay returns 12AM of the supplied time.
FirstDayOfISOWeek returns time.Time when fed a year and week.
FormatCommas adds commas to a number.
GenerateRandom returns a 7-digit pseudorandom number; NOTE: PLEASE SEED THE RANDOM GENERATOR BEFORE CALLING.
GenerateRandomAlphaNumeric ...
GenerateRandom returns a pseudorandom whole number in the provided range NOTE: PLEASE SEED THE RANDOM GENERATOR BEFORE CALLING.
GetConjunction is used to make a list human-readable with a comma and/or the supplied conjunction.
GetContent returns contents of a URL.
GetGoQueryDocumentFromFile returns goquery doc from URL.
GetGoQueryDocumentFromURL returns goquery doc from URL.
GetIDFromURL returns ID from a URL fragment, e.g.
GetImagesFromURL returns a slice of image urls, e.g.http://www.remotesite.com/img.jpg.
GetIP returns UserIP address.
GetLastPart gets the last text past the final delimiter.
GetLocationFromTZ returns location from tz unless it's blank or unless there's an error, and otherwise returns the defaultLoc.
GetMonthEnd returns the end of the month when fed, e.g., 20187 => 7/31/2018.
GetMonthEnd returns the end of the month when fed, e.g., 20187 => 7/31/2018.
GetMonthStartAndEnd returns a month's start date and end date when given a "yearMonth" string, i.e.
GetNearestWeekday returns the most recent weekday before today.
GetStringIDFromURL gets the last text past the final slash in a URL.
InFuture checks whether the provided dte is after now.
InPast checks whether the provided dte is before now.
Int64ToAmPm takes *hour* like 13 and returns 1p.
Int64ToCSV converts a list of int64s to CSV.
Int64ToString ...
IntToString ...
FromRequest return client's real public IP address from http request headers.
IsNumeric removes commas, trims spaces, and then attempts to parse as float.
IsPDF opens a file and checks whether it has a PDF signature.
IsToday determins whether supplied date is today.
IsUpperCaseWord checks if a word has all uppercase characters.
Join takes *basePath* ("http...") and joins it withpaths to form a URL.
Log string to file.
LogToStdError ...
MakeFullname concats first and last name.
MakeSliceFromRange returns a slice of integers in the range 'from'-'to' inclusive.
MakeTimeFromTimeField takes the value from an HTML time field, combines it with *date* (can be IsZero, which then uses today's date), and returns a time.Time object.
MinutesFromFloat ...
OnToBool ...
OnToInt returns 1 if on, 0 otherwise.
ParseBool ...
ParseDate is a fast parse for date []byte formatted as yyyy-mm-dd.
ParseDateMulti tries to parse the provided value using three formats: 1) yyyy-mm-dd 2) yyyy-mm-dd hh:mm:ss 3) yyyy-mm-dd hh:mm If all these produce errors, time.Time{} is returned.
ParseDateTime parses the suppied string in location America/New York.
ParseDateTime3 is a fast parse for date-time []byte formatted as yyyy-mm-dd hh:mm:ss.
ParseDateTime4 is a fast parse for date-time string formatted as yyyy-mm-dd hh:mm:ss.
ParseDateTime5 is a fast parse for date-time string formatted as yyyy-mm-dd hh:mm.
ParseDateUS tries three formats mm/dd/yyyy, m/dd/yyyy, m/d/yyyy, and mm/d/yyyy.
ParseFloat32 ...
ParseFloat64 ...
ParseInt parses *candidate* using strconv.Atoi, and returns the converted result if there is no error.
ParseInt32 parses *candidate* using strconv.ParseInt, and returns the converted result if there is no error.
ParseInt32 parses *candidate* using strconv.ParseInt, and returns the converted result if there is no error.
ParseInt64Err returns an error if parsing fails.
ParseName takes a string name as a parameter and returns a populated NameParts object */.
PathExists determines whether the path to resource exists on disk.
PrepCookieDomain removes http(s) from the institution's root URLto function as a cookie domain valuee.g., https://princeton.seminars.app -> princeton.seminars.app.
PrepForDecimalization preps string for decimalization.
PrepRedirectURL takes an http.Request to create a redirectURL back to it.
ReceiveFile ...
ReceiveNamedFile ...
RemoveItem removes a string from a slice.
RemovePunctuation ...
RemoveSpaces trims spaces around a string, and removes two+ spaces inside string.
RenderFloat ...
RenderInteger ...
ReplaceAccents replaces accented characters with close eqivalents.
Secure returns false only if the Host is localhost.
SplitSubN splits a string by length.
StringToBool returns true if "true", "1", "on", or "yes".
SumFloat64 ...
SumInt64 ...
TimeFromFloat takes a number like 13.5 and pairs it with dateVal to make a date-time value If dateVal is "nil" (time.Time{}), the func will pair hourMinute with today's date et = current time in eastern time zone.
TimeToFloat takes time (e.g., 10:30) and converts it into a float 10.5.
TimeToInt64 takes time (e.g., 10:30) and converts it into an int64, 1030.
TimeTrack should be called likedefer TimeTrack(time.Now(), "caller").
To8601Format produces a time in 8601 format for iCalendar and other functions.
ToInt64ForStorage multiplies the input number by 10^precision and returns an int64 for Datastore persist.
ToInt64Precision10ForStorage multiplies the input number by 10^10 and returns an int64 for Datastore persist.
Tokenize returns a slice of unique "words" of *minLength*from the given string *args".
TokenizeWords splits a phrase into words and returnsphrases 1 .
ToTitleCase returns the input string in Title Case.
UniqueInts returns a unique subset of the int slice provided.
UniqueStrings returns a unique subset of the string slice provided.
ValidateEmail checks email for ..
ValToBool returns true if val is "on", "true", or "1"; false for all others.
WeeksInMonth returns the number of weeks in the month given by now.
WeeksInMonth2 ...
ZeroPad64 adds a zero in front of *val*.

# Structs

NameParts represents the slotted components of a given name */.