mysqltime

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateFormat     = "2006-01-02"
	DatetimeFormat = "2006-01-02 15:04:05"
	TimeFormat     = "15:04:05"
	YearFormat     = "2006"
)

The string formats.

View Source
const (
	ZeroDate     = "0000-00-00"
	ZeroDatetime = "0000-00-00 00:00:00"
	ZeroTime     = "00:00:00"
	ZeroYear     = "0000"
)

The zero strings.

Variables

View Source
var (
	ErrDateParse     = errors.New("Invalid Date string.")
	ErrDateRange     = errors.New("Invalid Date range.")
	ErrDateScan      = errors.New("Unable to convert value to a Date.")
	ErrDatetimeParse = errors.New("Invalid Datetime string.")
	ErrDatetimeRange = errors.New("Invalid Datetime range.")
	ErrDatetimeScan  = errors.New("Unable to convert value to a Datetime.")
	ErrTimeParse     = errors.New("Invalid Time string.")
	ErrTimeRange     = errors.New("Invalid Time range.")
	ErrTimeScan      = errors.New("Unable to convert value to a Time.")
	ErrYearParse     = errors.New("Invalid Year string.")
	ErrYearRange     = errors.New("Invalid Year range.")
	ErrYearScan      = errors.New("Unable to convert value to a Year.")
)

Common errors.

Functions

This section is empty.

Types

type Date

type Date time.Time

Date represents a date. Dates are location independent.

func NewDate

func NewDate(year int, month time.Month, day int) (d Date, err error)

NewDate creates a new date using the given year, month, and day. The year must lie in the range 1000 to 9999, inclusive, or all arguments must be 0.

func ParseDate

func ParseDate(value string) (d Date, err error)

ParseDate converts the string format "YYYY-MM-DD" to a Date. Leading and trailing spaces are ignored.

func (Date) After

func (d Date) After(u Date) bool

After returns true iff the date d is after u.

func (Date) Before

func (d Date) Before(u Date) bool

Before returns true iff the date d is before u.

func (Date) Date

func (d Date) Date() (int, time.Month, int)

Date returns the components of the date.

func (Date) Day

func (d Date) Day() int

Day returns the day.

func (Date) Equal

func (d Date) Equal(u Date) bool

Equal returns true iff the date d is equal to u.

func (Date) IsZero

func (d Date) IsZero() bool

IsZero return true if the date is outside the supported range.

func (Date) Local

func (d Date) Local() time.Time

Local converts the Date to time.Time using Local location

func (Date) Month

func (d Date) Month() time.Month

Month returns the month.

func (*Date) Scan

func (d *Date) Scan(src interface{}) (err error)

Scan assigns a value to this Date from a database driver. The src value should be one of the types defined in the sql.Scanner interface.

func (Date) String

func (d Date) String() string

String returns the Date in the format "YYYY-MM-DD".

func (Date) Time

func (d Date) Time(loc *time.Location) (t time.Time)

Time converts the Date to time.Time using the given location.

func (Date) Value

func (d Date) Value() (driver.Value, error)

Value returns the Date as a driver.Value, satisfying the driver.Valuer interface.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday returns the weekday.

func (Date) Year

func (d Date) Year() int

Year returns the year.

func (Date) YearDay

func (d Date) YearDay() int

YearDay returns the day of the year in the range [1,365] for non-leap years, and [1,366] in leap years. Returns 0 if this is the zero date.

type Datetime

type Datetime time.Time

Datetime represents a datetime. Datetimes are location independent.

func NewDatetime

func NewDatetime(year int, month time.Month, day int, hour int, min int, sec int) (t Datetime, err error)

NewDatetime creates a new datetime using the given data. The year must lie in the range 1000 to 9999, inclusive, or all arguments must be 0.

func ParseDatetime

func ParseDatetime(value string) (t Datetime, err error)

ParseDatetime converts the string format "YYYY-MM-DD hh:mm:ss" to a Datetime. Leading and trailing spaces are ignored.

func TimeToDatetime

func TimeToDatetime(t time.Time) Datetime

TimeToDatetime creates a new datetime using the given time.Time. The year, month, etc. are read from the time.Time using its defined location.

func (Datetime) After

func (t Datetime) After(u Datetime) bool

After returns true iff the datetime t is after u.

func (Datetime) Before

func (t Datetime) Before(u Datetime) bool

Before returns true iff the datetime t is before u.

func (Datetime) Clock

func (t Datetime) Clock() (int, int, int)

Clock returns the hour, minute, and second of the datetime.

func (Datetime) Date

func (t Datetime) Date() (int, time.Month, int)

Date returns the year, month, and day of the datetime.

func (Datetime) Day

func (t Datetime) Day() int

Day returns the day.

func (Datetime) Equal

func (t Datetime) Equal(u Datetime) bool

Equal returns true iff the datetime t is equal to u.

func (Datetime) Hour

