refactor: represent time fields as int64 Unix seconds throughout the stack
Collapses a four-step conversion chain (time_t → int64 → time.Time → RFC3339 string → string → time.Time) to a direct int64 pass-through: C time_t → rawJobData int64 → JobInfo int64 → JSON integer → QueryJob int64 → time.Unix() for display Changes: - apiserver/models/jobs.go: SubmitTime, QueueTime, StartTime, EndTime, ReserveTime in JobInfo and JobAdditionalFields: time.Time → int64 - apiserver/models/common.go: ActionControl.SubmitTime: time.Time → int64 - backend/convert_pure.go: remove time.Unix() calls; assign int64 directly - backend/convert_test.go: update time assertions to compare int64 values - xcecli/models/jobs.go: SubmitTime, StartTime, EndTime, ReserveTime in QueryJob: string/time.Time → int64; remove time import - xcecli/common/output/time.go: replace parseJobTime(string) with unixToTime(int64) and fmtUnixTime(int64) helpers - xcecli/common/output/page_print_jobs.go: replace parseJobTime() calls with unixToTime()/fmtUnixTime(); remove !startTime.IsZero() guard (unixToTime returns false for ts<=0, making it redundant) - xcecli/common/output/page_print_array_elements_jobs.go: replace string-split+time.Parse submit-time block with fmtUnixTime(); remove unused time import Side effect: eliminates the "0001-01-01T00:00:00Z" zero-time serialization issue at the source — zero timestamps are now 0 (integer) and unixToTime/fmtUnixTime return false/"-" for ts<=0 without special- casing needed in callers.
This commit is contained in:
parent
14de6c4fa6
commit
ce2edf0dac
8 changed files with 55 additions and 82 deletions
|
|
@ -3,7 +3,6 @@ package backend
|
|||
import (
|
||||
"apiserver/models"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// JobID bit layout constants — mirrors src/include/config.h.
|
||||
|
|
@ -179,18 +178,10 @@ func rawJobToModel(r rawJobData) *models.JobInfo {
|
|||
info.ExecUser = si.execUser
|
||||
}
|
||||
}
|
||||
if r.subTime > 0 {
|
||||
info.SubmitTime = time.Unix(r.subTime, 0)
|
||||
}
|
||||
if r.queueTime > 0 {
|
||||
info.QueueTime = time.Unix(r.queueTime, 0)
|
||||
}
|
||||
if r.startTime > 0 {
|
||||
info.StartTime = time.Unix(r.startTime, 0)
|
||||
}
|
||||
if r.finishTime > 0 {
|
||||
info.EndTime = time.Unix(r.finishTime, 0)
|
||||
}
|
||||
info.SubmitTime = r.subTime
|
||||
info.QueueTime = r.queueTime
|
||||
info.StartTime = r.startTime
|
||||
info.EndTime = r.finishTime
|
||||
if len(r.execHosts) > 0 {
|
||||
type hostSlot struct {
|
||||
HostName string `json:"host_name"`
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package backend
|
|||
import (
|
||||
"apiserver/models"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRawJobToModel_BasicFields(t *testing.T) {
|
||||
|
|
@ -81,17 +80,17 @@ func TestRawJobToModel_Timestamps(t *testing.T) {
|
|||
|
||||
info := rawJobToModel(r)
|
||||
|
||||
if info.SubmitTime != time.Unix(1700000000, 0) {
|
||||
t.Errorf("SubmitTime mismatch")
|
||||
if info.SubmitTime != 1700000000 {
|
||||
t.Errorf("SubmitTime: got %d, want 1700000000", info.SubmitTime)
|
||||
}
|
||||
if info.QueueTime != time.Unix(1700000010, 0) {
|
||||
t.Errorf("QueueTime mismatch")
|
||||
if info.QueueTime != 1700000010 {
|
||||
t.Errorf("QueueTime: got %d, want 1700000010", info.QueueTime)
|
||||
}
|
||||
if info.StartTime != time.Unix(1700000020, 0) {
|
||||
t.Errorf("StartTime mismatch")
|
||||
if info.StartTime != 1700000020 {
|
||||
t.Errorf("StartTime: got %d, want 1700000020", info.StartTime)
|
||||
}
|
||||
if info.EndTime != time.Unix(1700000030, 0) {
|
||||
t.Errorf("EndTime mismatch")
|
||||
if info.EndTime != 1700000030 {
|
||||
t.Errorf("EndTime: got %d, want 1700000030", info.EndTime)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue