Documentation
¶
Overview ¶
Package carbon is a small ergonomic wrapper around time.Time modelled on Laravel's Carbon helper.
The standard library is already excellent — this package only adds the methods callers tend to wish stdlib had: human-readable diffs, boundary helpers (StartOfDay, EndOfMonth, …), Parse with multiple layouts, and chainable Add helpers.
A Carbon is just `time.Time` with methods, so callers can drop in any place a stdlib time is accepted:
t := carbon.Now() t = t.AddDays(7).StartOfDay() fmt.Println(t.DiffForHumans(carbon.Now())) // "1 week from now"
Index ¶
- Variables
- type Carbon
- func (c Carbon) Add(d time.Duration) Carbon
- func (c Carbon) AddDays(n int) Carbon
- func (c Carbon) AddHours(n int) Carbon
- func (c Carbon) AddMinutes(n int) Carbon
- func (c Carbon) AddMonths(n int) Carbon
- func (c Carbon) AddSeconds(n int) Carbon
- func (c Carbon) AddWeeks(n int) Carbon
- func (c Carbon) AddYears(n int) Carbon
- func (c Carbon) After(o Carbon) bool
- func (c Carbon) Before(o Carbon) bool
- func (c Carbon) Date() string
- func (c Carbon) DateTime() string
- func (c Carbon) DiffForHumans(o Carbon) string
- func (c Carbon) DiffInDays(o Carbon) int
- func (c Carbon) EndOfDay() Carbon
- func (c Carbon) EndOfMonth() Carbon
- func (c Carbon) EndOfYear() Carbon
- func (c Carbon) Equal(o Carbon) bool
- func (c Carbon) Format(layout string) string
- func (c Carbon) ISO8601() string
- func (c Carbon) IsFuture() bool
- func (c Carbon) IsPast() bool
- func (c Carbon) IsToday() bool
- func (c Carbon) IsZero() bool
- func (c Carbon) StartOfDay() Carbon
- func (c Carbon) StartOfMonth() Carbon
- func (c Carbon) StartOfYear() Carbon
- func (c Carbon) Sub(o Carbon) time.Duration
- func (c Carbon) SubDays(n int) Carbon
- func (c Carbon) SubMonths(n int) Carbon
- func (c Carbon) SubYears(n int) Carbon
- func (c Carbon) Time() time.Time
Constants ¶
This section is empty.
Variables ¶
var ParseLayouts = []string{ time.RFC3339Nano, time.RFC3339, "2006-01-02 15:04:05", "2006-01-02T15:04:05", "2006-01-02", "02/01/2006", "01/02/2006", }
ParseLayouts is the list of layouts Parse tries in order. The default set covers the common shapes lagodev apps see: RFC3339, SQL datetime, plain date, and ISO date.
Functions ¶
This section is empty.
Types ¶
type Carbon ¶
type Carbon struct {
// contains filtered or unexported fields
}
Carbon wraps time.Time. The zero value is a zero Carbon (use IsZero to check).
func (Carbon) AddMinutes ¶
func (Carbon) AddSeconds ¶
func (Carbon) DiffForHumans ¶
DiffForHumans renders a relative description of (c - o):
"5 seconds ago" "3 minutes from now" "1 hour ago" "2 days from now"
func (Carbon) DiffInDays ¶
DiffInDays returns the difference in calendar days (rounded toward zero) between c and o (c - o).
func (Carbon) EndOfMonth ¶
EndOfMonth returns the last instant of the month.
func (Carbon) StartOfDay ¶
StartOfDay sets the time to 00:00:00 on the same day.
func (Carbon) StartOfMonth ¶
StartOfMonth sets the time to the first day of the month at 00:00.
func (Carbon) StartOfYear ¶
StartOfYear sets the time to Jan 1 00:00 in the same year.