Documentation
¶
Index ¶
- Constants
- Variables
- func AddDaysToStringDate(dateStr string, days int) string
- func AddMinutesToDateTimeString(datetimeStr string, minutes int) string
- func AddMinutesToDateTimeStringAsGoTime(datetimeStr string, minutes int) time.Time
- func ConvertDateOnlyStringToGoLangTime(s string) time.Time
- func ConvertDateTimeStringToGoLangTime(s string) time.Time
- func ConvertGoLangTimeToPBString(tt time.Time) string
- func ConvertGoLangTimeToStringWithFormat(timeObj time.Time, format string) string
- func ConvertManyTimeFormatToGoLangTime(str string) (time.Time, error)
- func ConvertTimeOnlyStringToGoLangTime(s string) time.Time
- func DateStringABeforeB(a, b string) bool
- func DurationElapsedLong(uptime time.Duration) string
- func DurationElapsedShort(uptime time.Duration) string
- func DurationHUmanReadableWithOptions(uptime time.Duration, opt HumanReadableOptions) string
- func DurationHumanReadableLong(uptime time.Duration) string
- func DurationUptimeLong(uptime time.Duration) string
- func DurationUptimeShort(uptime time.Duration) string
- func ExtractDateFromString(thedate string) string
- func ExtractDateTimeFromString(thedate string) string
- func ExtractTimeFromString(thedate string) string
- func ExtractYearFromString(thedate string) string
- func GetDaysFromDateTimeBToA(a, b time.Time) int
- func GetFirstAndLastDayOfYear(year int) (time.Time, time.Time)
- func GetFirstDayOfYear(year int) time.Time
- func GetLastDayOfYear(year int) time.Time
- func GetMinutesFromDateTimeBToA(a, b time.Time) float64
- func GetMinutesFromDateTimeStringBtoA(a, b string) float64
- func GetMinutesFromTimeStringBToA(timeStr1, timeStr2 string) float64
- func GetNumberOfWeeksInMonth(year int, month time.Month) int
- func GetRangeFromDate(calcDate string, n int) (string, string)
- func GetWeekNumberInMonth(date time.Time) int
- func IsDateStrInRange(x, a, b string) bool
- func IsTimeStringExpired(expiresAt string) bool
- func PBDateTimeStringABeforeB(a, b string) bool
- func SetDateToTimeOnlyGoLangTime(timeonly, dateToSet time.Time) time.Time
- func TimeStringFromNow(duration int) string
- type HumanReadableOptions
- type TimeConvertSetting
Constants ¶
const ( // not used DATE_ONLY TimeConvertSetting = "DateOnly" TIME_ONLY TimeConvertSetting = "TimeOnly" DATE_AND_TIME TimeConvertSetting = "DateAndTime" // FORMAT_PB_DATETIME string = "2006-01-02 15:04:05.000Z" FORMAT_PB_DATETIME string = "2006-01-02 15:04:05.999Z" FORMAT_PB_TIME string = "15:04:05.000Z" FORMAT_H_M string = "15:04" EMPTY_DATE_STRING string = "0001-01-01 00:00:0.000Z" // not sure we need this, but just in case we need to define "empty" date while variable must have value, then this is the value to denote empty date BIG_DATE_STRING string = "3000-01-01 00:00:0.000Z" // sometime we need to check if date is less than but the end-date is empty )
TODO: This was created originally for PocketBase, we need to change this to more standard format.
Variables ¶
var ( // NOTE: WARNING: IMPORTANT: PLEASE USE TimeToString before saving to PB if not it will not work! TimeToString func(time.Time) string = ConvertGoLangTimeToPBString StringToTime func(string) time.Time = ConvertDateTimeStringToGoLangTime DateStrToTime func(string) time.Time = ConvertDateOnlyStringToGoLangTime // convert "yyyy-mm-dd" to time.Time TimeStrToTime func(string) time.Time = ConvertTimeOnlyStringToGoLangTime EMPTY_DATE time.Time = TimeStrToTime(EMPTY_DATE_STRING) ParseStringnToTime func(string) (time.Time, error) = ConvertManyTimeFormatToGoLangTime )
ShortCut Only, Not really needed
Functions ¶
func AddDaysToStringDate ¶
Add days into string date, can do negative days as well to substract dateStr by days dateStr = mm/dd/yyyy and return format is the same
func AddMinutesToDateTimeString ¶
Add minutes to date-time string (PB format) and return PB format as well. Can use negative value for minutes to substract
func AddMinutesToDateTimeStringAsGoTime ¶
Add minutes to datetimeStr and return as time
func ConvertDateOnlyStringToGoLangTime ¶
Convert string to time.Time (both date and time) Only accept yyyy-mm-dd format, else return .IsZero()
func ConvertDateTimeStringToGoLangTime ¶
Convert string to time.Time (both date and time)
func ConvertGoLangTimeToPBString ¶
Convert time.Time to string using default FORMAT_PB_DATETIME format
func ConvertGoLangTimeToStringWithFormat ¶
Convert time.Time to string with format (if empty return using FORMAT_PB_DATETIME)
func ConvertManyTimeFormatToGoLangTime ¶
Convert string (time and date) to GoLangTime parseTime tries to parse a string into a time.Time using common formats.
func ConvertTimeOnlyStringToGoLangTime ¶
This is to convert string like 'hh:mm' | 'hh:mm:ss' | 'hh:mm:ss:nnnZ' format to time.Time struct
func DateStringABeforeB ¶
Compare date_only format for strings ie "2024-04-03" and "2024-04-20" then true
func DurationElapsedLong ¶
This is usually to print the elapsed time for some function or db access usually is small units, so definitely no years and all. Output: 23 milliseconds,12 microseconds,39 nanoseconds
func DurationElapsedShort ¶
This is usually to print the elapsed time for some function or db access usually is small units, so definitely no years -- until hours Output: 23ms,12µs,39ns
func DurationHUmanReadableWithOptions ¶
func DurationHUmanReadableWithOptions(uptime time.Duration, opt HumanReadableOptions) string
func DurationHumanReadableLong ¶
Default long format for duration string, prints every unit from year-to-nanoseconds Output: 2 days, 3 hours and 15 minutes
func DurationUptimeLong ¶
Default long format for Uptime duration string Output: remove the seconds and smaller
func DurationUptimeShort ¶
Default short format for Uptime duration string Output: remove the seconds and smaller 2d,20h,12m or just remove the comma as well: 2d20h12m
func ExtractDateFromString ¶
Format that from PB usually is 2006-01-02 15:04:05.999Z we only need the first 10 chars
func ExtractDateTimeFromString ¶
Format for printing only mostly
func ExtractTimeFromString ¶
format from PB to get time only
func ExtractYearFromString ¶
Format that from PB usually is 2006-01-02 15:04:05.999Z we only need the first 4 chars
func GetDaysFromDateTimeBToA ¶
get number of days between time B to time A (B - A). Except time.Time format and only dateStr
func GetFirstAndLastDayOfYear ¶
Get start and end date of the year in time.Time (UTC)
func GetLastDayOfYear ¶
func GetMinutesFromDateTimeBToA ¶
Meaning from time B --- to time A ==> meaning = B - A (if posistive means B is later, negative means B is before A)
func GetMinutesFromDateTimeStringBtoA ¶
Ignore error, accept "2024-12-03 10:23:00.000Z" format. B minus A
func GetMinutesFromTimeStringBToA ¶
Ignore error and return 0 instead. Except "10:32" and "13:20" format
func GetNumberOfWeeksInMonth ¶
============= THIS IS UTILS functions if not yet exist getNumberOfWeeksInMonth calculates the number of weeks in a month
func GetRangeFromDate ¶
Get n-days previous and n-days next from calcDate. Accept the dateOnly string Also return dateOnly format as string only, not time.Time
func GetWeekNumberInMonth ¶
getWeekNumberInMonth determines the week number for a specific date
func IsDateStrInRange ¶
compare if string x is in between string a and string b and only compare the date. This takes string in dateOnly format 'yyyy-mm-dd'
func IsTimeStringExpired ¶
Is timestring expired Check if expiresAt(string) is already expired (before) compared to time.now
func SetDateToTimeOnlyGoLangTime ¶
days.TimeStringToTimeInstanceWithDate cannot be used because it parse timeonly as date.TimeOnly ("hh:mm:ss") format. While timeonly is usually
func TimeStringFromNow ¶
Convert int duration to time string : now + duration Output is RFC3339
Types ¶
type HumanReadableOptions ¶
type HumanReadableOptions struct {
NanoSecondString string
MicroSecondString string
MilliSecondString string
SecondString string
MinuteString string
HourString string
DayString string
WeekString string
MonthString string
YearString string
ValueUnitSeparator string
WithSpaceUnit bool // space between units like: 20 days[this-space]20 hour
WithComma bool // comma between units like: 20 days, 20 hour
WithAndEnd bool // with "and" at the end: 20 days and 20 hour
AutoSingular bool // if true: if the value==1 then remove the last "s" at the end
}
func DefaultLongtHumanReadableOptions ¶
func DefaultLongtHumanReadableOptions() HumanReadableOptions
func DefaultShortHumanReadableOptions ¶
func DefaultShortHumanReadableOptions() HumanReadableOptions
type TimeConvertSetting ¶
type TimeConvertSetting string