mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix(scheduledtask): format time from utc_offset
This commit is contained in:
@@ -41,6 +41,7 @@ func init() {
|
||||
ScheduledType string `help:"scheduled type" choices:"timing|cycle"`
|
||||
ResourceType string `help:"resource type"`
|
||||
Operation string `help:"operation"`
|
||||
UtcOffset int `help:"utc offset"`
|
||||
}
|
||||
R(&ScheduledTaskListOptions{}, "scheduledtask-list", "list Scheduled Task", func(s *mcclient.ClientSession, args *ScheduledTaskListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
|
||||
@@ -118,11 +118,13 @@ func (stm *SScheduledTaskManager) FetchCustomizeColumns(
|
||||
fields stringutils2.SSortedStrings,
|
||||
isList bool,
|
||||
) []api.ScheduledTaskDetails {
|
||||
utcOffset, _ := query.Int("utc_offset")
|
||||
zone := time.FixedZone("UTC", int(utcOffset)*3600)
|
||||
rows := make([]api.ScheduledTaskDetails, len(objs))
|
||||
virRows := stm.SVirtualResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
var err error
|
||||
for i := range rows {
|
||||
rows[i], err = objs[i].(*SScheduledTask).getMoreDetails(ctx, userCred, query, isList)
|
||||
rows[i], err = objs[i].(*SScheduledTask).getMoreDetails(ctx, userCred, query, isList, zone)
|
||||
if err != nil {
|
||||
log.Errorf("SScheduledTask.getMoreDetails error: %s", err)
|
||||
}
|
||||
@@ -131,7 +133,7 @@ func (stm *SScheduledTaskManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
func (st *SScheduledTask) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.ScheduledTaskDetails, error) {
|
||||
func (st *SScheduledTask) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool, zone *time.Location) (api.ScheduledTaskDetails, error) {
|
||||
var out api.ScheduledTaskDetails
|
||||
switch st.ScheduledType {
|
||||
case api.ST_TYPE_TIMING:
|
||||
@@ -139,7 +141,7 @@ func (st *SScheduledTask) getMoreDetails(ctx context.Context, userCred mcclient.
|
||||
case api.ST_TYPE_CYCLE:
|
||||
out.CycleTimer = st.STimer.CycleTimerDetails()
|
||||
}
|
||||
out.TimerDesc = st.Description(ctx)
|
||||
out.TimerDesc = st.Description(ctx, zone)
|
||||
// fill label
|
||||
stLabels, err := st.STLabels()
|
||||
if err != nil {
|
||||
|
||||
@@ -172,13 +172,13 @@ func init() {
|
||||
timerDescTable.Set("timerLang", i18n.NewTableEntry().EN("en").CN("cn"))
|
||||
}
|
||||
|
||||
func (st *STimer) Description(ctx context.Context) string {
|
||||
func (st *STimer) Description(ctx context.Context, zone *time.Location) string {
|
||||
lang := timerDescTable.Lookup(ctx, TIMERLANG)
|
||||
switch lang {
|
||||
case "en":
|
||||
return st.descEnglish()
|
||||
return st.descEnglish(zone)
|
||||
case "cn":
|
||||
return st.descChinese()
|
||||
return st.descChinese(zone)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -186,11 +186,9 @@ func (st *STimer) Description(ctx context.Context) string {
|
||||
var (
|
||||
wdsCN = []string{"", "一", "二", "三", "四", "五", "六", "日"}
|
||||
wdsEN = []string{"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
|
||||
zone = time.Now().Local().Location()
|
||||
//zone = time.FixedZone("GMT", 8*3600)
|
||||
)
|
||||
|
||||
func (st *STimer) descChinese() string {
|
||||
func (st *STimer) descChinese(zone *time.Location) string {
|
||||
format := "2006-01-02 15:04:05"
|
||||
var prefix string
|
||||
switch st.Type {
|
||||
@@ -216,7 +214,7 @@ func (st *STimer) descChinese() string {
|
||||
return fmt.Sprintf("%s %02d:%02d触发 有效时间为%s至%s", prefix, st.Hour, st.Minute, st.StartTime.In(zone).Format(format), st.EndTime.In(zone).Format(format))
|
||||
}
|
||||
|
||||
func (st *STimer) descEnglish() string {
|
||||
func (st *STimer) descEnglish(zone *time.Location) string {
|
||||
var detail string
|
||||
format := "2006-01-02 15:04:05"
|
||||
switch st.Type {
|
||||
|
||||
Reference in New Issue
Block a user