import "github.com/uniplaces/carbon"
Package `carbon` is an extension to Go's time library based on PHP's Carbon library
carbon.go carboninterval.go translator.go
const (
DefaultFormat = "2006-01-02 15:04:05"
DateFormat = "2006-01-02"
FormattedDateFormat = "Jan 2, 2006"
TimeFormat = "15:04:05"
HourMinuteFormat = "15:04"
HourFormat = "15"
DayDateTimeFormat = "Mon, Aug 2, 2006 3:04 PM"
CookieFormat = "Monday, 02-Jan-2006 15:04:05 MST"
RFC822Format = "Mon, 02 Jan 06 15:04:05 -0700"
RFC1036Format = "Mon, 02 Jan 06 15:04:05 -0700"
RFC2822Format = "Mon, 02 Jan 2006 15:04:05 -0700"
RFC3339Format = "2006-01-02T15:04:05-07:00"
RSSFormat = "Mon, 02 Jan 2006 15:04:05 -0700"
)Represents the different string formats for dates
After will be behave like time.After unless time has been frozen If time is frozen it will add the expected delay and immediately send the frozen time on the returned channel
Freeze allows time to be frozen to facilitate testing
IsTimeFrozen allows checking if time has been frozen
Sleep will be behave like time.Sleep unless time has been frozen If time is frozen it will add the expected sleep delay and return immediately
Tick will be behave like time.Tick unless time has been frozen If time is frozen it will tick normally but the date will be based on the frozen date
func UnFreeze()
UnFreeze returns time to normal operation
type Carbon struct {
time.Time
Translator *Translator
// contains filtered or unexported fields
}The Carbon type represents a Time instance. Provides a simple API extension for Time.
Create returns a new pointer to Carbon instance from a specific date and time. If the location is invalid, it returns an error instead.
CreateFromDate returns a new pointer to a Carbon instance from just a date. The time portion is set to now. If the location is invalid, it returns an error instead.
CreateFromFormat returns a new pointer to a Carbon instance from a specific format. If the location is invalid, it returns an error instead.
CreateFromTime returns a new pointer to a Carbon instance from just a date. The time portion is set to now. If the locations is invalid, it returns an error instead.
CreateFromTimestamp returns a new pointer to a Carbon instance from a timestamp. If the location is invalid, it returns an error instead.
CreateFromTimestampUTC returns a new pointer to a Carbon instance from an UTC timestamp. If the location is invalid, it returns an error instead.
MaxValue returns a pointer to a new carbon instance for greatest supported date
MinValue returns a pointer to a new carbon instance for lowest supported date
NewCarbon returns a pointer to a new Carbon instance
Now returns a new Carbon instance for right now in current localtime
NowInLocation returns a new Carbon instance for right now in given location. The location is in IANA Time Zone database, such as "America/New_York".
Parse returns a pointer to a new carbon instance from a string If the location is invalid, it returns an error instead.
Today returns a pointer to a new carbon instance for today If the location is invalid, it returns an error instead.
Tomorrow returns a pointer to a new carbon instance for tomorrow If the location is invalid, it returns an error instead.
Yesterday returns a pointer to a new carbon instance for yesterday If the location is invalid, it returns an error instead.
AddCenturies adds centuries to the time. Positive values travels forward while negative values travels into the past
AddCentury adds a century to the current time
AddDay adds a day to the current time
AddDays adds a day to the current time. Positive value travels forward while negative value travels into the past
AddHour adds an hour to the current time
AddHours adds an hour to the current time. Positive value travels forward while negative value travels into the past
AddMinute adds a minute to the current time
AddMinutes adds minutes to the current time. Positive value travels forward while negative value travels into the past.
AddMonth adds a month to the current time
AddMonthNoOverflow adds a month with no overflow to the current time
AddMonths adds months to the current time. Positive value travels forward while negative values travels into the past
AddMonthsNoOverflow adds a month to the current time, not overflowing in case the destination month has less days than the current one. Positive value travels forward while negative value travels into the past.
AddQuarter adds a quarter to the current time
AddQuarters adds quarters to the current time. Positive values travel forward while negative values travel into the past
AddSecond adds a second to the time
AddSeconds adds seconds to the current time. Positive values travels forward while negative values travels into the past.
AddWeek adds a week to the current time
AddWeekday adds a weekday to the current time
AddWeekdays adds a weekday to the current time. Positive value travels forward while negative value travels into the past
AddWeeks adds a week to the current time. Positive value travels forward while negative value travels into the past.
AddYear adds a year to the current time
AddYears adds a year to the current time. Positive values travel forward while negative values travel into the past
Age gets the age from the current instance time to now
AtomString formats the current time to a Atom date format
Average returns the average between a given carbon date and the current date
Between determines if the current instance is between two others eq Indicates if a > and < comparison should be used or <= or >=
Closest returns the closest date from the current time
CookieString formats the current time to a Cookie date format
Copy returns a new copy of the current Carbon instance
DateString return the current time in Y-m-d format
DateTimeString returns the current time in Y-m-d hh:mm:ss format
DayDateTimeString returns the current time with a day, date and time format
DaysInMonth returns the number of days in the month
DaysInYear returns the number of days in the year
DiffDurationInString returns the duration difference in string format
DiffFiltered returns the difference by the given duration using a filter
DiffForHumans returns the difference in a human readable format in the current locale. When comparing a value in the past to default now: 1 hour ago 5 months ago When comparing a value in the future to default now: 1 hour from now 5 months from now When comparing a value in the past to another value: 1 hour before 5 months before When comparing a value in the future to another value: 1 hour after 5 months after
DiffInDays returns the difference in days
DiffInDaysFiltered returns the difference in days using a filter
DiffInHours returns the difference in hours
DiffInHoursFiltered returns the difference in hours using a filter
DiffInMinutes returns the difference in minutes
DiffInMonths returns the difference in months
DiffInNights returns the difference in nights
DiffInSeconds returns the difference in seconds
DiffInWeekdays returns the difference in weekdays
DiffInWeekendDays returns the difference in weekend days using a filter
DiffInWeeks returns the difference in weeks
DiffInYears returns the difference in years
EndOfCentury returns the date of the end of the century at 23:59:59
EndOfDay returns the time at 23:59:59 of the same day
EndOfDecade returns the date at the end of the decade and time at 23:59:59
EndOfMonth returns the date at the end of the month and time at 23:59:59
EndOfQuarter returns the date at end of the quarter and time at 23:59:59
EndOfWeek returns the date of the last day of the week at 23:59:59
EndOfYear returns the date at end of the year and time to 23:59:59
Eq determines if the current carbon is equal to another
EqualTo determines if the current carbon is equal to another
Farthest returns the farthest date from the current time
FirstDayOfMonth returns a new carbon instance with the first day of current month
FirstOfMonth returns the first occurrence of a given day of the week in the current month
FirstOfQuarter returns the first occurrence of a given day of the week in the current quarter
FirstOfYear returns the first occurrence of a given day of the week in the current year
FormattedDateString returns the current time as a readable date
GetLocale returns locale of the Translator of Carbon
func (c *Carbon) GetTranslator() (*Translator, error)
GetTranslator returns Translator inside a Carbon instance if exist, otherwise it creates a new Translator with "en" as default locale
GreaterThan determines if the current carbon is greater (after) than another
GreaterThanOrEqualTo determines if the instance is greater (after) than or equal to another
Gt determines if the current carbon is greater (after) than another
Gte determines if the instance is greater (after) than or equal to another
ISO8601String returns the current time in ISO8601 format
IsCurrentMonth determines if the current time is in the current month
IsCurrentYear determines if the current time is in the current year
IsFriday checks if this day is a Friday.
IsFuture determines if the current time is in the future, ie. greater (after) than now
IsLastMonth returns true is the date is within last month
IsLastWeek returns true is the date is within last week
IsLeapYear determines if current current time is a leap year
IsLongYear determines if the instance is a long year
IsMonday checks if this day is a Monday.
IsPast determines if the current time is in the past, ie. less (before) than now
IsSameAs compares the formatted values of the two dates. If passed date is nil, compares against today
IsSameDay checks if the passed in date is the same day as the current day. If passed date is nil, compares against today
IsSameMonth checks if the passed in date is in the same month as the current month If passed date is nil, compares against today
IsSameYear checks if the passed in date is in the same year as the current time year. If passed date is nil, compares against today
IsSaturday checks if this day is a Saturday.
IsSunday checks if this day is a Sunday.
IsThursday checks if this day is a Thursday.
IsToday determines if the current time is today
IsTomorrow determines if the current time is tomorrow
IsTuesday checks if this day is a Tuesday.
IsWednesday checks if this day is a Wednesday.
IsWeekday determines if the current time is a weekday
IsWeekend determines if the current time is a weekend day
IsYesterday determines if the current time is yesterday
LastDayOfMonth returns a new carbon instance with the last day of current month
LastOfMonth returns the last occurrence of a given day of the week in the current month
LastOfQuarter returns the last occurrence of a given day of the week in the current quarter
LastOfYear returns the last occurrence of a given day of the week in the current year
LessThan determines if the instance is less (before) than another
LessThanOrEqualTo determines if the instance is less (before) or equal to another
Lt determines if the instance is less (before) than another
Lte determines if the instance is less (before) or equal to another
Max returns the maximum instance between a given instance and the current instance
Maximum returns the maximum instance between a given instance and the current instance
Min returns the minimum instance between a given instance and the current instance
Minimum returns the minimum instance between a given instance and the current instance
Ne determines if the current carbon is not equal to another
Next changes the time to the next occurrence of a given day of the week
NextWeekday goes forward to the next weekday
NextWeekendDay goes forward to the next weekend day
NotEqualTo determines if the current carbon is not equal to another
NthOfMonth returns the given occurrence of a given day of the week in the current month If the calculated occurrence is outside the scope of current month, no modifications are made
NthOfQuarter returns the given occurrence of a given day of the week in the current quarter If the calculated occurrence is outside the scope of current quarter, no modifications are made
NthOfYear returns the given occurrence of a given day of the week in the current year If the calculated occurrence is outside the scope of current year, no modifications are made
Previous changes the time to the previous occurrence of a given day of the week
PreviousMonthLastDay returns the last day of the previous month
PreviousWeekday goes back to the previous weekday
PreviousWeekendDay goes back to the previous weekend day
Quarter gets the current quarter
RFC1036String returns the current time in RFC 1036 format
RFC1123String returns the current time in RFC 1123 format
RFC2822String returns the current time in RFC 2822 format
RFC3339String returns the current time in RFC 3339 format
RFC822String returns the current time in RFC 822 format
RFC850String returns the current time in RFC 850 format
RSSString returns the current time for RSS format
ResetStringFormat changes the format to the DefaultFormat
SecondsSinceMidnight returns the number of seconds since midnight.
SecondsUntilEndOfDay returns the number of seconds until 23:59:59.
SetDate sets only the date of the current time
SetDateTime sets the date and the time
SetDay sets the day of the current time
SetHour sets the hour of the current time
SetLocale sets locale for the Translator of Carbon
SetMinute sets the minute of the current time
SetMonth sets the month of the current time
SetSecond sets the second of the current time
SetStringFormat formats the current time with the set format string
SetTimeFromTimeString receives a string and sets the current time It accepts the following formats: "hh:mm:ss", "hh:mm" and "hh"
SetTimeZone sets the location from a string If the location is invalid, it returns an error instead.
SetTimestamp sets the current time given a timestamp
func (c *Carbon) SetTranslator(t *Translator)
SetTranslator sets the Translator inside a Carbon instance
SetWeekEndsAt sets the last day of week
SetWeekStartsAt sets the first day of week
SetWeekendDays sets the weekend days
SetYear sets the year of the current time
StartOfCentury returns the date of the first day of the century at 00:00:00
StartOfDay returns the time at 00:00:00 of the same day
StartOfDecade returns the date at the first day of the decade and time at 00:00:00
StartOfMonth returns the date on the first day of the month and the time to 00:00:00
StartOfQuarter returns the date at the first day of the quarter and time at 00:00:00
StartOfWeek returns the date of the first day of week at 00:00:00
StartOfYear returns the date at the first day of the year and the time at 00:00:00
String gets the current date using the previously set format
SubCenturies removes centuries from the current time
SubCentury removes a century from the current time
SubDay removes a day from the current instance
SubDays removes days from the current time
SubHour removes an hour from the current time
SubHours removes hours from the current time
SubMinute removes a minute from the current time
SubMinutes removes minutes from the current time
SubMonth removes a month from the current time
SubMonthNoOverflow remove a month with no overflow from the current time
SubMonths removes months from the current time
SubMonthsNoOverflow removes months with no overflow from the current time
SubQuarter removes a quarter from the current time
SubQuarters removes quarters from current time
SubSecond removes a second from the current time
SubSeconds removes seconds from the current time
SubWeek removes a week from the current time
SubWeekday removes a weekday from the current time
SubWeekdays removes a weekday from the current time
SubWeeks removes weeks to the current time
SubYear removes a year from the current time
SubYears removes years from current time
TimeString returns the current time in hh:mm:ss format
TimeZone gets the current timezone
Timestamp gets the current time since January 1, 1970 UTC
W3CString returns the current time for WWW Consortium format
WeekEndsAt gets the ending day of the week
WeekOfMonth returns the week of the month
WeekOfYear returns the week of the current year. This is an alias for time.ISOWeek
WeekStartsAt get the starting day of the week
WeekendDays gets the weekend days of the week
CarbonInterval represents an interval between two carbons.
func NewCarbonInterval(start, end *Carbon) (*CarbonInterval, error)
NewCarbonInterval returns a pointer to a new CarbonInterval instance
func (ci *CarbonInterval) DiffInHours() int64
DiffInHours return the difference in hours between start and end date
Filter represents a predicate used for filtering diffs
type Translator struct {
// contains filtered or unexported fields
}Translator helps to translate time based on locale
func NewTranslator() *Translator
NewTranslator returns a initialized instance of Translator
func (t *Translator) AssertValidLocale(l string) error
AssertValidLocale checks if the locale is valid or not
func (t *Translator) GetLocale() string
GetLocale will return locale of a Translator
func (t *Translator) SetLocale(l string) error
SetLocale will set locale on a Translator
| Path | Synopsis |
|---|---|
| examples | |
| lang |
Package carbon imports 8 packages (graph) and is imported by 4 packages. Updated 2018-06-29. Refresh now. Tools for package owners.