func (d Duration) Shrink(c context.Context) (Duration, context.Context, context.CancelFunc) {
	if deadline, ok := c.Deadline(); ok {
		if ctimeout := time.Until(deadline); ctimeout < time.Duration(d) {
			return Duration(ctimeout), c, func() {}
		}
	}
	ctx, cancel := context.WithTimeout(c, time.Duration(d))
	return d, ctx, cancel
}
Shrink will decrease the duration by comparing with context's timeout duration and return new timeout\context\CancelFunc.
package xtime
import (
	"context"
	"database/sql/driver"
	"strconv"
	"time"
)
type Time int64
func (t *Time) Scan(src interface{}) (err error) {
	switch sc := src.(type) {
	case time.Time:
		*t = Time(sc.Unix())
	case string:
		var i int64
		i, err = strconv.ParseInt(sc, 10, 64)
		*t = Time(i)
	}
	return
}
func (t Time) Value() (driver.Value, error) {
	return time.Unix(int64(t), 0), nil
}
func (t Time) Time() time.Time {
	return time.Unix(int64(t), 0)
}
func (t *Time) FromDB(bs []byte) error {
	timeStr := string(bs)
	ti, err := time.ParseInLocation("2006-01-02T15:04:05", timeStr[:19], time.Local)
	if err != nil {
		return err
	}
	*t = Time(ti.Unix())
	return nil
}
func (t Time) ToDB() ([]byte, error) {
	unix := time.Unix(int64(t), 0)
	return []byte(unix.String()), nil
}
type Duration time.Duration
func (d *Duration) UnmarshalText(text []byte) error {
	tmp, err := time.ParseDuration(string(text))
	if err == nil {
		*d = Duration(tmp)
	}
	return err
}
func (d *Duration) UnitTime() string {
	return DurationToUnit(time.Duration(*d))
}