gotime

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 5 Imported by: 3

README

GoTime 🕧🕐🕜🕑🕝🕒

⚠️ Package name changed to gotime on community request.

Designed on the top of Golang's built-in time package, instead of reinventing the wheel gotime uses internal time package to provide additional day-to-day functionalities that are practical for real-world applications.

Before we understand why there is a need for yet another time paackage, let's see some of the code that shocases what this library is capable of doing.

import "github.com/maniartech/gotime"

// // Format the date using human-friendly case-insensitive specifiers like yyyy-mm-dd
dt = time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC)
s := gotime.Format(dt, "dt mmmm, yyyy")
fmt.Println(s) // 1st January, 2012

// Convert date string to different format
s, err := gotime.Convert("2012-01-01", "yyyy-mm-dd", "wwww, dt mmmm, yyyy")
fmt.Println(s) // Sunday, 1st January, 2012

// Use time ago to get relative time
s, err := gotime.TimeAgo(time.Now().Add(-5 * time.Minute))
fmt.Println(s) // 5 minutes ago

// Parse a date string using easy to remember specifiers
t, err := gotime.Parse("2012-01-01", "yyyy-mm-dd")
fmt.Println(t) // 2012-01-01 00:00:00 +0000 UTC

tz := time.FixedZone("IST", 5.5*60*60)
t, err := gotime.ParseInLocation("01/01/2020", "dd/mm/yyyy", tz)
fmt.Println(t) // 2020-01-01 00:00:00 +0530 IST

// Some handy date finders and other utility functions
gotime.Yesterday()  // Returns yesterday's date
gotime.NextWeek()   // Returns data exactly one week from now

// Other utility functions
d1 := gotime.Date(10) // Returns date of 10 days from now
d2 := gotime.Date(-2) // Returns date of 2 days ago
d3 := gotime.Date(10, d1) // Returns date of 10 days from t1
gotime.Earliest(d1, d2, d3) // Returns the earliest date from the given list of dates
gotime.Latest(d1, d2, d3) // Returns the latest date from the given list of dates
gotime.IsBetween(d1, d2, d3) // Returns true if d1 is between d2 and d3

gotime.IsLeapYear(2020) // Returns true if the given year is a leap year
weekDdays := bool{true, true, true, true, true, false, false}
gotime.WorkDay(time.Now(), 15, weekDays) // Returns the date after the specified
                                           // number of workdays, considering
                                           // holidays and weekends

// So on...

Why GoTime?

✨ Key Features (Designed for Practicality)

It provides features are practical and useful in real-world applications. These features are either missing or not easy to use in the standard time package.

  • Easy Formatting: Format dates using straightforward, human-readable and intuitive specifiers like dd/mm/yyyy.
  • Human-Friendly Parsing: Effortlessly parse dates using intuitive date specifiers
  • Format Conversion: Seamlessly convert dates between formats, e.g., from dd/mm/yyyy to yyyy-mm-dd.
  • Relative Time Processing: Translate datetime into relative terms like a few minutes ago, yesterday, 5 days ago, or 3 years from now.
  • Finder Functions: Utilize functions like Yesterday(), Tomorrow(), SoD() (Start of Day), and EoD() (End of Day) etc.
  • Utility Functions: Access a suite of utility functions including Latest(), Earliest(), IsBetween(), TruncateDate(), and more.
✨ Developer Friendly

It provides a comprehensive range of specifiers for all your date and time formatting needs, making it an indispensable tool for Go developers.

  • 💯% test coverage 👌🏼
  • TinyGo compatible 👌🏼
  • No external dependencies 👌🏼
  • Fully utilises the standard time package and does not reinvent the wheel 👌🏼
  • Simple, intuitive and hackable API 👌🏼
  • Fully documented 👌🏼
  • Performance focused 👌🏼
✨ Ideal Use Cases
  • Developers needing formatting and parsing dates using human-friendly specifiers like yyyy-mm-dd.
  • Applications requiring conversion between different date formats.
  • Systems that display relative time representations.
  • Software dealing with date range calculations and comparisons.
  • Projects where standard time package features are insufficient or cumbersome.

The gotime stands out by offering features that are either missing or not as user-friendly in the standard time package, making it an invaluable addition to any Go developer's toolkit.

Installation

Installation is simple. Just run the following command in your terminal to install the gotime package in your project.

