mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
Merge pull request #2216 from semaphoreui/always_use_utc_time
Always use utc time
This commit is contained in:
commit
74863501dd
19
db/Task.go
19
db/Task.go
@ -2,6 +2,7 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-gorp/gorp/v3"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ansible-semaphore/semaphore/pkg/task_logger"
|
"github.com/ansible-semaphore/semaphore/pkg/task_logger"
|
||||||
@ -51,6 +52,24 @@ type Task struct {
|
|||||||
InventoryID *int `db:"inventory_id" json:"inventory_id"`
|
InventoryID *int `db:"inventory_id" json:"inventory_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (task *Task) PreInsert(gorp.SqlExecutor) error {
|
||||||
|
task.Created = task.Created.UTC()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *Task) PreUpdate(gorp.SqlExecutor) error {
|
||||||
|
if task.Start != nil {
|
||||||
|
start := task.Start.UTC()
|
||||||
|
task.Start = &start
|
||||||
|
}
|
||||||
|
|
||||||
|
if task.End != nil {
|
||||||
|
end := task.End.UTC()
|
||||||
|
task.End = &end
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (task *Task) GetIncomingVersion(d Store) *string {
|
func (task *Task) GetIncomingVersion(d Store) *string {
|
||||||
if task.BuildTaskID == nil {
|
if task.BuildTaskID == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -30,7 +30,7 @@ func (d *SqlDb) getEvents(q squirrel.SelectBuilder, params db.RetrieveQueryParam
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqlDb) CreateEvent(evt db.Event) (newEvent db.Event, err error) {
|
func (d *SqlDb) CreateEvent(evt db.Event) (newEvent db.Event, err error) {
|
||||||
var created = time.Now()
|
var created = time.Now().UTC()
|
||||||
|
|
||||||
_, err = d.exec(
|
_, err = d.exec(
|
||||||
"insert into event(user_id, project_id, object_id, object_type, description, created) values (?, ?, ?, ?, ?, ?)",
|
"insert into event(user_id, project_id, object_id, object_type, description, created) values (?, ?, ?, ?, ?, ?)",
|
||||||
@ -54,7 +54,7 @@ func (d *SqlDb) GetUserEvents(userID int, params db.RetrieveQueryParams) ([]db.E
|
|||||||
q := squirrel.Select("event.*, p.name as project_name").
|
q := squirrel.Select("event.*, p.name as project_name").
|
||||||
From("event").
|
From("event").
|
||||||
LeftJoin("project as p on event.project_id=p.id").
|
LeftJoin("project as p on event.project_id=p.id").
|
||||||
OrderBy("created desc").
|
OrderBy("id desc").
|
||||||
LeftJoin("project__user as pu on pu.project_id=p.id").
|
LeftJoin("project__user as pu on pu.project_id=p.id").
|
||||||
Where("p.id IS NULL or pu.user_id=?", userID)
|
Where("p.id IS NULL or pu.user_id=?", userID)
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ func (d *SqlDb) GetEvents(projectID int, params db.RetrieveQueryParams) ([]db.Ev
|
|||||||
q := squirrel.Select("event.*, p.name as project_name").
|
q := squirrel.Select("event.*, p.name as project_name").
|
||||||
From("event").
|
From("event").
|
||||||
LeftJoin("project as p on event.project_id=p.id").
|
LeftJoin("project as p on event.project_id=p.id").
|
||||||
OrderBy("created desc").
|
OrderBy("id desc").
|
||||||
Where("event.project_id=?", projectID)
|
Where("event.project_id=?", projectID)
|
||||||
|
|
||||||
return d.getEvents(q, params)
|
return d.getEvents(q, params)
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (d *SqlDb) CreateProject(project db.Project) (newProject db.Project, err error) {
|
func (d *SqlDb) CreateProject(project db.Project) (newProject db.Project, err error) {
|
||||||
project.Created = time.Now()
|
project.Created = time.Now().UTC()
|
||||||
|
|
||||||
insertId, err := d.insert(
|
insertId, err := d.insert(
|
||||||
"id",
|
"id",
|
||||||
|
@ -12,7 +12,7 @@ func (d *SqlDb) CreateSession(session db.Session) (db.Session, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqlDb) CreateAPIToken(token db.APIToken) (db.APIToken, error) {
|
func (d *SqlDb) CreateAPIToken(token db.APIToken) (db.APIToken, error) {
|
||||||
token.Created = db.GetParsedTime(time.Now())
|
token.Created = db.GetParsedTime(time.Now().UTC())
|
||||||
err := d.sql.Insert(&token)
|
err := d.sql.Insert(&token)
|
||||||
return token, err
|
return token, err
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func (d *SqlDb) ExpireSession(userID int, sessionID int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqlDb) TouchSession(userID int, sessionID int) error {
|
func (d *SqlDb) TouchSession(userID int, sessionID int) error {
|
||||||
_, err := d.exec("update session set last_active=? where id=? and user_id=?", time.Now(), sessionID, userID)
|
_, err := d.exec("update session set last_active=? where id=? and user_id=?", time.Now().UTC(), sessionID, userID)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,12 @@ func (d *SqlDb) CreateTask(task db.Task, maxTasks int) (newTask db.Task, err err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqlDb) UpdateTask(task db.Task) error {
|
func (d *SqlDb) UpdateTask(task db.Task) error {
|
||||||
_, err := d.exec(
|
err := task.PreUpdate(d.sql)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = d.exec(
|
||||||
"update task set status=?, start=?, `end`=? where id=?",
|
"update task set status=?, start=?, `end`=? where id=?",
|
||||||
task.Status,
|
task.Status,
|
||||||
task.Start,
|
task.Start,
|
||||||
@ -107,7 +112,7 @@ func (d *SqlDb) CreateTaskOutput(output db.TaskOutput) (db.TaskOutput, error) {
|
|||||||
"insert into task__output (task_id, task, output, time) VALUES (?, '', ?, ?)",
|
"insert into task__output (task_id, task, output, time) VALUES (?, '', ?, ?)",
|
||||||
output.TaskID,
|
output.TaskID,
|
||||||
output.Output,
|
output.Output,
|
||||||
output.Time)
|
output.Time.UTC())
|
||||||
return output, err
|
return output, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +128,7 @@ func (d *SqlDb) getTasks(projectID int, templateID *int, taskIDs []int, params d
|
|||||||
From("task").
|
From("task").
|
||||||
Join("project__template as tpl on task.template_id=tpl.id").
|
Join("project__template as tpl on task.template_id=tpl.id").
|
||||||
LeftJoin("`user` on task.user_id=`user`.id").
|
LeftJoin("`user` on task.user_id=`user`.id").
|
||||||
OrderBy("task.created desc, id desc")
|
OrderBy("id desc")
|
||||||
|
|
||||||
if templateID == nil {
|
if templateID == nil {
|
||||||
q = q.Where("tpl.project_id=?", projectID)
|
q = q.Where("tpl.project_id=?", projectID)
|
||||||
|
@ -16,7 +16,7 @@ func (d *SqlDb) CreateUserWithoutPassword(user db.User) (newUser db.User, err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.Password = ""
|
user.Password = ""
|
||||||
user.Created = db.GetParsedTime(time.Now())
|
user.Created = db.GetParsedTime(time.Now().UTC())
|
||||||
|
|
||||||
err = d.sql.Insert(&user)
|
err = d.sql.Insert(&user)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ func (d *SqlDb) CreateUser(user db.UserWithPwd) (newUser db.User, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.Password = string(pwdHash)
|
user.Password = string(pwdHash)
|
||||||
user.Created = db.GetParsedTime(time.Now())
|
user.Created = db.GetParsedTime(time.Now().UTC())
|
||||||
|
|
||||||
err = d.sql.Insert(&user.User)
|
err = d.sql.Insert(&user.User)
|
||||||
|
|
||||||
|
@ -13,7 +13,18 @@ const convert = new Convert();
|
|||||||
axios.defaults.baseURL = document.baseURI;
|
axios.defaults.baseURL = document.baseURI;
|
||||||
Vue.config.productionTip = false;
|
Vue.config.productionTip = false;
|
||||||
|
|
||||||
Vue.filter('formatDate', (value) => (value ? moment(String(value)).fromNow() : '—'));
|
Vue.filter('formatDate', (value) => {
|
||||||
|
if (!value) {
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
|
const date = moment(value);
|
||||||
|
const now = moment();
|
||||||
|
|
||||||
|
if (now.isSame(date, 'day')) {
|
||||||
|
return `${date.fromNow()} (${date.format('LT')})`; // Display only time if today
|
||||||
|
}
|
||||||
|
return date.format('L LT'); // Display only date otherwise
|
||||||
|
});
|
||||||
Vue.filter('formatTime', (value) => (value ? moment(String(value)).format('LTS') : '—'));
|
Vue.filter('formatTime', (value) => (value ? moment(String(value)).format('LTS') : '—'));
|
||||||
Vue.filter('formatLog', (value) => (value ? convert.toHtml(String(value)) : value));
|
Vue.filter('formatLog', (value) => (value ? convert.toHtml(String(value)) : value));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user