@@ -23,19 +23,19 @@ import (
2323 "time"
2424)
2525
26- //Date Format unix time int64 to string
26+ // Date Format unix time int64 to string
2727func Date (ti int64 , format string ) string {
2828 t := time .Unix (int64 (ti ), 0 )
2929 return DateT (t , format )
3030}
3131
32- //DateS Format unix time string to string
32+ // DateS Format unix time string to string
3333func DateS (ts string , format string ) string {
3434 i , _ := strconv .ParseInt (ts , 10 , 64 )
3535 return Date (i , format )
3636}
3737
38- //DateT Format time.Time struct to string
38+ // DateT Format time.Time struct to string
3939// MM - month - 01
4040// M - month - 1, single bit
4141// DD - day - 02
@@ -104,18 +104,18 @@ var datePatterns = []string{
104104// DateFormatReplacer .
105105var DateFormatReplacer = strings .NewReplacer (datePatterns ... )
106106
107- //DateParse Parse Date use PHP time format.
107+ // DateParse Parse Date use PHP time format.
108108func DateParse (dateString , format string ) (time.Time , error ) {
109109 return time .ParseInLocation (ConvDateFormat (format ), dateString , time .Local )
110110}
111111
112- //ConvDateFormat Convert PHP time format.
112+ // ConvDateFormat Convert PHP time format.
113113func ConvDateFormat (format string ) string {
114114 format = DateFormatReplacer .Replace (format )
115115 return format
116116}
117117
118- //DateFormat 将时间戳格式化为日期字符窜
118+ // DateFormat 将时间戳格式化为日期字符窜
119119func DateFormat (format string , timestamp interface {}) (t string ) { // timestamp
120120 switch format {
121121 case "Y-m-d H:i:s" , "" :
@@ -140,7 +140,7 @@ func DateFormat(format string, timestamp interface{}) (t string) { // timestamp
140140 return
141141}
142142
143- //StrToTime 日期字符窜转为时间戳数字
143+ // StrToTime 日期字符窜转为时间戳数字
144144func StrToTime (str string , args ... string ) (unixtime int ) {
145145 layout := "2006-01-02 15:04:05"
146146 if len (args ) > 0 {
@@ -207,7 +207,7 @@ func FormatBytes(args ...interface{}) string {
207207 return r + sizeUnits [total ]
208208}
209209
210- //DateFormatShort 格式化耗时
210+ // DateFormatShort 格式化耗时
211211func DateFormatShort (timestamp interface {}) string {
212212 now := time .Now ()
213213 year := now .Year ()
@@ -334,10 +334,10 @@ func FriendlyTime(d time.Duration, args ...interface{}) (r string) {
334334 return
335335}
336336
337- //StartTime 开始时间
337+ // StartTime 开始时间
338338var StartTime = time .Now ()
339339
340- //TotalRunTime 总运行时长
340+ // TotalRunTime 总运行时长
341341func TotalRunTime () string {
342342 return FriendlyTime (time .Since (StartTime ))
343343}
@@ -545,6 +545,8 @@ func (t Time) IsAfter(timestamp interface{}, agoDays int, units ...int) bool {
545545}
546546
547547var numberSpitRule = regexp .MustCompile (`[^\d]+` )
548+ var MinYear = 1000
549+ var MaxYear = 9999
548550
549551func FixDateString (dateStr string ) string {
550552 parts := numberSpitRule .Split (dateStr , 3 )
@@ -577,7 +579,7 @@ func FixDateString(dateStr string) string {
577579 case 1 :
578580 // year
579581 year , _ := strconv .Atoi (parts [0 ])
580- if year <= 1000 || year > 9999 {
582+ if year <= MinYear || year > MaxYear {
581583 return ``
582584 }
583585 dateArr [0 ] = parts [0 ]
0 commit comments