How can I calculate a duration from start and end time #1479
Unanswered
kontango-bot
asked this question in
Q&A
Replies: 4 comments
|
It seems that vars are evaluated when they are called, so i don't think this approach will work either way. |
0 replies
|
This is what I ended up with: vars:
start_time: { sh: date +%s }
tasks:
test:
cmds:
- sleep 5
- task: end_timer
- echo "Done."
end_timer:
cmds:
- "echo Duration: {{ .duration | duration }}"
vars:
duration: { sh: "echo $(( $(date +%s) - {{ .start_time }} ))" } |
0 replies
|
I've found another solution: version: '3'
tasks:
test:
desc: "Test timing measurements of task"
cmds:
- echo "⌚️ Test timing measurements of a task ⌚️"
- echo ""
- sleep 5
- task: task_timer
vars:
start_time: '{{ now |unixEpoch }}'
silent: true
task_timer:
desc: "Calculate timing of the calling task"
# Call this task at the end of the caller task with following parameters:
# - task: task_timer
# vars:
# start_time: '{{ now | unixEpoch }}'
summary: |
This task is a helper task to calulate the duration in seconds
for the caller task
vars:
end_time: '{{now | unixEpoch}}'
requires:
vars: [start_time]
cmds:
- 'echo ⏲️ -----------------------------------------------------------------------'
# - 'echo ⏲️ StartTime: {{ .start_time }} EndTime: {{ .end_time }}'
- 'echo ⏲️ Duration: {{ sub .end_time .start_time | duration }}'
- 'echo ⏲️ -----------------------------------------------------------------------'
silent: true
internal: true |
0 replies
|
If I understand correctly the end goal, on Unix systems it is literally a 0 line: Assume I would like to know how long utility I can do: Where |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
here's my taskfile:
This is invalid syntax, and i've tried a few other things (e.g. without parens) that also seem to be invalid.
Part of the problem is that
.start_timegets converted to a string, which is not suprising. I'm not sure how to convert it back into a date before passing it intonow.Sub. Or, if there is a way to storenowwithout converting it to a string, that would be ideal.All reactions