Skip to content

Commit

Permalink
ADD section about simulated time to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Mar 6, 2024
1 parent 2cd1a3f commit fbdb04d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ Result:
a text string
```

## Using simulated time

By default, the current time reference used by [date related transformations](#date related transformations) is system current time. However, this can be changed using the positional argument `now` in the `JEXL` constructor to specify a function that returns a `datetime` object to be used as current time.

For instance, if we want to set current time to November 13th, 2020 at 6:24:58am we can use:

```python
from tcjexl import JEXL
import datetime

def simulated_time():
return datetime.datetime(2020, 11, 13, 6, 24, 58, 000, tzinfo=datetime.timezone.utc)

jexl = JEXL(now=simulated_time)

print(jexl.evaluate('0|currentTimeIso', {}))
```

Result:

```
2020-11-13T06:24:58.000Z
```

## Included transformations

**NOTE:** JEXL pipeline is needed even if the transformation doesn't need an parameter to work (e.g. `currentTime` that provides the current system time and doesn't need and argument). In this case, we use `0|` for these cases (e.g. `0|currentTime`).
Expand Down

0 comments on commit fbdb04d

Please sign in to comment.