go get github.com/maniartech/gotime

Intuitive Date Format Specifiers (IDFS)

We've developed the Intuitive Date Format Specifiers (IDFS) for gotime. IDFS is a cAsE-insensitive format, eliminating ambiguity often associated with dd-mm-yyyy formats. This intuitive specifiers makes date and time formatting simple and hackable. entry by removing the need to remember upper and lower case attributes, a common issue with other similar formats. For example, %Y represents a four-digit year, while %y denotes a two-digit year in strftime. In contrast, IDFS intuitively uses yyyy for a four-digit year and yy for a two-digit year. Typing dates is also more straightforward with IDFS, as the format yyyy-mm-dd is easier to remember and input compared to the less intuitive 2006-01-02.

It supports simple, human-friendly date-time formatting. The table below displays the supported formats. Internally, gotime utilizes time.Time.Format() and converts human-friendly formats into the time.Time format. For instance, it transforms yyyy-mm-dd into 2006-01-02 before using time.Time.Format() to format the date.

Date Formats
Format Output Description
yy 06 Two-digit year with leading zero
yyyy 2006 Four-digit year
m 1 Month without leading zero
mm 01 Month in two digits with leading zero
mt 1st Month in ordinal format (not for parsing)
mmm Jan Month in short name
mmmm January Month in full name
d 2 Day without leading zero
dd 02 Day in two digits with leading zero
db 2 Day in blank-padded two digits
dt 2nd Day in ordinal format (not for parsing)
ddd 002 Zero padded day of year
www Mon Three-letter weekday name
wwww Monday Full weekday name
Time Formats
Format Output Description
h 3 Hour in 12-hour format without leading zero
hh 03 Hour in 12-hour format with leading zero
hhh 15 Hour in 24-hour format without leading zero
a pm AM/PM in lowercase
aa PM AM/PM in uppercase
ii 04 Minute with leading zero
i 4 Minute without leading zero
ss 05 Second with leading zero
s 5 Second without leading zero
.0 .00 Microsecond with leading zero
.9 .99 Microsecond without leading zero
Timezone Formats
Format Output Description
z Z The Z literal represents UTC
zz MST Timezone abbreviation
o ±07 Timezone offset with leading zero (only hours)
oo ±0700 Timezone offset with leading zero without colon
ooo ±07:00 Timezone offset with leading zero with colon
Built-in Formats

It provides all the built-in formats supported by the standard time package. Such as time.Layout, time.ANSIC, time.UnixDate, time.RubyDate, time.RFC822, time.RFC822Z, time.RFC850, time.RFC1123, time.RFC1123Z, time.RFC3339, time.RFC3339Nano, time.Kitchen, etc.

API Reference

Date Parsing, Formatting and Conversion
Function Description
Parse Parses the given date string using IDFS, a human-friendly, hackable date format
ParseInLocation Parses the given date string in the specified location using IDFS, a human-friendly, hackable date format, and the given location
Format Formats the given date using IDFS format specifiers
FormatTimestamp Formats the given timestamp in Unix format using IDFS format specifiers
Convert Converts the given date string from one format to another using IDFS format specifiers
Time Ago
Function Description
TimeAgo Returns the humanized relative time from the given date
Relative Date Finders
Years
Function Description
YearStart Returns the start date of the given year
YearEnd Returns the end date of the given year
LastYear Returns the date exactly one year before today
NextYear Returns the date exactly one year after today
Years Returns the date of the given number of years from now or the given date
Months
Function Description
MonthStart Returns the start date of the given month
MonthEnd Returns the end date of the given month
LastMonth Returns the date exactly one month before today
NextMonth Returns the date exactly one month after today
Months Returns the date of the given number of months from now or the given date
Weeks
Function Description
WeekStart Returns the start date of the given week
WeekStartOn Considers the given day as the start of the week and returns the start date of the week
WeekEnd Returns the end date of the given week
WeekEndOn Considers the given day as the end of the week and returns the end date of the week
LastWeek Returns the date exactly one week before today
NextWeek Returns the date exactly one week after today
Weeks Returns the date of the given number of weeks from now or the given date
Days
Function Description
SoD Returns the start of the given day
EoD Returns the end of the given day
Yesterday Returns the date exactly one day before today
Tomorrow Returns the date exactly one day after today
Days Returns the date of the given number of days from now or the given date
DateRange Functions
Function Description
IsInRange Returns true if the given date is in the specified range
IsInDateRange Returns true if the given date is in the specified range. Before performing inclusive comparison, it sets the time to the start of the day for the start date and the end of the day for the end date.
DateTime Utility Functions
Function Description
IsLeapYear Returns true if the given year is a leap year
DaysInMonth Returns the number of days in the given month
DaysInYear Returns the number of days in the given year
DaysInQuarter Returns the number of days in the given quarter
NewDate Returns the date from the given year, month, and day
NewTime Returns the time from the given hour, minute, and second
DateValue Returns the serial number of the given date from 1900-01-01
Diff Returns the difference between two durations. Can also return a rounded result.
Latest Returns the latest time from the specified list of times
Earliest Returns the earliest time from the specified list of times
IsBetween Returns true if the given date is between the specified range
TruncateTime Truncates the time part from the given date
TruncateDate Truncates the date part from the given date
NetWorkDays Returns the number of workdays between two dates, considering holidays and weekends
WorkDay Returns the date after the specified number of workdays, considering holidays and weekends
PrevWorkDay Returns the date before the specified number of working days, considering holidays and weekends
ReplaceDate ReplaceDate lets you replace the date part of a time.Time object with a new date.
ReplaceTime ReplaceTime lets you replace the time part of a time.Time object with a new time.

