Skip to content

Commit

Permalink
add english docs
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Feb 19, 2024
1 parent bce146b commit c47bf87
Show file tree
Hide file tree
Showing 29 changed files with 1,512 additions and 206 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var datetimeString string = datebin.FromDatetime(2024, 01, 15, 23, 35, 01).ToDat
// output: 2024-01-15 23:35:01
~~~

more docs and see [docs](example.md)
more docs and see [docs](docs.md)


### LICENSE
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var datetimeString string = datebin.FromDatetime(2024, 01, 15, 23, 35, 01).ToDat
// 输出: 2024-01-15 23:35:01
~~~

更多示例可点击查看 [使用文档](example.md)
更多示例可点击查看 [使用文档](docs_cn.md)


### 开源协议
Expand Down
12 changes: 7 additions & 5 deletions datebin/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

// 时间常量
// time const
const (
// 皮秒[ps] [Picosecond = Nanosecond * 0.001]
Picosecond = time.Nanosecond / 1000
Expand All @@ -27,7 +28,7 @@ const (
)

// 时区常量
// const timezones
// timezones const
const (
Local = "Local"
CET = "CET"
Expand Down Expand Up @@ -87,7 +88,7 @@ const (
)

// 周常量
// const week
// week const
const (
Monday = "Monday"
Tuesday = "Tuesday"
Expand All @@ -99,7 +100,7 @@ const (
)

// 月份常量
// const month
// month const
const (
January = "January" // 一月
February = "February" // 二月
Expand All @@ -116,7 +117,7 @@ const (
)

// 数字常量
// const types
// types const
const (
YearsPerMillennium = 1000 // 每千年1000年
YearsPerCentury = 100 // 每世纪100年
Expand Down Expand Up @@ -144,7 +145,7 @@ const (
)

// 时间格式化常量
// const formats
// formats const
const (
AnsicFormat = time.ANSIC
UnixDateFormat = time.UnixDate
Expand All @@ -162,6 +163,7 @@ const (
StampMilliFormat = time.StampMilli
StampMicroFormat = time.StampMicro
StampNanoFormat = time.StampNano
W3CFormat = RFC3339Format
RFC3339MilliFormat = "2006-01-02T15:04:05.999Z07:00"
RFC3339MicroFormat = "2006-01-02T15:04:05.999999Z07:00"
RFC3339NanoFormat = "2006-01-02T15:04:05.999999999Z07:00"
Expand Down
2 changes: 2 additions & 0 deletions datebin/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

// 实现 sql.Scanner 接口,Scan 将 value 填充进结构体
// sql.Scanner interface
func (this *Datebin) Scan(value any) error {
data, ok := value.(time.Time)
if ok {
Expand All @@ -19,6 +20,7 @@ func (this *Datebin) Scan(value any) error {
}

// 实现 driver.Valuer 接口,Value 返回数据
// driver.Valuer interface
func (this Datebin) Value() (driver.Value, error) {
if this.IsZero() {
return nil, nil
Expand Down
23 changes: 14 additions & 9 deletions datebin/datebin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

var (
// 解析的格式字符
// parse format list
PaseFormats = map[string]string{
"D": "Mon",
"d": "02",
Expand Down Expand Up @@ -42,6 +43,7 @@ var (
}

// 输出的格式字符
// output format list
ToFormats = map[string]string{
"D": "Mon",
"d": "02",
Expand Down Expand Up @@ -73,6 +75,7 @@ var (
}

// 月份
// Month list
Months = map[int]time.Month{
1: time.January,
2: time.February,
Expand All @@ -89,6 +92,7 @@ var (
}

// 周列表
// Weekday list
Weekdays = []string{
"Sunday",
"Monday",
Expand All @@ -101,10 +105,11 @@ var (
)

// 默认
// default Datebin
var defaultDatebin = NewDatebin()

/**
* 日期
* 日期 / Datebin
*
* @create 2022-3-6
* @author deatil
Expand All @@ -123,21 +128,21 @@ type Datebin struct {
Errors []error
}

// 构造函数 / NewDatebin
// New Datebin
func NewDatebin() Datebin {
return Datebin{
loc: time.Local,
weekStartAt: time.Monday,
}
}

// 构造函数 / New
// New Datebin
func New() Datebin {
return NewDatebin()
}

// 设置时间
// With Time
// set Time
func (this Datebin) WithTime(time time.Time) Datebin {
this.time = time
return this
Expand All @@ -150,7 +155,7 @@ func (this Datebin) GetTime() time.Time {
}

// 设置周开始时间
// With Start Week
// set Start Week
func (this Datebin) WithWeekStartAt(weekday time.Weekday) Datebin {
this.weekStartAt = weekday
return this
Expand All @@ -163,7 +168,7 @@ func (this Datebin) GetWeekStartAt() time.Weekday {
}

// 设置时区
// With Location struct
// set Location struct
func (this Datebin) WithLocation(loc *time.Location) Datebin {
this.loc = loc
return this
Expand Down Expand Up @@ -201,7 +206,7 @@ func SetTimezone(timezone string) {
}

// 获取时区 Zone 名称
// GetTimezone
// Get Timezone string
func (this Datebin) GetTimezone() string {
name, _ := this.time.Zone()
return name
Expand Down Expand Up @@ -237,14 +242,14 @@ func (this Datebin) FixedZone(name string, offset int) Datebin {
}

// 覆盖错误信息
// WithErrors
// set Errors
func (this Datebin) WithErrors(errs []error) Datebin {
this.Errors = errs
return this
}

// 获取错误信息
// GetErrors
// Get Errors
func (this Datebin) GetErrors() []error {
return this.Errors
}
Expand Down
1 change: 1 addition & 0 deletions datebin/diff.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datebin

// 相差时间判断
// get DiffTime struct
func (this Datebin) Diff(date Datebin) DiffTime {
return NewDiffTime(this, date)
}
25 changes: 22 additions & 3 deletions datebin/formatter.go
Original file line number Diff line number Diff line change
@@ -1,90 +1,102 @@
package datebin

/**
* 格式化时间
* 格式化时间 / Formatter time
*
* @create 2022-12-11
* @author deatil
*/
type Formatter struct {
// 传入的时间
// 传入的时间 / input time
time int64
}

// 构造函数
// New Formatter
func NewFormatter() Formatter {
return Formatter{}
}

// 设置时间
// set Time
func (this Formatter) WithTime(data int64) Formatter {
this.time = data

return this
}

// 获取时间
// Get Time
func (this Formatter) GetTime() int64 {
return this.time
}

// 传入周
// set Week
func (this Formatter) FromWeek(data int64) Formatter {
this.time = data * int64(Day) * 7

return this
}

// 传入天
// set Day
func (this Formatter) FromDay(data int64) Formatter {
this.time = data * int64(Day)

return this
}

// 传入小时
// set Hour
func (this Formatter) FromHour(data int64) Formatter {
this.time = data * int64(Hour)

return this
}

// 传入分钟
// set Minute
func (this Formatter) FromMinute(data int64) Formatter {
this.time = data * int64(Minute)

return this
}

// 传入秒
// set Second
func (this Formatter) FromSecond(data int64) Formatter {
this.time = data * int64(Second)

return this
}

// 传入毫秒
// set Millisecond
func (this Formatter) FromMillisecond(data int64) Formatter {
this.time = data * int64(Millisecond)

return this
}

// 传入微秒
// set Microsecond
func (this Formatter) FromMicrosecond(data int64) Formatter {
this.time = data * int64(Microsecond)

return this
}

// 传入纳秒
// set Nanosecond
func (this Formatter) FromNanosecond(data int64) Formatter {
this.time = data

return this
}

// 获取周数和天数
// get Week And Day
func (this Formatter) WeekAndDay() (int, int) {
weeks := this.time / int64(Week)
days := (this.time % int64(Week)) / int64(Day)
Expand All @@ -93,50 +105,57 @@ func (this Formatter) WeekAndDay() (int, int) {
}

// 获取天
// get Day
func (this Formatter) Day() int {
data := this.time / int64(Day)

return int(data)
}

// 获取小时
// get Hour
func (this Formatter) Hour() int {
data := (this.time % int64(Day)) / int64(Hour)

return int(data)
}

// 获取分钟
// get Minute
func (this Formatter) Minute() int {
data := (this.time % int64(Hour)) / int64(Minute)

return int(data)
}

// 获取秒
// get Second
func (this Formatter) Second() int {
data := (this.time % int64(Minute)) / int64(Second)

return int(data)
}

// 获取毫秒
// get Millisecond
func (this Formatter) Millisecond() int {
data := (this.time % int64(Second)) / int64(Millisecond)

return int(data)
}

// 获取微秒
// get Microsecond
func (this Formatter) Microsecond() int {
data := (this.time % int64(Millisecond)) / int64(Microsecond)

return int(data)
}

// 获取纳秒
// get Nanosecond
func (this Formatter) Nanosecond() int {
// 余数
// 余数 / mod
data := this.time % int64(Microsecond)

return int(data)
Expand Down
Loading

0 comments on commit c47bf87

Please sign in to comment.