Skip to content

tkrtmy/dtdiff

Repository files navigation

Release CI GoDoc GitHub

dtdiff

dtdiff is DateTimeDiff

CLI Usage

$ dtdiff -help
Usage: dtdiff [options] [datetime(from)] [datetime(to)]

  -h    display hours only
  -m    display minutes only
  -n    display nanoseconds only
  -q    display without time unit
  -s    display seconds only
  -short
        short description
  -until
        calculate until a given one
  -v    display current version

$ dtdiff '2018-10-14 12:40:50' '2018-10-16 15:48:20'
2 days 3 hours 7 minutes 30 seconds

# When you give one argument, calculate between a given and now.
# If you execute command at 2018-10-16 15:48:20
$ dtdiff '2018-10-14 12:40:50'
2 days 3 hours 7 minutes 30 seconds

# When you give one argument with -u option, calculate between now and a given.
# If you execute command at 2018-10-14 12:40:50
$ dtdiff -until '2018-10-16 15:48:20'
2 days 3 hours 7 minutes 30 seconds

$ dtdiff -m '12:40:50' '15:48:20'
187 minutes
$ dtdiff -m -q '12:40:50' '15:48:20'
187

$ dtdiff -m 11:47 18:23
396 minutes

# When you would like to calculate multiple DateTimes Difference
# pseudo-instruction:
# expr `dtdiff '2019-02-03 12:40:50' '2019-02-04 11:48:16'` + `dtdiff '2019-02-07 11:40:52' '2019-02-13 15:32:09'` + ...
$ dtdiff '2019-02-03 12:40:50' '2019-02-04 11:48:16' '2019-02-07 11:40:52' '2019-02-13 15:32:09'
7 days 2 hours 58 minutes 43 seconds

CLI Installation

For Homebrew user

$ brew tap tkrtmy/dtdiff
$ brew install dtdiff

For Go user

$ go get -u github.com/tkrtmy/dtdiff/cmd/dtdiff

Use without installation

$ docker run --rm tkrtmy/dtdiff -m 12:48 21:24
516 minutes

dockerhub

How to build & run

# build in container
$ docker build -t dtdiff .
# run in container
$ docker run --rm dtdiff 12:48 21:23
0 days 8 hours 35 minutes 0 seconds