For more information, see the time package documentation.

Code Clean up - WIP ⚠️

While the gotime is fully functional, and API has been finalized thoroughly tested and documented, and can be used in production, there are few area that needs to be cleaned up. Such as:

  • Some of the source code and tests are not well organized
  • In some cases, documentation needs to be improved
  • Uncomented code in the source files etc

We shall be working on these issues in the coming days. If you find any issues or have any suggestions, please feel free to open an issue or submit a pull request.

Contributing

Contributions to gotime are welcome. Please ensure that your code adheres to the existing style and includes tests covering new features or bug fixes.

License

gotime is MIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(value, fromLayout, toLayout string) (string, error)

ParseAndFormat is a utility function that takes a date-time string, a source format string (from), and a target format string (to). The function parses the input date-time string according to the source format, and then formats the parsed date-time value using the target format. The function returns the formatted date-time string and an error if the parsing or formatting fails.

Example usage:

formattedDate, err := ParseAndFormat("2022-12-31", "yyyy-mm-dd", "dt mmmm, yyyy")
if err != nil {
	panic(err)
}
fmt.Println(formattedDate) // 31st December, 2022

func DateValue

func DateValue(date time.Time) int

DateValue returns the serial number of the given time.Time

Arguments

date: (time.Time) The date to be converted to serial number

Note

The serial number is the number of days from 1/1/1900

func Days

func Days(days int, dt ...time.Time) time.Time

Days returns the date of the given number of days from the date provided,

Arguments

days: (int) The number of days to be added to the date.

dt: (time.Time) The date to be used to calculate the date of the given number of days. (Only takes the first date if multiple dates are provided)

Note

If the days parameter is 0 it will panic.

func DaysInMonth

func DaysInMonth(year, month int) int

DaysInMonth returns the number of days in the month.

For February, the number of days depends on whether the year is a leap year or not. For April, June, September, and November, the number of days is 30. For all other months, the number of days is 31.

Example:

days := DaysInMonth(2022, 2)
// days == 28

func DaysInQuarter

func DaysInQuarter(year, quarter int) int

DaysInQuarter returns the number of days in the quarter.

The number of days in each quarter depends on the number of days in each month. Q1: Jan (31) + Feb (28 or 29) + Mar (31) = 90 or 91 days Q2: Apr (30) + May (31) + Jun (30) = 91 days Q3: Jul (31) + Aug (31) + Sep (30) = 92 days Q4: Oct (31) + Nov (30) + Dec (31) = 92 days

Example:

days := DaysInQuarter(2022, 1)
// days == 90

func DaysInYear

func DaysInYear(year int) int

DaysInYear returns the number of days in the year.

If the year is a leap year, it returns 366, otherwise it returns 365.

Example:

days := DaysInYear(2022)
// days == 365

func Diff

func Diff(t1, t2 time.Time, unit time.Duration, rounded ...bool) float64

Diff returns the difference between the given time.Time and the current time.Time in the given unit

func Earliest

func Earliest(t1, t2 time.Time, tn ...time.Time) time.Time

