mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-04-14 21:55:17 +08:00
实现基础的智能调度
This commit is contained in:
@@ -2,6 +2,7 @@ package shared
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -41,6 +42,45 @@ func (this *TimeDuration) Duration() time.Duration {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *TimeDuration) Seconds() int64 {
|
||||
switch this.Unit {
|
||||
case TimeDurationUnitMS:
|
||||
return this.Count / 1000
|
||||
case TimeDurationUnitSecond:
|
||||
return this.Count
|
||||
case TimeDurationUnitMinute:
|
||||
return this.Count * 60
|
||||
case TimeDurationUnitHour:
|
||||
return this.Count * 3600
|
||||
case TimeDurationUnitDay:
|
||||
return this.Count * 3600 * 24
|
||||
case TimeDurationUnitWeek:
|
||||
return this.Count * 3600 * 24 * 7
|
||||
default:
|
||||
return this.Count
|
||||
}
|
||||
}
|
||||
|
||||
func (this *TimeDuration) Description() string {
|
||||
var countString = types.String(this.Count)
|
||||
switch this.Unit {
|
||||
case TimeDurationUnitMS:
|
||||
return countString + "毫秒"
|
||||
case TimeDurationUnitSecond:
|
||||
return countString + "秒"
|
||||
case TimeDurationUnitMinute:
|
||||
return countString + "分钟"
|
||||
case TimeDurationUnitHour:
|
||||
return countString + "小时"
|
||||
case TimeDurationUnitDay:
|
||||
return countString + "天"
|
||||
case TimeDurationUnitWeek:
|
||||
return countString + "周"
|
||||
default:
|
||||
return countString + "秒"
|
||||
}
|
||||
}
|
||||
|
||||
func (this *TimeDuration) AsJSON() ([]byte, error) {
|
||||
return json.Marshal(this)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user