{"push_id":740432040,"size":1,"distinct_size":1,"ref":"refs/heads/elapsed-time-bash","head":"511bae66e3b1626fb515cdd5d4f81f2702b76544","before":"b41aa313693e16ff0c1d6d7930ab5644fb560cd1","commits":[{"sha":"511bae66e3b1626fb515cdd5d4f81f2702b76544","author":{"email":"9b97a0d46f52055a14a9273131a882065637a272@users.noreply.github.com","name":"Daniele Sluijters"},"message":"docker-gc: Calculate elapsed time in Bash\n\nThis removes the dependency on Python and as such also removed\nPython as a runtime dependency in the `debian/control` file.\n\nI've compared both functions with the following script:\n```bash\ntime_15=\"2015-07-03T02:39:00.39028499\"\ntime_17=\"2015-07-03 02:39:00.390284991 +0000 UTC\"\n\nfunction date_parse {\n  if date --utc >/dev/null 2>&1; then\n    # GNU/date\n    echo $(date -u --date \"${1}\" \"+%s\")\n  else\n    # BSD/date\n    echo $(date -j -u -f \"%F %T\" \"${1}\" \"+%s\")\n  fi\n}\n\nfunction elapsed_time() {\n    # Docker 1.5.0 datetime format is 2015-07-03T02:39:00.390284991\n    # Docker 1.7.0 datetime format is 2015-07-03 02:39:00.390284991 +0000 UTC\n    utcnow=$(date -u \"+%s\")\n    without_ms=\"${1:0:19}\"\n    replace_t=\"${without_ms/T/ }\"\n    epoch=$(date_pase \"${without_ms}\")\n    echo $(($utcnow - $epoch))\n}\n\nfunction ElapsedTime {\n    python <<END\nfrom datetime import datetime,timedelta\nnow = datetime.utcnow()\nexited = datetime.strptime('${1}'[:19].replace(\"T\",\" \"), \"%Y-%m-%d %H:%M:%S\")\ndifference = now - exited\ndifferenceTotalSeconds = difference.seconds + difference.days*24*3600\nprint(int(differenceTotalSeconds))\nEND\n}\n\nfor time in \"${time_15}\" \"${time_17}\"; do\n  echo $(elapsed_time \"${time}\")\n  echo $(ElapsedTime \"${time}\")\ndone\n```\n\nThis results in the following output, proving the functions result\nin identical behaviour:\n\n```\n2219644\n2219644\n2219644\n2219644\n```","distinct":true,"url":"https://api.github.com/repos/daenney/docker-gc/commits/511bae66e3b1626fb515cdd5d4f81f2702b76544"}]}