Earliest returns the earliest time from the given time.Time list

Arguments

t1: (time.Time) The first time to be compared

t2: (time.Time) The second time to be compared

tn: (time.Time) The rest of the times to be compared

func EoD

func EoD(t ...time.Time) time.Time

EoD returns the end of the day for the given time.

It calculates the start of the day for the given time using the SoD function, and adds 24 hours to it. To get the end of the day, it subtracts one nanosecond from the resulting time.Time value, since the SoD function returns the first nanosecond of the day.

Example:

t := time.Date(2022, time.December, 30, 16, 30, 0, 0, time.UTC)
endOfDay := EoD(t)
// endOfDay == time.Date(2022, time.December, 30, 23, 59, 59, 999999999, time.UTC)

func Format

func Format(dt time.Time, layout string) string

Format is a utility function that takes a time.Time value and a layout string as input, then converts the time value to a formatted string based on the layout.

Example usage:

formattedDate := Format(time.Now(), "yyyy-mm-dd")

func FormatTimestamp

func FormatTimestamp(timestamp int64, layout string) string

FormatTimestamp takes a Unix timestamp in seconds and a layout string, then returns a formatted string based on the layout.

Example usage:

formattedDate := FormatTimestamp(1609459200, "yyyy-mm-dd")

func FormatUnix

func FormatUnix(sec int64, nsec int64, layout string) string

FormatUnix takes the Unix time in seconds and nanoseconds, as well as a layout string, and returns a formatted string based on the layout.

Example usage:

formattedDate := FormatUnix(1609459200, 0, "yyyy-mm-dd")

func IsBetween

func IsBetween(t1, t2, t3 time.Time) bool

IsBetween returns true if the given time.Time is between the given time.Time range

Arguments

t1: (time.Time) The date to be checked

t2: (time.Time) The first date of the range

t3: (time.Time) The second date of the range

func IsBetweenDates

func IsBetweenDates(t1, t2, t3 time.Time) bool

IsBetweenDates checks if the given time is in the range of the start and end date. Before performing inclusive comparison, it sets the time to the start of the day for the start date and the end of the day for the end date.

func IsLeapYear

func IsLeapYear(year int) bool

IsLeapYear returns true if the year is a leap year.

A leap year is a year that is evenly divisible by 4, but not by 100 unless it is also divisible by 400.

Example:

isLeap := IsLeapYear(2024)
// isLeap == true

func LastMonth

func LastMonth() time.Time

LastMonth returns the last month's time.Time corresponding to the current time.

func LastWeek

func LastWeek() time.Time

LastWeek returns the last week's time.Time corresponding to the current time.

func LastYear

func LastYear() time.Time

LastYear returns the last year's time.Time corresponding to the current time.

func Latest

func Latest(t1, t2 time.Time, tn ...time.Time) time.Time

Latest returns the latest time from the given time.Time list

Arguments

t1: (time.Time) The first time to be compared

t2: (time.Time) The second time to be compared

tn: (time.Time) The rest of the times to be compared

func MonthEnd

func MonthEnd(dt ...time.Time) time.Time

MonthEnd returns the last day and the last second of the month.

Arguments

dt: (time.Time) The date to be used to calculate the last day of the month.

Note

If the date is not provided, it will return the last day of the month from the current date.

func MonthStart

func MonthStart(dt ...time.Time) time.Time

MonthStart returns the first day of the month.

Arguments

dt: (time.Time) The date to be used to calculate the first day of the month.

Note

If the date is not provided, it will return the first day of the month from the current date.

func Months

func Months(months int, dt ...time.Time) time.Time

Months returns the date of the given number of months from the date provided,

Arguments

months: (int) The number of months to be added to the date.

dt: (time.Time) The date to be used to calculate the date of the given number of months. (Only takes the first date if multiple dates are provided)

Note

If the months parameter is 0 it will panic.

func NetWorkDays

func NetWorkDays(startDate, endDate time.Time, workingDays [7]bool, holidays ...time.Time) int

NetWorkdays returns the number of working days between the given dates

Arguments

startDate: (time.Time) The date to start from

endDate: (time.Time) The date to end at

workingDays: ([7]bool) The working days of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)

holidays: (...time.Time) The holidays to be excluded

func NewDate

func NewDate(year, month, day int) time.Time

NewDate creates a time.Time object from the given year, month and day.

