modulepackage
0.0.0-20200818130035-8cc1b656a124
Repository: https://github.com/researchnow/tareekh.git
Documentation: pkg.go.dev
# README
Tareekh
Tareekh is a GoLang library to make it a little bit easy to work with dates. This was written to avoid reimplementing common functionality working with time.Time
.
Time zone
By default the Local timezone is used. But if you want to specify a particular timezone, just do:
tareekh.TimeZone = "America/New_York" //EST
Examples
Yesterday
yesterday := tareekh.Yesterday()
fmt.Println(yesterday) //yesterdays time object
FromDateString
dt, err := tareekh.FromDateString("2016-11-22")
if err != nil {
//handle error
}
fmt.Println(t)
ToShortDate
t, _ := tareekh.FromDateString("2016-11-22")
shortDate := tareekh.ToShortDate(t)
fmt.Println(shortDate) //should print 2016-11-22
IsDateInFuture
future := time.Now().AddDate(0, 0, 1)
isit := tareekh.IsDateInFuture(future)
fmt.Println(isit) //should be true
BeginningOfMonth
begin := tareekh.BeginningOfMonth() //first of current month
EndOfMonth
end := tareekh.EndOfMonth() //last day of current month
FromDayOfMonth
dayx := tareekh.FromDayOfMonth(1) //specified day of current month
Status
In development, if there's other useful stuff feel free to fork and issue a pull request.
# Functions
BeginningOfDay resets the time to 00:00:00 while keeping date intact.
BeginningOfMonth returns time object set to first day of current month.
DaysAfter returns time for specified number of days forward.
DaysAgo returns time for specified number of days back.
DifferenceInDays returns the number of days between two given dates.
DifferenceInHours returns the number of hours between two given dates.
DifferenceInSeconds returns the number of seconds between two given dates.
EndOfMonth return time object set to last day of current month.
ExtractBeginningOfMonth ..
ExtractEndOfMonth ..
Format returns the time in string format.
FromDateString parses date string of format YYYY-MM-DD and returns time object.
FromDayOfMonth return time object set to specified day of the current month.
IsDateInFuture returns true if the date is in future.
IsDateInPast returns true if the date is in past.
Now returns time.Now() and is timezone aware.
Today returns the current time.
ToShortDate converts time object to string with format YYYY-MM-DD.
Yesterday returns time object set to yesterdays (-1 Day).
# Constants
DefaultDateFormat is the golang date format used by default.
LeastPossibleDays in a month.
# Variables
TimeZone uses whichever is the default unless specified.