1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ctx.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
urso 提交于 2016-07-22 13:15 . Add date formatter support
package dtfmt
import "time"
// ctx stores pre-computed time fields used by the formatter.
type ctx struct {
year int
month time.Month
day int
weekday time.Weekday
yearday int
isoWeek, isoYear int
hour, min, sec int
millis int
buf []byte
}
type ctxConfig struct {
date bool
clock bool
weekday bool
yearday bool
millis bool
iso bool
}
func (c *ctx) initTime(config *ctxConfig, t time.Time) {
if config.date {
c.year, c.month, c.day = t.Date()
}
if config.clock {
c.hour, c.min, c.sec = t.Clock()
}
if config.iso {
c.isoYear, c.isoWeek = t.ISOWeek()
}
if config.millis {
c.millis = t.Nanosecond() / 1000000
}
if config.yearday {
c.yearday = t.YearDay()
}
if config.weekday {
c.weekday = t.Weekday()
}
}
func (c *ctxConfig) enableDate() {
c.date = true
}
func (c *ctxConfig) enableClock() {
c.clock = true
}
func (c *ctxConfig) enableWeekday() {
c.weekday = true
}
func (c *ctxConfig) enableYearday() {
c.yearday = true
}
func (c *ctxConfig) enableISO() {
c.iso = true
}
func isLeap(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.6.13

搜索帮助