types

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0, MIT, MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnspecifiedFsp is the unspecified fractional seconds part.
	UnspecifiedFsp = int8(-1)
	// MaxFsp is the maximum digit of fractional seconds part.
	MaxFsp = int8(6)
	// MinFsp is the minimum digit of fractional seconds part.
	MinFsp = int8(0)
	// DefaultFsp is the default digit of fractional seconds part.
	// MySQL use 0 as the default Fsp.
	DefaultFsp = int8(0)
)
View Source
const (
	TypeUnspecified byte = 0
	TypeTiny        byte = 1
	TypeShort       byte = 2
	TypeLong        byte = 3
	TypeFloat       byte = 4
	TypeDouble      byte = 5
	TypeNull        byte = 6
	TypeTimestamp   byte = 7
	TypeLonglong    byte = 8
	TypeInt24       byte = 9
	TypeDate        byte = 10
	/* TypeDuration original name was TypeTime, renamed to TypeDuration to resolve the conflict with Go type Time.*/
	TypeDuration byte = 11
	TypeDatetime byte = 12
	TypeYear     byte = 13
	TypeNewDate  byte = 14
	TypeVarchar  byte = 15
	TypeBit      byte = 16

	TypeJSON       byte = 0xf5
	TypeNewDecimal byte = 0xf6
	TypeEnum       byte = 0xf7
	TypeSet        byte = 0xf8
	TypeTinyBlob   byte = 0xf9
	TypeMediumBlob byte = 0xfa
	TypeLongBlob   byte = 0xfb
	TypeBlob       byte = 0xfc
	TypeVarString  byte = 0xfd
	TypeString     byte = 0xfe
	TypeGeometry   byte = 0xff
)

MySQL type information.

Variables

View Source
var ZeroCoreTime = CoreTime(0)

ZeroCoreTime is the zero value for TimeInternal type.

View Source
var (

	// ZeroCoreTime is the zero value for Time type.
	ZeroTime = Time{}
)

Zero values for different types.

Functions

func AddDate

func AddDate(year, month, day int64, ot gotime.Time) (nt gotime.Time)

AddDate fix gap between mysql and golang api When we execute select date_add('2018-01-31',interval 1 month) in mysql we got 2018-02-28 but in tidb we got 2018-03-03. Dig it and we found it's caused by golang api time.Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time , it says October 32 converts to November 1 ,it conflicts with mysql. See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-add

func DateDiff

func DateDiff(startTime, endTime CoreTime) int

DateDiff calculates number of days between two days.

func GetLastDay

func GetLastDay(year, month int) int

GetLastDay returns the last day of the month

Types

type CoreTime

type CoreTime uint64

CoreTime is the internal struct type for Time.

func FromDate

func FromDate(year int, month int, day int, hour int, minute int, second int, microsecond int) CoreTime

FromDate makes a internal time representation from the given date.

func FromGoTime

func FromGoTime(t gotime.Time) CoreTime

FromGoTime translates time.Time to mysql time internal representation.

func (CoreTime) Day

func (t CoreTime) Day() int

Day returns the day value.

func (CoreTime) GoTime

func (t CoreTime) GoTime(loc *gotime.Location) (gotime.Time, error)

GoTime converts Time to GoTime.

func (CoreTime) Hour

func (t CoreTime) Hour() int

Hour returns the hour value.

func (CoreTime) IsLeapYear

func (t CoreTime) IsLeapYear() bool

IsLeapYear returns if it's leap year.

func (CoreTime) Microsecond

func (t CoreTime) Microsecond() int

Microsecond returns the microsecond value.

func (CoreTime) Minute

func (t CoreTime) Minute() int

Minute returns the minute value.

func (CoreTime) Month

func (t CoreTime) Month() int

Month returns the month value.

func (CoreTime) Second

func (t CoreTime) Second() int

Second returns the second value.

func (CoreTime) String

func (t CoreTime) String() string

String implements fmt.Stringer.

func (CoreTime) Week

func (t CoreTime) Week(mode int) int

Week returns week value.

func (CoreTime) Weekday

func (t CoreTime) Weekday() gotime.Weekday

Weekday returns weekday value.

func (CoreTime) Year

func (t CoreTime) Year() int

Year returns the year value.

func (CoreTime) YearDay

func (t CoreTime) YearDay() int

YearDay returns year and day.

func (CoreTime) YearWeek

func (t CoreTime) YearWeek(mode int) (year int, week int)

YearWeek returns year and week.

type Time

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

Time is the struct for handling datetime, timestamp and date.

func NewTime

func NewTime(coreTime CoreTime, tp uint8, fsp int8) Time

NewTime constructs time from core time, type and fsp.

func (Time) Compare

func (t Time) Compare(o Time) int

Compare returns an integer comparing the time instant t to o. If t is after o, returns 1, equal o, returns 0, before o, returns -1.

Jump to

Keyboard shortcuts

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