- update
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is failing Details

master v1.0.4
李光春 2 years ago
parent f7b17917ad
commit 9f8bce0361

@ -5,13 +5,13 @@
📦 Golang 时间 📦 Golang 时间
[comment]: <> (go) [comment]: <> (go)
[![godoc](https://pkg.go.dev/badge/github.com/dtapps/gotime?status.svg)](https://pkg.go.dev/github.com/dtapps/gotime) [![godoc](https://pkg.go.dev/badge/go.dtapp.net/gotime?status.svg)](https://pkg.go.dev/go.dtapp.net/gotime)
[![goproxy.cn](https://goproxy.cn/stats/github.com/dtapps/gotime/badges/download-count.svg)](https://goproxy.cn/stats/github.com/dtapps/gotime) [![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gotime/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gotime)
[![goreportcard.com](https://goreportcard.com/badge/github.com/dtapps/gotime)](https://goreportcard.com/report/github.com/dtapps/gotime) [![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gotime)](https://goreportcard.com/report/go.dtapp.net/gotime)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/github.com%2Fdtapps%2Fgotime) [![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net%2Fgotime)
#### 安装 #### 安装
```go ```go
go get -v -u github.com/dtapps/gotime go get -v -u go.dtapp.net/gotime
``` ```

@ -1,3 +1,3 @@
module github.com/dtapps/gotime module go.dtapp.net/gotime
go 1.18 go 1.18

@ -36,42 +36,42 @@ func NewPro() Pro {
} }
// BeforeSeconds 获取n秒前的时间 // BeforeSeconds 获取n秒前的时间
func (p Pro) BeforeSeconds(seconds int) Pro { func (p Pro) BeforeSeconds(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("-%ds", seconds)) st, _ := time.ParseDuration(fmt.Sprintf("-%ds", seconds))
p.Time = p.Time.Add(st) p.Time = p.Time.Add(st)
return p return p
} }
// AfterSeconds 获取n秒后的时间 // AfterSeconds 获取n秒后的时间
func (p Pro) AfterSeconds(seconds int) Pro { func (p Pro) AfterSeconds(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("+%ds", seconds)) st, _ := time.ParseDuration(fmt.Sprintf("+%ds", seconds))
p.Time = p.Time.Add(st) p.Time = p.Time.Add(st)
return p return p
} }
// BeforeMinute 获取n分钟前的时间 // BeforeMinute 获取n分钟前的时间
func (p Pro) BeforeMinute(seconds int) Pro { func (p Pro) BeforeMinute(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("-%dm", seconds)) st, _ := time.ParseDuration(fmt.Sprintf("-%dm", seconds))
p.Time = p.Time.Add(st) p.Time = p.Time.Add(st)
return p return p
} }
// AfterMinute 获取n分钟后的时间 // AfterMinute 获取n分钟后的时间
func (p Pro) AfterMinute(seconds int) Pro { func (p Pro) AfterMinute(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("+%dm", seconds)) st, _ := time.ParseDuration(fmt.Sprintf("+%dm", seconds))
p.Time = p.Time.Add(st) p.Time = p.Time.Add(st)
return p return p
} }
// BeforeHour 获取n小时前的时间 // BeforeHour 获取n小时前的时间
func (p Pro) BeforeHour(hour int) Pro { func (p Pro) BeforeHour(hour int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("-%dh", hour)) st, _ := time.ParseDuration(fmt.Sprintf("-%dh", hour))
p.Time = p.Time.Add(st) p.Time = p.Time.Add(st)
return p return p
} }
// AfterHour 获取n小时后的时间 // AfterHour 获取n小时后的时间
func (p Pro) AfterHour(hour int) Pro { func (p Pro) AfterHour(hour int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("+%dh", hour)) st, _ := time.ParseDuration(fmt.Sprintf("+%dh", hour))
p.Time = p.Time.Add(st) p.Time = p.Time.Add(st)
return p return p
@ -95,11 +95,11 @@ func (p Pro) SetFormat(layout string) string {
} }
// Month 获取当前月 // Month 获取当前月
func (p Pro) Month() int { func (p Pro) Month() int64 {
return p.MonthOfYear() return p.MonthOfYear()
} }
// MonthOfYear 获取本年的第几月 // MonthOfYear 获取本年的第几月
func (p Pro) MonthOfYear() int { func (p Pro) MonthOfYear() int64 {
return int(p.Time.In(p.loc).Month()) return int64(p.Time.In(p.loc).Month())
} }

@ -1,3 +1,3 @@
package gotime package gotime
const Version = "1.0.3" const Version = "1.0.4"

Loading…
Cancel
Save