Skip to content

Commit

Permalink
Merge pull request #1160 from France-ioi/fix_start_result_feature
Browse files Browse the repository at this point in the history
Fix start_result.feature
  • Loading branch information
smadbe authored Aug 21, 2024
2 parents bbf0c41 + 3e47db6 commit ed288c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/api/items/start_result.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Feature: Start a result for an item
Background:
Given time is frozen
And the DB time now is "{{currentTimeDB()}}"
And the database has the following table 'groups':
| id | type | root_activity_id | root_skill_id |
| 90 | Class | 10 | null |
Expand Down
5 changes: 5 additions & 0 deletions testhelpers/steps_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,11 @@ func constructWhereForColumnValues(columnNames, columnValues []string, whereIn b

// DBTimeNow sets the current time in the database to the provided time.
func (ctx *TestContext) DBTimeNow(timeStrRaw string) error {
var err error
timeStrRaw, err = ctx.preprocessString(timeStrRaw)
if err != nil {
return err
}
MockDBTime(timeStrRaw)
return nil
}
Expand Down
11 changes: 6 additions & 5 deletions testhelpers/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func (ctx *TestContext) constructTemplateSet() *jet.Set {
})

set.AddGlobalFunc("currentTimeDB", func(a jet.Arguments) reflect.Value {
return reflect.ValueOf(time.Now().UTC().Format("2006-01-02 15:04:05.999999"))
return reflect.ValueOf(time.Now().UTC().Round(time.Microsecond).Format("2006-01-02 15:04:05.999999"))
})

set.AddGlobalFunc("currentTimeDBMs", func(a jet.Arguments) reflect.Value {
return reflect.ValueOf(time.Now().UTC().Format("2006-01-02 15:04:05.000"))
return reflect.ValueOf(time.Now().UTC().Round(time.Millisecond).Format("2006-01-02 15:04:05.000"))
})

set.AddGlobalFunc("generateToken", func(a jet.Arguments) reflect.Value {
Expand Down Expand Up @@ -148,7 +148,7 @@ func (ctx *TestContext) constructTemplateSet() *jet.Set {
if err != nil {
a.Panicf("can't parse duration: %s", err.Error())
}
return reflect.ValueOf(time.Now().UTC().Add(duration).Format("2006-01-02 15:04:05"))
return reflect.ValueOf(time.Now().UTC().Add(duration).Round(time.Second).Format("2006-01-02 15:04:05"))
})

addRelativeTimeDBMsFunction(set)
Expand All @@ -169,18 +169,19 @@ func addRelativeTimeDBMsFunction(set *jet.Set) *jet.Set {
if err != nil {
a.Panicf("can't parse duration: %s", err.Error())
}
return reflect.ValueOf(time.Now().UTC().Add(duration).Format("2006-01-02 15:04:05.000"))
return reflect.ValueOf(time.Now().UTC().Add(duration).Round(time.Millisecond).Format("2006-01-02 15:04:05.000"))
})
}

func addTimeDBToRFCFunction(set *jet.Set) {
set.AddGlobalFunc("timeDBToRFC", func(a jet.Arguments) reflect.Value {
a.RequireNumOfArguments("timeDBToRFC", 1, 1)
dbTime := a.Get(0).Interface().(string)
parsedTime, err := time.Parse("2006-01-02 15:04:05", dbTime)
parsedTime, err := time.Parse("2006-01-02 15:04:05.999999999", dbTime)
if err != nil {
a.Panicf("can't parse mysql datetime: %s", err.Error())
}
parsedTime = parsedTime.Round(time.Second)
return reflect.ValueOf(parsedTime.Format(time.RFC3339))
})
}
Expand Down

0 comments on commit ed288c3

Please sign in to comment.