func (t Datetime) Hour() int

Hour returns the hour.

func (Datetime) IsZero

func (t Datetime) IsZero() bool

IsZero return true if the datetime is outside the supported range.

func (Datetime) Local

func (t Datetime) Local() time.Time

Local converts the Datetime to time.Time using Local location.

func (Datetime) Minute

func (t Datetime) Minute() int

Minute returns the minute.

func (Datetime) Month

func (t Datetime) Month() time.Month

Month returns the month.

func (*Datetime) Scan

func (t *Datetime) Scan(src interface{}) (err error)

Scan assigns a value to this Datetime from a database driver. The src value should be one of the types defined in the sql.Scanner interface.

func (Datetime) Second

func (t Datetime) Second() int

Second returns the second.

func (Datetime) String

func (t Datetime) String() string

String returns a string representation of the datetime

func (Datetime) Time

func (t Datetime) Time(loc *time.Location) (tt time.Time)

Time converts the Datetime to time.Time using the given location.

func (Datetime) Value

func (t Datetime) Value() (driver.Value, error)

Value returns the datetime as a driver.Value, satisfying the driver.Valuer interface.

func (Datetime) Weekday

func (t Datetime) Weekday() time.Weekday

Weekday returns the weekday.

func (Datetime) Year

func (t Datetime) Year() int

Year returns the year.

func (Datetime) YearDay

func (t Datetime) YearDay() int

YearDay returns the day of the year in the range [1,365] for non-leap years, and [1,366] in leap years. Returns 0 if this is the zero date.

type Time

type Time time.Duration

Time represents a duration of time.

func DurationToTime

func DurationToTime(d time.Duration) (t Time, err error)

DurationToTime creates a new time from the given duration.

func NewTime

func NewTime(hour int, min int, sec int) (t Time, err error)

NewTime creates a new time using the given data. The number of hours must lie in the range -838 to 838, inclusive.

func ParseTime

func ParseTime(value string) (t Time, err error)

ParseTime converts the string format "[+-]h+:mm:ss" to a Time. Leading and trailing spaces are ignored.

func (Time) After

func (t Time) After(u Time) bool

After returns true iff the time t is after u.

func (Time) Before

func (t Time) Before(u Time) bool

Before returns true iff the time t is before u.

func (Time) Clock

func (t Time) Clock() (int, int, int)

Clock returns the hour, minute, and second of the time.

func (Time) Duration

func (t Time) Duration() time.Duration

Duration converts the Time to time.Duration.

func (Time) Equal

func (t Time) Equal(u Time) bool

Equal returns true iff the time t is equal to u.

func (Time) Hour

func (t Time) Hour() int

Hour returns the hour.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero return true if the time is zero.

func (Time) Local

func (t Time) Local() time.Time

Local converts the Time to time.Time using Local location.

func (Time) Minute

func (t Time) Minute() int

Minute returns the minute.

func (*Time) Scan

func (t *Time) Scan(src interface{}) (err error)

Scan assigns a value to this Time from a database driver. The src value should be one of the types defined in the sql.Scanner interface.

func (Time) Second

func (t Time) Second() int

Second returns the second.

func (Time) String

func (t Time) String() string

String returns a string representation of the time.

func (Time) Time

func (t Time) Time(loc *time.Location) time.Time

Time converts the Time to time.Time using the given location.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value returns the time as a driver.Value, satisfying the driver.Valuer interface.

type Year

type Year int

Year represents a year. Years are location independent.

func NewYear

func NewYear(year int) (y Year, err error)

NewYear creates a new year. The year must lie in the range 1901 to 2155, inclusive, or be 0.

func ParseYear

func ParseYear(value string) (y Year, err error)

ParseYear converts the string to a Year. Leading and trailing spaces are ignored.

func (Year) After

func (y Year) After(u Year) bool

After returns true iff the year y is after u.

func (Year) Before

func (y Year) Before(u Year) bool

Before returns true iff the year y is before u.

func (Year) Equal

func (y Year) Equal(u Year) bool

Equal returns true iff the year y is equal to u.

func (Year) IsZero

func (y Year) IsZero() bool

IsZero return true if the year is outside the supported range.

func (Year) Local

func (y Year) Local() time.Time

Local converts the Year to time.Time using Local location

func (*Year) Scan

func (y *Year) Scan(src interface{}) (err error)

Scan assigns a value to this Year from a database driver. The src value should be one of the types defined in the sql.Scanner interface.

func (Year) String

func (y Year) String() string

String returns the Year in the format "YYYY".

func (Year) Time

func (y Year) Time(loc *time.Location) (t time.Time)

Time converts the Year to time.Time using the given location.

func (Year) Value

func (y Year) Value() (driver.Value, error)

Value returns the Year as a driver.Value, satisfying the driver.Valuer interface.

func (Year) Year

func (y Year) Year() int

Year returns the year.

Jump to

Keyboard shortcuts

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