It constructs a new time.Time object with the given year, month, and day, and sets the hour, minute, second, and nanosecond fields to 0. It also sets the location field to time.UTC.

Example:

date := NewDate(2022, 4, 15)
// date == time.Date(2022, time.April, 15, 0, 0, 0, 0, time.UTC)

func NewTime

func NewTime(hour, minute, second int) time.Time

NewTime creates a time.Time object from the given hour, minute and second.

It constructs a new time.Time object with the given hour, minute, and second, and sets the year, month, and day fields to 0. It also sets the location field to time.UTC.

Example:

timeObj := NewTime(12, 30, 0)
// timeObj == time.Date(0, 1, 1, 12, 30, 0, 0, time.UTC)

func NextMonth

func NextMonth() time.Time

NextMonth returns the next month's time.Time corresponding to the current time.

func NextWeek

func NextWeek() time.Time

NextWeek returns the next week's time.Time corresponding to the current time.

func NextYear

func NextYear() time.Time

NextYear returns the next year's time.Time corresponding to the current time.

func Parse

func Parse(layout, value string) (time.Time, error)

Parse is a utility function that takes a date-time string and a format string as input, then parses the date-time string according to the format. The function returns a time.Time value and an error if the parsing fails.

Example usage:

parsedDate, err := Parse("yyyy-mm-dd", "2022-12-31")
if err != nil {
    panic(err)
}
fmt.Println(parsedDate) // 2022-12-31 00:00:00 +0000 UTC

func ParseInLocation

func ParseInLocation(layout, value string, loc *time.Location) (time.Time, error)

ParseInLocation is a utility function that takes a date-time string, a format string as input, then parses the date-time string according to the format. The function returns a time.Time value and an error if the parsing fails. It also takes a location as input and returns the time in that location.

Example usage:

parsedDate, err := ParseInLocation("yyyy-mm-dd", "2022-12-31", time.FixedZone("IST", 5.5*60*60))
if err != nil {
    panic(err)
}
fmt.Println(parsedDate) // 2022-12-31 00:00:00 +0000 UTC

func PrevWorkDay

func PrevWorkDay(startDate time.Time, days int, workingDays [7]bool, holidays ...time.Time) time.Time

PrevWorkDay returns the date before the given number of working days

Arguments

startDate: (time.Time) The date to start from

days: (int) The number of working days to subtract

workingDays: ([7]bool) The working days of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)

holidays: (...time.Time) The holidays to be excluded

Note

The working days are the days that are not holidays and are in the working days of the week

func ReplaceDate

func ReplaceDate(t time.Time, year, month, day int) time.Time

ReplaceDate lets you replace the date part of a time.Time object with a new date. It keeps the time part of the time.Time object unchanged.

Example:

date := time.Date(2022, time.April, 15, 12, 30, 0, 0, time.UTC)
newDate := ReplaceDate(date, 2023, 5, 20)
// newDate == time.Date(2023, time.May, 20, 12, 30, 0, 0, time.UTC)

func ReplaceTime

func ReplaceTime(t time.Time, hour, minute, second int) time.Time

ReplaceTime lets you replace the time part of a time.Time object with a new time. It keeps the date part of the time.Time object unchanged.

Example:

date := time.Date(2022, time.April, 15, 12, 30, 0, 0, time.UTC)
newTime := ReplaceTime(date, 15, 45, 0)
// newTime == time.Date(2022, time.April, 15, 15, 45, 0, 0, time.UTC)

func SoD

func SoD(t ...time.Time) time.Time

SoD returns the start of the day for the given time.

It constructs a new time.Time value using the year, month, and day of the given time.Time value, and setting the hour, minute, second, and nanosecond fields to 0. It also sets the location field to the same location as the input time.Time value. The resulting time.Time value represents the start of the day for the given time.

Example:

t := time.Date(2022, time.December, 30, 16, 30, 0, 0, time.UTC)
startOfDay := SoD(t)
// startOfDay == time.Date(2022, time.December, 30, 0, 0, 0, 0, time.UTC)

func TimeAgo

func TimeAgo(t time.Time, baseTime ...time.Time) string

TimeAgo calculates the relative time difference between a given timestamp and the current time, and returns a string that describes the time difference in human-readable terms. The function takes a time.Time object representing the timestamp, and an optional baseTime parameter, which can be used to specify a different base time to use instead of the current time. The function returns a string that describes the time difference in human-readable terms, such as "2 weeks ago" or "In a few minutes".

