mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
日历相关计算
This commit is contained in:
40
calendar/creator.go
Normal file
40
calendar/creator.go
Normal file
@ -0,0 +1,40 @@
|
||||
package calendar
|
||||
|
||||
import "time"
|
||||
|
||||
func Now() Calendar {
|
||||
return Create(time.Now())
|
||||
}
|
||||
|
||||
func Today() Calendar {
|
||||
return Now().BeginningOfDay()
|
||||
}
|
||||
|
||||
func Create(t time.Time) Calendar {
|
||||
return Calendar{
|
||||
Time: t,
|
||||
weekStartsAt: WeekStartDay,
|
||||
}
|
||||
}
|
||||
|
||||
func CreateFromTimestamp(timestamp int64) Calendar {
|
||||
return Create(time.Unix(timestamp, 0))
|
||||
}
|
||||
|
||||
func CreateFromTimestampMilli(timestamp int64) Calendar {
|
||||
return Create(time.Unix(timestamp/1e3, (timestamp%1e3)*1e6))
|
||||
}
|
||||
|
||||
func CreateFromTimestampMicro(timestamp int64) Calendar {
|
||||
return Create(time.Unix(timestamp/1e6, (timestamp%1e6)*1e3))
|
||||
}
|
||||
|
||||
func CreateFromTimestampNano(timestamp int64) Calendar {
|
||||
return Create(time.Unix(timestamp/1e9, timestamp%1e9))
|
||||
}
|
||||
|
||||
func create(year, month, day, hour, minute, second, nanosecond int) Calendar {
|
||||
return Calendar{
|
||||
Time: time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, time.Local),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user