carbon

package module
Version: v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2019 License: Apache-2.0 Imports: 8 Imported by: 36

README

Carbon

Build Status Go Report Card codecov GoDoc License

A simple extension for Time based on PHP's Carbon library.

Features:

  • Time is embedded into Carbon (provides access to all of Time's functionality)
  • Supports addition and subtraction of dates
  • Provides methods to compare dates
  • Supports date formatting in common formats
  • Easily calculate difference between dates
  • Ease testing with dates by using carbon.Freeze() and carbon.Now()

To do:

  • Implement all localization features as in Carbon
  • Improve the code style to be more idiomatic Go

Getting started

Install Carbon:

go get github.com/uniplaces/carbon

Add to your imports to start using Carbon

import "github.com/uniplaces/carbon"

Examples

A simple example to get you started:

package main

import (
	"fmt"
	"time"

	"github.com/uniplaces/carbon"
)

func main() {
	fmt.Printf("Right now is %s\n", carbon.Now().DateTimeString())

	today, _ := carbon.NowInLocation("America/Vancouver")
	fmt.Printf("Right now in Vancouver is %s\n", today)

	fmt.Printf("Tomorrow is %s\n", carbon.Now().AddDay())
	fmt.Printf("Last week is %s\n", carbon.Now().SubWeek())

	nextOlympics, _ := carbon.CreateFromDate(2016, time.August, 5, "Europe/London")
	nextOlympics = nextOlympics.AddYears(4)
	fmt.Printf("Next olympics are in %d\n", nextOlympics.Year())

	if carbon.Now().IsWeekend() {
		fmt.Printf("Party time!")
	}
}

You can also check the examples/ folder for more examples.

Contributing

Please feel free to make suggestions, create issues, fork the repository and send pull requests!

Licence

Copyright 2016 UNIPLACES

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package `carbon` is an extension to Go's time library based on PHP's Carbon library

Index

Constants

View Source
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

Variables

This section is empty.

Functions

func After

func After(d time.Duration) <-chan time.Time

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

func Freeze

func Freeze(time time.Time)

Freeze allows time to be frozen to facilitate testing

func IsTimeFrozen

func IsTimeFrozen() bool

IsTimeFrozen allows checking if time has been frozen

func Sleep

func Sleep(d time.Duration)

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

func Tick

func Tick(d time.Duration) <-chan time.Time

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

func UnFreeze()

UnFreeze returns time to normal operation

Types

type Carbon

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.

func Create

func Create(y int, mon time.Month, d, h, m, s, ns int, location string) (*Carbon, error)

Create returns a new pointer to Carbon instance from a specific date and time. If the location is invalid, it returns an error instead.

func CreateFromDate

func CreateFromDate(y int, mon time.Month, d int, location string) (*Carbon, error)

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.

func CreateFromFormat

func CreateFromFormat(layout, value string, location string) (*Carbon, error)

CreateFromFormat returns a new pointer to a Carbon instance from a specific format. If the location is invalid, it returns an error instead.

func CreateFromMonthAndYear added in v0.1.3

func CreateFromMonthAndYear(y int, mon time.Month, location string) (*Carbon, error)

CreateFromMonthAndYear returns a new pointer to a Carbon instance from a specific month and year. If the location is invalid, it returns an error instead.

func CreateFromTime

func CreateFromTime(h, m, s, ns int, location string) (*Carbon, error)

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.

func CreateFromTimestamp

func CreateFromTimestamp(timestamp int64, location string) (*Carbon, error)

CreateFromTimestamp returns a new pointer to a Carbon instance from a timestamp. If the location is invalid, it returns an error instead.

func CreateFromTimestampUTC

func CreateFromTimestampUTC(timestamp int64) (*Carbon, error)

CreateFromTimestampUTC returns a new pointer to a Carbon instance from an UTC timestamp. If the location is invalid, it returns an error instead.

func MaxValue

func MaxValue() *Carbon

MaxValue returns a pointer to a new carbon instance for greatest supported date

func MinValue

func MinValue() *Carbon

MinValue returns a pointer to a new carbon instance for lowest supported date

func NewCarbon

func NewCarbon(t time.Time) *Carbon

NewCarbon returns a pointer to a new Carbon instance

func Now

func Now() *Carbon

Now returns a new Carbon instance for right now in current localtime

func NowInLocation

func NowInLocation(loc string) (*Carbon, error)

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".

func Parse

func Parse(layout, value, location string) (*Carbon, error)

Parse returns a pointer to a new carbon instance from a string If the location is invalid, it returns an error instead.

func Today

func Today(location string) (*Carbon, error)

Today returns a pointer to a new carbon instance for today If the location is invalid, it returns an error instead.

func Tomorrow

func Tomorrow(location string) (*Carbon, error)

Tomorrow returns a pointer to a new carbon instance for tomorrow If the location is invalid, it returns an error instead.

func Yesterday

func Yesterday(location string) (*Carbon, error)

Yesterday returns a pointer to a new carbon instance for yesterday If the location is invalid, it returns an error instead.

func (*Carbon) AddCenturies

func (c *Carbon) AddCenturies(cent int) *Carbon

AddCenturies adds centuries to the time. Positive values travels forward while negative values travels into the past

func (*Carbon) AddCentury

func (c *Carbon) AddCentury() *Carbon

AddCentury adds a century to the current time

func (*Carbon) AddDay

func (c *Carbon) AddDay() *Carbon

AddDay adds a day to the current time

func (*Carbon) AddDays

func (c *Carbon) AddDays(d int) *Carbon

AddDays adds a day to the current time. Positive value travels forward while negative value travels into the past

func (*Carbon) AddHour

func (c *Carbon) AddHour() *Carbon

AddHour adds an hour to the current time

func (*Carbon) AddHours

func (c *Carbon) AddHours(h int) *Carbon

AddHours adds an hour to the current time. Positive value travels forward while negative value travels into the past

func (*Carbon) AddMinute

func (c *Carbon) AddMinute() *Carbon

AddMinute adds a minute to the current time

func (*Carbon) AddMinutes

func (c *Carbon) AddMinutes(m int) *Carbon

AddMinutes adds minutes to the current time. Positive value travels forward while negative value travels into the past.

func (*Carbon) AddMonth

func (c *Carbon) AddMonth() *Carbon

AddMonth adds a month to the current time

func (*Carbon) AddMonthNoOverflow

func (c *Carbon) AddMonthNoOverflow() *Carbon

AddMonthNoOverflow adds a month with no overflow to the current time

func (*Carbon) AddMonths

func (c *Carbon) AddMonths(m int) *Carbon

AddMonths adds months to the current time. Positive value travels forward while negative values travels into the past

func (*Carbon) AddMonthsNoOverflow

func (c *Carbon) AddMonthsNoOverflow(m int) *Carbon

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.

func (*Carbon) AddQuarter

func (c *Carbon) AddQuarter() *Carbon

AddQuarter adds a quarter to the current time

func (*Carbon) AddQuarters

func (c *Carbon) AddQuarters(q int) *Carbon

AddQuarters adds quarters to the current time. Positive values travel forward while negative values travel into the past

func (*Carbon) AddSecond

func (c *Carbon) AddSecond() *Carbon

AddSecond adds a second to the time

func (*Carbon) AddSeconds

func (c *Carbon) AddSeconds(s int) *Carbon

AddSeconds adds seconds to the current time. Positive values travels forward while negative values travels into the past.

func (*Carbon) AddWeek

func (c *Carbon) AddWeek() *Carbon

AddWeek adds a week to the current time

func (*Carbon) AddWeekday

func (c *Carbon) AddWeekday() *Carbon

AddWeekday adds a weekday to the current time

func (*Carbon) AddWeekdays

func (c *Carbon) AddWeekdays(wd int) *Carbon

AddWeekdays adds a weekday to the current time. Positive value travels forward while negative value travels into the past

func (*Carbon) AddWeeks

func (c *Carbon) AddWeeks(w int) *Carbon

AddWeeks adds a week to the current time. Positive value travels forward while negative value travels into the past.

func (*Carbon) AddYear

func (c *Carbon) AddYear() *Carbon

AddYear adds a year to the current time

func (*Carbon) AddYears

func (c *Carbon) AddYears(y int) *Carbon

AddYears adds a year to the current time. Positive values travel forward while negative values travel into the past

func (*Carbon) Age

func (c *Carbon) Age() int

Age gets the age from the current instance time to now

func (*Carbon) AtomString

func (c *Carbon) AtomString() string

AtomString formats the current time to a Atom date format

func (*Carbon) Average

func (c *Carbon) Average(carb *Carbon) *Carbon

Average returns the average between a given carbon date and the current date

func (*Carbon) Between

func (c *Carbon) Between(a, b *Carbon, eq bool) bool

Between determines if the current instance is between two others eq Indicates if a > and < comparison should be used or <= or >=

func (*Carbon) Closest

func (c *Carbon) Closest(a, b *Carbon) *Carbon

Closest returns the closest date from the current time

func (*Carbon) CookieString

func (c *Carbon) CookieString() string

CookieString formats the current time to a Cookie date format

func (*Carbon) Copy

func (c *Carbon) Copy() *Carbon

Copy returns a new copy of the current Carbon instance

func (*Carbon) DateString

func (c *Carbon) DateString() string

DateString return the current time in Y-m-d format

func (*Carbon) DateTimeString

func (c *Carbon) DateTimeString() string

DateTimeString returns the current time in Y-m-d hh:mm:ss format

func (*Carbon) DayDateTimeString

func (c *Carbon) DayDateTimeString() string

DayDateTimeString returns the current time with a day, date and time format

func (*Carbon) DaysInMonth

func (c *Carbon) DaysInMonth() int

DaysInMonth returns the number of days in the month

func (*Carbon) DaysInYear

func (c *Carbon) DaysInYear() int

DaysInYear returns the number of days in the year

func (*Carbon) DiffDurationInString

func (c *Carbon) DiffDurationInString(carb *Carbon) string

DiffDurationInString returns the duration difference in string format

func (*Carbon) DiffFiltered

func (c *Carbon) DiffFiltered(duration time.Duration, f Filter, carb *Carbon, abs bool) int64

DiffFiltered returns the difference by the given duration using a filter

func (*Carbon) DiffForHumans

func (c *Carbon) DiffForHumans(d *Carbon, abs, absolute, short bool) (string, error)

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

func (*Carbon) DiffInDays

func (c *Carbon) DiffInDays(carb *Carbon, abs bool) int64

DiffInDays returns the difference in days

func (*Carbon) DiffInDaysFiltered

func (c *Carbon) DiffInDaysFiltered(f Filter, carb *Carbon, abs bool) int64

DiffInDaysFiltered returns the difference in days using a filter

func (*Carbon) DiffInHours

func (c *Carbon) DiffInHours(d *Carbon, abs bool) int64

DiffInHours returns the difference in hours

func (*Carbon) DiffInHoursFiltered

func (c *Carbon) DiffInHoursFiltered(f Filter, carb *Carbon, abs bool) int64

DiffInHoursFiltered returns the difference in hours using a filter

func (*Carbon) DiffInMinutes

func (c *Carbon) DiffInMinutes(d *Carbon, abs bool) int64

DiffInMinutes returns the difference in minutes

func (*Carbon) DiffInMonths

func (c *Carbon) DiffInMonths(carb *Carbon, abs bool) int64

DiffInMonths returns the difference in months

func (*Carbon) DiffInNights

func (c *Carbon) DiffInNights(carb *Carbon, abs bool) int64

DiffInNights returns the difference in nights

func (*Carbon) DiffInSeconds

func (c *Carbon) DiffInSeconds(carb *Carbon, abs bool) int64

DiffInSeconds returns the difference in seconds

func (*Carbon) DiffInWeekdays

func (c *Carbon) DiffInWeekdays(carb *Carbon, abs bool) int64

DiffInWeekdays returns the difference in weekdays

func (*Carbon) DiffInWeekendDays

func (c *Carbon) DiffInWeekendDays(carb *Carbon, abs bool) int64

DiffInWeekendDays returns the difference in weekend days using a filter

func (*Carbon) DiffInWeeks

func (c *Carbon) DiffInWeeks(carb *Carbon, abs bool) int64

DiffInWeeks returns the difference in weeks

func (*Carbon) DiffInYears

func (c *Carbon) DiffInYears(carb *Carbon, abs bool) int64

DiffInYears returns the difference in years

func (*Carbon) EndOfCentury

func (c *Carbon) EndOfCentury() *Carbon

EndOfCentury returns the date of the end of the century at 23:59:59

func (*Carbon) EndOfDay

func (c *Carbon) EndOfDay() *Carbon

EndOfDay returns the time at 23:59:59 of the same day

func (*Carbon) EndOfDecade

func (c *Carbon) EndOfDecade() *Carbon

EndOfDecade returns the date at the end of the decade and time at 23:59:59

func (*Carbon) EndOfMonth

func (c *Carbon) EndOfMonth() *Carbon

EndOfMonth returns the date at the end of the month and time at 23:59:59

func (*Carbon) EndOfQuarter

func (c *Carbon) EndOfQuarter() *Carbon

EndOfQuarter returns the date at end of the quarter and time at 23:59:59

func (*Carbon) EndOfWeek

func (c *Carbon) EndOfWeek() *Carbon

EndOfWeek returns the date of the last day of the week at 23:59:59

func (*Carbon) EndOfYear

func (c *Carbon) EndOfYear() *Carbon

EndOfYear returns the date at end of the year and time to 23:59:59

func (*Carbon) Eq

func (c *Carbon) Eq(carb *Carbon) bool

Eq determines if the current carbon is equal to another

func (*Carbon) EqualTo

func (c *Carbon) EqualTo(carb *Carbon) bool

EqualTo determines if the current carbon is equal to another

func (*Carbon) Farthest

func (c *Carbon) Farthest(a, b *Carbon) *Carbon

Farthest returns the farthest date from the current time

func (*Carbon) FirstDayOfMonth

func (c *Carbon) FirstDayOfMonth() *Carbon

FirstDayOfMonth returns a new carbon instance with the first day of current month

func (*Carbon) FirstOfMonth

func (c *Carbon) FirstOfMonth(wd time.Weekday) *Carbon

FirstOfMonth returns the first occurrence of a given day of the week in the current month

func (*Carbon) FirstOfQuarter

func (c *Carbon) FirstOfQuarter(wd time.Weekday) *Carbon

FirstOfQuarter returns the first occurrence of a given day of the week in the current quarter

func (*Carbon) FirstOfYear

func (c *Carbon) FirstOfYear(wd time.Weekday) *Carbon

FirstOfYear returns the first occurrence of a given day of the week in the current year

func (*Carbon) FormattedDateString

func (c *Carbon) FormattedDateString() string

FormattedDateString returns the current time as a readable date

func (*Carbon) GetLocale

func (c *Carbon) GetLocale() string

GetLocale returns locale of the Translator of Carbon

func (*Carbon) GetTranslator

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

func (*Carbon) GreaterThan

func (c *Carbon) GreaterThan(carb *Carbon) bool

GreaterThan determines if the current carbon is greater (after) than another

func (*Carbon) GreaterThanOrEqualTo

func (c *Carbon) GreaterThanOrEqualTo(carb *Carbon) bool

GreaterThanOrEqualTo determines if the instance is greater (after) than or equal to another

func (*Carbon) Gt

func (c *Carbon) Gt(carb *Carbon) bool

Gt determines if the current carbon is greater (after) than another

func (*Carbon) Gte

func (c *Carbon) Gte(carb *Carbon) bool

Gte determines if the instance is greater (after) than or equal to another

func (*Carbon) ISO8601String

func (c *Carbon) ISO8601String() string

ISO8601String returns the current time in ISO8601 format

func (*Carbon) IsCurrentMonth

func (c *Carbon) IsCurrentMonth() bool

IsCurrentMonth determines if the current time is in the current month

func (*Carbon) IsCurrentYear

func (c *Carbon) IsCurrentYear() bool

IsCurrentYear determines if the current time is in the current year

func (*Carbon) IsFriday

func (c *Carbon) IsFriday() bool

IsFriday checks if this day is a Friday.

func (*Carbon) IsFuture

func (c *Carbon) IsFuture() bool

IsFuture determines if the current time is in the future, ie. greater (after) than now

func (*Carbon) IsLastMonth

func (c *Carbon) IsLastMonth() bool

IsLastMonth returns true is the date is within last month

func (*Carbon) IsLastWeek

func (c *Carbon) IsLastWeek() bool

IsLastWeek returns true is the date is within last week

func (*Carbon) IsLeapYear

func (c *Carbon) IsLeapYear() bool

IsLeapYear determines if current current time is a leap year

func (*Carbon) IsLongYear

func (c *Carbon) IsLongYear() bool

IsLongYear determines if the instance is a long year

func (*Carbon) IsMonday

func (c *Carbon) IsMonday() bool

IsMonday checks if this day is a Monday.

func (*Carbon) IsPast

func (c *Carbon) IsPast() bool

IsPast determines if the current time is in the past, ie. less (before) than now

func (*Carbon) IsSameAs

func (c *Carbon) IsSameAs(format string, carb *Carbon) bool

IsSameAs compares the formatted values of the two dates. If passed date is nil, compares against today

func (*Carbon) IsSameDay

func (c *Carbon) IsSameDay(carb *Carbon) bool

IsSameDay checks if the passed in date is the same day as the current day. If passed date is nil, compares against today

func (*Carbon) IsSameMonth

func (c *Carbon) IsSameMonth(carb *Carbon, sameYear bool) bool

IsSameMonth checks if the passed in date is in the same month as the current month If passed date is nil, compares against today

func (*Carbon) IsSameYear

func (c *Carbon) IsSameYear(carb *Carbon) bool

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

func (*Carbon) IsSaturday

func (c *Carbon) IsSaturday() bool

IsSaturday checks if this day is a Saturday.

func (*Carbon) IsSunday

func (c *Carbon) IsSunday() bool

IsSunday checks if this day is a Sunday.

func (*Carbon) IsThursday

func (c *Carbon) IsThursday() bool

IsThursday checks if this day is a Thursday.

func (*Carbon) IsToday

func (c *Carbon) IsToday() bool

IsToday determines if the current time is today

func (*Carbon) IsTomorrow

func (c *Carbon) IsTomorrow() bool

IsTomorrow determines if the current time is tomorrow

func (*Carbon) IsTuesday

func (c *Carbon) IsTuesday() bool

IsTuesday checks if this day is a Tuesday.

func (*Carbon) IsWednesday

func (c *Carbon) IsWednesday() bool

IsWednesday checks if this day is a Wednesday.

func (*Carbon) IsWeekday

func (c *Carbon) IsWeekday() bool

IsWeekday determines if the current time is a weekday

func (*Carbon) IsWeekend

func (c *Carbon) IsWeekend() bool

IsWeekend determines if the current time is a weekend day

func (*Carbon) IsYesterday

func (c *Carbon) IsYesterday() bool

IsYesterday determines if the current time is yesterday

func (*Carbon) LastDayOfMonth

func (c *Carbon) LastDayOfMonth() *Carbon

LastDayOfMonth returns a new carbon instance with the last day of current month

func (*Carbon) LastOfMonth

func (c *Carbon) LastOfMonth(wd time.Weekday) *Carbon

LastOfMonth returns the last occurrence of a given day of the week in the current month

func (*Carbon) LastOfQuarter

func (c *Carbon) LastOfQuarter(wd time.Weekday) *Carbon

LastOfQuarter returns the last occurrence of a given day of the week in the current quarter

func (*Carbon) LastOfYear

func (c *Carbon) LastOfYear(wd time.Weekday) *Carbon

LastOfYear returns the last occurrence of a given day of the week in the current year

func (*Carbon) LessThan

func (c *Carbon) LessThan(carb *Carbon) bool

LessThan determines if the instance is less (before) than another

func (*Carbon) LessThanOrEqualTo

func (c *Carbon) LessThanOrEqualTo(carb *Carbon) bool

LessThanOrEqualTo determines if the instance is less (before) or equal to another

func (*Carbon) Lt

func (c *Carbon) Lt(carb *Carbon) bool

Lt determines if the instance is less (before) than another

func (*Carbon) Lte

func (c *Carbon) Lte(carb *Carbon) bool

Lte determines if the instance is less (before) or equal to another

func (*Carbon) Max

func (c *Carbon) Max(carb *Carbon) *Carbon

Max returns the maximum instance between a given instance and the current instance

func (*Carbon) Maximum

func (c *Carbon) Maximum(carb *Carbon) *Carbon

Maximum returns the maximum instance between a given instance and the current instance

func (*Carbon) Min

func (c *Carbon) Min(carb *Carbon) *Carbon

Min returns the minimum instance between a given instance and the current instance

func (*Carbon) Minimum

func (c *Carbon) Minimum(carb *Carbon) *Carbon

Minimum returns the minimum instance between a given instance and the current instance

func (*Carbon) Ne

func (c *Carbon) Ne(carb *Carbon) bool

Ne determines if the current carbon is not equal to another

func (*Carbon) Next

func (c *Carbon) Next(wd time.Weekday) *Carbon

Next changes the time to the next occurrence of a given day of the week

func (*Carbon) NextWeekday

func (c *Carbon) NextWeekday() *Carbon

NextWeekday goes forward to the next weekday

func (*Carbon) NextWeekendDay

func (c *Carbon) NextWeekendDay() *Carbon

NextWeekendDay goes forward to the next weekend day

func (*Carbon) NotEqualTo

func (c *Carbon) NotEqualTo(carb *Carbon) bool

NotEqualTo determines if the current carbon is not equal to another

func (*Carbon) NthOfMonth

func (c *Carbon) NthOfMonth(nth int, wd time.Weekday) *Carbon

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

func (*Carbon) NthOfQuarter

func (c *Carbon) NthOfQuarter(nth int, wd time.Weekday) *Carbon

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

func (*Carbon) NthOfYear

func (c *Carbon) NthOfYear(nth int, wd time.Weekday) *Carbon

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

func (*Carbon) Previous

func (c *Carbon) Previous(wd time.Weekday) *Carbon

Previous changes the time to the previous occurrence of a given day of the week

func (*Carbon) PreviousMonthLastDay

func (c *Carbon) PreviousMonthLastDay() *Carbon

PreviousMonthLastDay returns the last day of the previous month

func (*Carbon) PreviousWeekday

func (c *Carbon) PreviousWeekday() *Carbon

PreviousWeekday goes back to the previous weekday

func (*Carbon) PreviousWeekendDay

func (c *Carbon) PreviousWeekendDay() *Carbon

PreviousWeekendDay goes back to the previous weekend day

func (*Carbon) Quarter

func (c *Carbon) Quarter() int

Quarter gets the current quarter

func (*Carbon) RFC1036String

func (c *Carbon) RFC1036String() string

RFC1036String returns the current time in RFC 1036 format

func (*Carbon) RFC1123String

func (c *Carbon) RFC1123String() string

RFC1123String returns the current time in RFC 1123 format

func (*Carbon) RFC2822String

func (c *Carbon) RFC2822String() string

RFC2822String returns the current time in RFC 2822 format

func (*Carbon) RFC3339String

func (c *Carbon) RFC3339String() string

RFC3339String returns the current time in RFC 3339 format

func (*Carbon) RFC822String

func (c *Carbon) RFC822String() string

RFC822String returns the current time in RFC 822 format

func (*Carbon) RFC850String

func (c *Carbon) RFC850String() string

RFC850String returns the current time in RFC 850 format

func (*Carbon) RSSString

func (c *Carbon) RSSString() string

RSSString returns the current time for RSS format

func (*Carbon) ResetStringFormat

func (c *Carbon) ResetStringFormat()

ResetStringFormat changes the format to the DefaultFormat

func (*Carbon) SecondsSinceMidnight

func (c *Carbon) SecondsSinceMidnight() int

SecondsSinceMidnight returns the number of seconds since midnight.

func (*Carbon) SecondsUntilEndOfDay

func (c *Carbon) SecondsUntilEndOfDay() int

SecondsUntilEndOfDay returns the number of seconds until 23:59:59.

func (*Carbon) SetDate

func (c *Carbon) SetDate(y int, m time.Month, d int)

SetDate sets only the date of the current time

func (*Carbon) SetDateTime

func (c *Carbon) SetDateTime(y int, mon time.Month, d, h, m, s int)

SetDateTime sets the date and the time

func (*Carbon) SetDay

func (c *Carbon) SetDay(d int)

SetDay sets the day of the current time

func (*Carbon) SetHour

func (c *Carbon) SetHour(h int)

SetHour sets the hour of the current time

func (*Carbon) SetLocale

func (c *Carbon) SetLocale(l string) error

SetLocale sets locale for the Translator of Carbon

func (*Carbon) SetMinute

func (c *Carbon) SetMinute(m int)

SetMinute sets the minute of the current time

func (*Carbon) SetMonth

func (c *Carbon) SetMonth(m time.Month)

SetMonth sets the month of the current time

func (*Carbon) SetSecond

func (c *Carbon) SetSecond(s int)

SetSecond sets the second of the current time

func (*Carbon) SetStringFormat

func (c *Carbon) SetStringFormat(format string)

SetStringFormat formats the current time with the set format string

func (*Carbon) SetTimeFromTimeString

func (c *Carbon) SetTimeFromTimeString(timeString string) error

SetTimeFromTimeString receives a string and sets the current time It accepts the following formats: "hh:mm:ss", "hh:mm" and "hh"

func (*Carbon) SetTimeZone

func (c *Carbon) SetTimeZone(name string) error

SetTimeZone sets the location from a string If the location is invalid, it returns an error instead.

func (*Carbon) SetTimestamp

func (c *Carbon) SetTimestamp(sec int64)

SetTimestamp sets the current time given a timestamp

func (*Carbon) SetTranslator

func (c *Carbon) SetTranslator(t *Translator)

SetTranslator sets the Translator inside a Carbon instance

func (*Carbon) SetWeekEndsAt

func (c *Carbon) SetWeekEndsAt(wd time.Weekday)

SetWeekEndsAt sets the last day of week

func (*Carbon) SetWeekStartsAt

func (c *Carbon) SetWeekStartsAt(wd time.Weekday)

SetWeekStartsAt sets the first day of week

func (*Carbon) SetWeekendDays

func (c *Carbon) SetWeekendDays(wds []time.Weekday)

SetWeekendDays sets the weekend days

func (*Carbon) SetYear

func (c *Carbon) SetYear(y int)

SetYear sets the year of the current time

func (*Carbon) StartOfCentury

func (c *Carbon) StartOfCentury() *Carbon

StartOfCentury returns the date of the first day of the century at 00:00:00

func (*Carbon) StartOfDay

func (c *Carbon) StartOfDay() *Carbon

StartOfDay returns the time at 00:00:00 of the same day

func (*Carbon) StartOfDecade

func (c *Carbon) StartOfDecade() *Carbon

StartOfDecade returns the date at the first day of the decade and time at 00:00:00

func (*Carbon) StartOfMonth

func (c *Carbon) StartOfMonth() *Carbon

StartOfMonth returns the date on the first day of the month and the time to 00:00:00

func (*Carbon) StartOfQuarter

func (c *Carbon) StartOfQuarter() *Carbon

StartOfQuarter returns the date at the first day of the quarter and time at 00:00:00

func (*Carbon) StartOfWeek

func (c *Carbon) StartOfWeek() *Carbon

StartOfWeek returns the date of the first day of week at 00:00:00

func (*Carbon) StartOfYear

func (c *Carbon) StartOfYear() *Carbon

StartOfYear returns the date at the first day of the year and the time at 00:00:00

func (*Carbon) String

func (c *Carbon) String() string

String gets the current date using the previously set format

func (*Carbon) SubCenturies

func (c *Carbon) SubCenturies(cent int) *Carbon

SubCenturies removes centuries from the current time

func (*Carbon) SubCentury

func (c *Carbon) SubCentury() *Carbon

SubCentury removes a century from the current time

func (*Carbon) SubDay

func (c *Carbon) SubDay() *Carbon

SubDay removes a day from the current instance

func (*Carbon) SubDays

func (c *Carbon) SubDays(d int) *Carbon

SubDays removes days from the current time

func (*Carbon) SubHour

func (c *Carbon) SubHour() *Carbon

SubHour removes an hour from the current time

func (*Carbon) SubHours

func (c *Carbon) SubHours(h int) *Carbon

SubHours removes hours from the current time

func (*Carbon) SubMinute

func (c *Carbon) SubMinute() *Carbon

SubMinute removes a minute from the current time

func (*Carbon) SubMinutes

func (c *Carbon) SubMinutes(m int) *Carbon

SubMinutes removes minutes from the current time

func (*Carbon) SubMonth

func (c *Carbon) SubMonth() *Carbon

SubMonth removes a month from the current time

func (*Carbon) SubMonthNoOverflow

func (c *Carbon) SubMonthNoOverflow() *Carbon

SubMonthNoOverflow remove a month with no overflow from the current time

func (*Carbon) SubMonths

func (c *Carbon) SubMonths(m int) *Carbon

SubMonths removes months from the current time

func (*Carbon) SubMonthsNoOverflow

func (c *Carbon) SubMonthsNoOverflow(m int) *Carbon

SubMonthsNoOverflow removes months with no overflow from the current time

func (*Carbon) SubQuarter

func (c *Carbon) SubQuarter() *Carbon

SubQuarter removes a quarter from the current time

func (*Carbon) SubQuarters

func (c *Carbon) SubQuarters(q int) *Carbon

SubQuarters removes quarters from current time

func (*Carbon) SubSecond

func (c *Carbon) SubSecond() *Carbon

SubSecond removes a second from the current time

func (*Carbon) SubSeconds

func (c *Carbon) SubSeconds(s int) *Carbon

SubSeconds removes seconds from the current time

func (*Carbon) SubWeek

func (c *Carbon) SubWeek() *Carbon

SubWeek removes a week from the current time

func (*Carbon) SubWeekday

func (c *Carbon) SubWeekday() *Carbon

SubWeekday removes a weekday from the current time

func (*Carbon) SubWeekdays

func (c *Carbon) SubWeekdays(wd int) *Carbon

SubWeekdays removes a weekday from the current time

func (*Carbon) SubWeeks

func (c *Carbon) SubWeeks(w int) *Carbon

SubWeeks removes weeks to the current time

func (*Carbon) SubYear

func (c *Carbon) SubYear() *Carbon

SubYear removes a year from the current time

func (*Carbon) SubYears

func (c *Carbon) SubYears(y int) *Carbon

SubYears removes years from current time

func (*Carbon) TimeString

func (c *Carbon) TimeString() string

TimeString returns the current time in hh:mm:ss format

func (*Carbon) TimeZone

func (c *Carbon) TimeZone() string

TimeZone gets the current timezone

func (*Carbon) Timestamp

func (c *Carbon) Timestamp() int64

Timestamp gets the current time since January 1, 1970 UTC

func (*Carbon) W3CString

func (c *Carbon) W3CString() string

W3CString returns the current time for WWW Consortium format

func (*Carbon) WeekEndsAt

func (c *Carbon) WeekEndsAt() time.Weekday

WeekEndsAt gets the ending day of the week

func (*Carbon) WeekOfMonth

func (c *Carbon) WeekOfMonth() int

WeekOfMonth returns the week of the month

func (*Carbon) WeekOfYear

func (c *Carbon) WeekOfYear() (int, int)

WeekOfYear returns the week of the current year. This is an alias for time.ISOWeek

func (*Carbon) WeekStartsAt

func (c *Carbon) WeekStartsAt() time.Weekday

WeekStartsAt get the starting day of the week

func (*Carbon) WeekendDays

func (c *Carbon) WeekendDays() []time.Weekday

WeekendDays gets the weekend days of the week

type CarbonInterval

type CarbonInterval struct {
	Start *Carbon
	End   *Carbon
}

CarbonInterval represents an interval between two carbons.

func NewCarbonInterval

func NewCarbonInterval(start, end *Carbon) (*CarbonInterval, error)

NewCarbonInterval returns a pointer to a new CarbonInterval instance

func (*CarbonInterval) DiffInHours

func (ci *CarbonInterval) DiffInHours() int64

DiffInHours return the difference in hours between start and end date

type Filter

type Filter func(*Carbon) bool

Filter represents a predicate used for filtering diffs

type Translator

type Translator struct {
	// contains filtered or unexported fields
}

Translator helps to translate time based on locale

func NewTranslator

func NewTranslator() *Translator

NewTranslator returns a initialized instance of Translator

func (*Translator) AssertValidLocale

func (t *Translator) AssertValidLocale(l string) error

AssertValidLocale checks if the locale is valid or not

func (*Translator) GetLocale

func (t *Translator) GetLocale() string

GetLocale will return locale of a Translator

func (*Translator) SetLocale

func (t *Translator) SetLocale(l string) error

SetLocale will set locale on a Translator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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