Example usage:

// Create a time object representing one week ago
oneWeekAgo := time.Now().Add(-7 * 24 * time.Hour)

// Calculate the relative time difference between the timestamp and the current time
timeAgo := TimeAgo(oneWeekAgo)

fmt.Println("One week ago:", timeAgo)
// Output: One week ago: Last week

// Create a time object representing 3 hours and 45 minutes ago
threeHoursAgo := time.Now().Add(-3 * time.Hour).Add(-45 * time.Minute)

// Calculate the relative time difference between the timestamp and the current time
timeAgo = TimeAgo(threeHoursAgo)

fmt.Println("Three hours ago:", timeAgo)
// Output: Three hours ago: 3 hours ago

func Tomorrow

func Tomorrow() time.Time

Tomorrow returns the tomorrow's time.Time corresponding to the current time.

func TruncateTime

func TruncateTime(date time.Time) time.Time

TruncateTime truncates the time part of the given date. It returns the tructed date.

Arguments

date: (time.Time) The date to be truncated

func WeekEnd

func WeekEnd(dt ...time.Time) time.Time

WeekEnd returns the last day and the last second of the week.

Arguments

dt: (time.Time) The date to be used to calculate the last day of the week.

Note

If the date is not provided, it will return the last day of the week from the current date.

func WeekEndOn

func WeekEndOn(day time.Weekday, dt ...time.Time) time.Time

WeekEndOn returns the last day and the last second of the week on the given day. For example, WeekEndOn(time.Sunday) returns the last day of the week (Sunday).

Arguments

day: (time.Weekday) The day to be used to calculate the last day of the week.

dt: (time.Time) The date to be used to calculate the last day of the week.

Note

If the date is not provided, it will return the last day of the week from the current date.

func WeekStart

func WeekStart(dt ...time.Time) time.Time

WeekStart returns the first day of the week (Monday).

Arguments

dt: (time.Time) The date to be used to calculate the first day of the week.

Note

If the date is not provided, it will return the first day of the week from the current date.

func WeekStartOn

func WeekStartOn(day time.Weekday, dt ...time.Time) time.Time

WeekStartOn returns the first day of the week on the given day.

Arguments

day: (time.Weekday) The day to be used to calculate the first day of the week.

dt: (time.Time) The date to be used to calculate the first day of the week.

Note

If the date is not provided, it will return the first day of the week from the current date.

func Weeks

func Weeks(weeks int, dt ...time.Time) time.Time

Weeks returns the date of the given number of weeks from the current date. If the value is negative, it will return the date of the previous week.

Arguments

weeks: (int) The number of weeks to be added to the date.

dt: (time.Time) The date to be used to calculate the date of the given number of weeks. (Only takes the first date if multiple dates are provided)

Note

If the weeks parameter is 0 it will panic.

func WorkDay

func WorkDay(startDate time.Time, days int, workingDays [7]bool, holidays ...time.Time) time.Time

WorkDay returns the date after the given number of working days

Arguments

startDate: (time.Time) The date to start from

days: (int) The number of working days to add

workingDays: ([7]bool) The working days of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)

holidays: (...time.Time) The holidays to be excluded

Note

The working days are the days that are not holidays and are in the working days of the week

func YearEnd

func YearEnd(dt ...time.Time) time.Time

YearEnd returns the last day and the last second of the year.

Arguments

dt: (time.Time) The date to be used to calculate the last day of the year.

Note

If the date is not provided, it will return the last day of the year from the current date.

func YearStart

func YearStart(dt ...time.Time) time.Time

-----------------Year Functions----------------- YearStart returns the first day of the year.

Arguments

dt: (time.Time) The date to be used to calculate the first day of the year.

Note

If the date is not provided, it will return the first day of the year from the current date.

func Years

func Years(years int, dt ...time.Time) time.Time

Years returns the date of the given number of years from the date provided, If the date is not provided, it will return the date of the given number of years from the current date.

Arguments

years: (int) The number of years to be added to the date.

dt: (time.Time) The date to be used to calculate the date of the given number of year. (Only takes the first date if multiple dates are provided)

Note

If the years parameter is 0 it will panic.

func Yesterday

func Yesterday() time.Time

Yesterday returns the yesterday's time.Time corresponding to the current time.

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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