Skip to content

Commit

Permalink
Language tweaking and additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed Sep 29, 2024
1 parent 7e7bf5a commit f7a855b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/usage/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ See: [json](json.md) for more information.

Syntax: `{time str "[format:cache]" "[tz:utc]"}`

Parse a given time-string into a unix second time (default format: `auto`)
Parse a given time-string into a unix second time (default format: `cache`)

##### Format Auto-Detection

Expand All @@ -461,7 +461,7 @@ If the format is unable to be resolved, it must be specified manually with a for

If ommitted or "cache": The first seen date will determine the format for all dates going forward (faster)

If "auto": The date format will always be auto-detected each time. This can be used if the date could be in different formats (slower)
If "auto": The date format will be auto-detected with each parse. This can be used if the date could be in different formats (slower)

##### Timezones

Expand All @@ -476,7 +476,7 @@ Syntax: `{time now}`

These are special values to output:

* `now` - return the current unix timestamp cached at the start of *rare* `{time now}`
* `now` - return the current unix timestamp cached at the start of *rare*
* `live` - return the current unix timestamp the moment it's executed
* `delta` - return the number of seconds that *rare* has executed

Expand All @@ -496,7 +496,7 @@ ANSIC, UNIX, RUBY, RFC822, RFC822Z, RFC1123, RFC1123Z, RFC3339, RFC3339, RFC3339
MONTH, MONTHNAME, MNTH, DAY, WEEKDAY, WDAY, YEAR, HOUR, MINUTE, SECOND, TIMEZONE, NTIMEZONE

**Custom formats:**
You can provide a custom format using go's well-known date. Here's an exercept from their docs:
You can provide a custom format using go's well-known date. Here's an exercept from the docs:

To define your own format, write down what the reference time would look like formatted your way; see the values of constants
like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format
Expand Down
4 changes: 4 additions & 0 deletions pkg/expressions/stdlib/funcsTime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func TestTimeDelta(t *testing.T) {
val := kb.BuildKey(mockContext())
assert.NotEmpty(t, val)

iVal, errVal := strconv.Atoi(val)
assert.NoError(t, errVal)
assert.Less(t, iVal, 300) // Delta should always be relatively lower (at least lower than running the test)

time.Sleep(1 * time.Second)

val2 := kb.BuildKey(mockContext())
Expand Down

0 comments on commit f7a855b

Please sign in to comment.