Documentation
¶
Overview ¶
Package dateHelpers provides utilities for date/time formatting, parsing, arithmetic, and business-day adjustments used across the project.
Index ¶
- func AddDays(startDate time.Time, daysToAdd int) time.Time
- func AddMonthAndAdjust(startDate time.Time, noMonths int) time.Time
- func AddMonths(startDate time.Time, monthsToAdd int) time.Time
- func AddWeeks(startDate time.Time, weeksToAdd int) time.Time
- func AddWorkingDays(startDate time.Time, daysToAdd int) time.Time
- func AddWorkingMonths(startDate time.Time, monthsToAdd int) time.Time
- func AddWorkingWeeks(startDate time.Time, weeksToAdd int) time.Time
- func AddWorkingYears(startDate time.Time, yearsToAdd int) time.Time
- func AddYears(startDate time.Time, yearsToAdd int) time.Time
- func AdjustToNextWorkingday(date time.Time) time.Time
- func AdjustToPreviousWorkingday(date time.Time) time.Time
- func DifferenceInDays(t1, t2 time.Time) int
- func EndOfDay(t time.Time) time.Time
- func FormatAudit(in time.Time) string
- func FormatBackupDate(in time.Time) string
- func FormatBackupFolder(in time.Time) string
- func FormatCalendar(in time.Time) string
- func FormatDMY(in time.Time) string
- func FormatDMY4(in time.Time) string
- func FormatDetail(in time.Time) string
- func FormatExternal(in time.Time) string
- func FormatHTMLInput(in time.Time) string
- func FormatHuman(t time.Time) string
- func FormatHumanFromString(in string) (time.Time, error)
- func FormatInternal(in time.Time) string
- func FormatYMD(in time.Time) string
- func HumanDate(t time.Time) string
- func IsAfter(t1, t2 time.Time) bool
- func IsAfterDays(t1, t2 time.Time, days int) bool
- func IsAfterOrEqualTo(t1, t2 time.Time) bool
- func IsBefore(t1, t2 time.Time) bool
- func IsBeforeDays(t1, t2 time.Time, days int) bool
- func IsBeforeOrEqualTo(t1, t2 time.Time) bool
- func IsBetweenDates(testDate, startDate, endDate time.Time) bool
- func IsFriday(t time.Time) bool
- func IsInXDays(t1, t2 time.Time, days int) bool
- func IsMonday(t time.Time) bool
- func IsNotInXDays(t1, t2 time.Time, days int) bool
- func IsSameDay(t1, t2 time.Time) bool
- func IsSaturday(t time.Time) bool
- func IsSunday(t time.Time) bool
- func IsThursday(t time.Time) bool
- func IsToday(t time.Time) bool
- func IsTomorrow(t time.Time) bool
- func IsTuesday(t time.Time) bool
- func IsWednesday(t time.Time) bool
- func IsWeekday(t time.Time) bool
- func IsWeekend(t time.Time) bool
- func IsWorkingDateBetween(testDate, startDate, endDate time.Time) bool
- func IsWorkingDay(t time.Time) bool
- func IsYesterday(t time.Time) bool
- func NextWorkingDay() time.Time
- func OrdinaliseDay(x int) string
- func ParseAudit(in string) (time.Time, error)
- func ParseBackupDate(in string) (time.Time, error)
- func ParseBackupFolder(in string) (time.Time, error)
- func ParseCalendar(in string) (time.Time, error)
- func ParseDMY(in string) (time.Time, error)
- func ParseDMY4(in string) (time.Time, error)
- func ParseDetail(in string) (time.Time, error)
- func ParseExternal(in string) (time.Time, error)
- func ParseHTMLInput(in string) (time.Time, error)
- func ParseHuman(in string) (time.Time, error)
- func ParseHumanFromString(in string) (time.Time, error)
- func ParseInternal(in string) (time.Time, error)
- func ParseYMD(in string) (time.Time, error)
- func PreviousWorkingDay() time.Time
- func StartOfDay(t time.Time) time.Time
- func SubtractDays(startDate time.Time, daysToSubtract int) time.Time
- func SubtractMonths(startDate time.Time, monthsToSubtract int) time.Time
- func SubtractWeeks(startDate time.Time, weeksToSubtract int) time.Time
- func SubtractWorkingDays(startDate time.Time, daysToSubtract int) time.Time
- func SubtractWorkingMonths(startDate time.Time, monthsToSubtract int) time.Time
- func SubtractWorkingWeeks(startDate time.Time, weeksToSubtract int) time.Time
- func SubtractWorkingYears(startDate time.Time, yearsToSubtract int) time.Time
- func SubtractYears(startDate time.Time, yearsToSubtract int) time.Time
- func Today() time.Time
- func Tomorrow() time.Time
- func Yesterday() time.Time
- type DateFormat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMonthAndAdjust ¶ added in v1.2.72
AddMonthAndAdjust adds noMonths calendar months and adjusts to the next weekday if needed.
func AddMonths ¶ added in v1.3.4
AddMonths returns the time that is monthsToAdd months after startDate.
func AddWorkingDays ¶ added in v1.2.72
AddWorkingDays adds n working days (excluding weekends) to a given date.
func AddWorkingMonths ¶ added in v1.3.4
func AddWorkingWeeks ¶ added in v1.3.4
func AddWorkingYears ¶ added in v1.3.4
func AdjustToNextWorkingday ¶ added in v1.2.72
AdjustToNextWorkingday moves the date forward to the next weekday if it's a weekend.
func AdjustToPreviousWorkingday ¶ added in v1.3.4
AdjustToPreviousWorkingday moves the date backward to the previous weekday if it's a weekend.
func DifferenceInDays ¶ added in v1.3.4
func FormatAudit ¶
FormatAudit returns the formatted date/time using the audit/detail layout.
func FormatBackupDate ¶ added in v1.3.4
FormatBackupDate formats a time for backup naming (date component).
func FormatBackupFolder ¶ added in v1.3.4
FormatBackupFolder formats a time for backup folder naming.
func FormatCalendar ¶
FormatCalendar formats the time using the calendar (ISO-like) layout.
func FormatDMY4 ¶ added in v1.3.4
FormatDMY4 formats a time as dd/mm/yyyy using the configured DMY4 layout.
func FormatDetail ¶ added in v1.3.4
FormatDetail returns a detailed date/time string including time components.
func FormatExternal ¶ added in v1.3.4
FormatExternal returns a human/external formatted date/time string.
func FormatHTMLInput ¶ added in v1.3.4
FormatHTMLInput formats a time for HTML input controls (e.g. dd/mm/yyyy).
func FormatHuman ¶
FormatHuman returns the human-friendly formatted date/time string using the External layout.
func FormatHumanFromString ¶
FormatHumanFromString parses a human-readable date/time string using the External layout. This is functionally equivalent to ParseHumanFromString.
func FormatInternal ¶ added in v1.3.4
FormatInternal returns the internal/system formatted date/time string.
func IsAfterOrEqualTo ¶
IsAfterOrEqualTo reports whether t1 is strictly after or equal to t2 when compared at the start of day.
func IsBeforeOrEqualTo ¶
IsBeforeOrEqualTo reports whether t1 is strictly before or equal to t2 when both are compared at their respective start-of-day values.
func IsBetweenDates ¶ added in v1.3.4
func IsSaturday ¶ added in v1.3.4
func IsThursday ¶ added in v1.3.4
func IsTomorrow ¶ added in v1.3.4
IsTomorrow reports whether the given time is tomorrow (relative to now).
func IsWednesday ¶ added in v1.3.4
func IsWorkingDateBetween ¶ added in v1.3.4
func IsWorkingDay ¶ added in v1.2.72
IsWorkingDay reports whether the date falls on a weekday (Mon-Fri).
func IsYesterday ¶ added in v1.3.4
IsYesterday reports whether the given time is yesterday (relative to now).
func NextWorkingDay ¶ added in v1.3.4
NextWorkingDay returns the next working day after today.
func OrdinaliseDay ¶ added in v1.5.0
func ParseAudit ¶ added in v1.3.4
ParseAudit parses a date/time string using the audit/detail layout.
func ParseBackupDate ¶ added in v1.3.4
ParseBackupDate parses a backup date string.
func ParseBackupFolder ¶ added in v1.3.4
ParseBackupFolder parses a backup folder date/time string.
func ParseCalendar ¶ added in v1.3.4
ParseCalendar parses a date/time string using the calendar layout.
func ParseDMY ¶ added in v1.3.4
ParseDMY parses a day/month/year string using the configured DMY layout.
func ParseDMY4 ¶ added in v1.3.4
ParseDMY4 parses a dd/mm/yyyy string using the configured DMY4 layout.
func ParseDetail ¶ added in v1.3.4
ParseDetail parses a detailed date/time string using the Detail layout.
func ParseExternal ¶ added in v1.3.4
ParseExternal parses a human/external date/time string.
func ParseHTMLInput ¶ added in v1.3.4
ParseHTMLInput parses a string formatted for HTML input controls.
func ParseHuman ¶ added in v1.3.4
ParseHuman parses a human-friendly date/time string using the External layout.
func ParseHumanFromString ¶ added in v1.3.4
ParseHumanFromString parses a human-readable date/time string using the External layout.
func ParseInternal ¶ added in v1.3.4
ParseInternal parses a date/time string using the internal/system layout.
func ParseYMD ¶ added in v1.3.4
ParseYMD parses a year-month-day string using the configured YMD layout.
func PreviousWorkingDay ¶ added in v1.3.4
PreviousWorkingDay returns the previous working day before today.
func StartOfDay ¶
StartOfDay returns the time truncated to midnight in the local timezone.
func SubtractDays ¶ added in v1.3.4
func SubtractMonths ¶ added in v1.3.4
func SubtractWeeks ¶ added in v1.3.4
func SubtractWorkingDays ¶ added in v1.3.4
func SubtractWorkingMonths ¶ added in v1.3.4
func SubtractWorkingWeeks ¶ added in v1.3.4
func SubtractWorkingYears ¶ added in v1.3.4
SubtractWorkingYears subtracts full years and adjusts to the previous working day if needed.
func SubtractYears ¶ added in v1.3.4
SubtractYears returns the time that is yearsToSubtract years before startDate.
Types ¶
type DateFormat ¶
type DateFormat struct {
External string
DMY string
Internal string
Detail string
YMD string
Calendar string
BackupDate string
BackupFolder string
HTMLInput string
DMY4 string
MYH string
}
DateFormat defines the collection of Go time layouts used by this package for formatting/parsing dates in various contexts.
var Format DateFormat
Format contains the active set of date/time layout strings loaded from application configuration. These layouts are used by the helper functions for formatting and parsing dates in consistent forms.