dtdiff

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 6 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDiff

func CalculateDiff(from time.Time, to time.Time) time.Duration

CalculateDiff calculate time diff between from and to

func CalculateDiffSince

func CalculateDiffSince(from time.Time) time.Duration

CalculateDiffSince calculate time diff between from and now

func CalculateDiffUntil

func CalculateDiffUntil(to time.Time) time.Duration

CalculateDiffUntil calculate time diff between now and to(future)

func CalculateDiffs added in v0.3.0

func CalculateDiffs(args ...time.Time) time.Duration

CalculateDiffs calculate time diff between pair of args

Types

type Formatter added in v0.2.0

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter is time diff put into words

func NewFormatter added in v0.2.0

func NewFormatter(withoutUnit bool, duration time.Duration) *Formatter

NewFormatter returns new Formatter

func (*Formatter) Hours added in v0.2.0

func (f *Formatter) Hours() string

Hours display hour, the second decimal. ex. 4.83 hours

func (*Formatter) Long added in v0.2.0

func (f *Formatter) Long() string

Long description (days, hours, minutes, seconds) of time diff

func (*Formatter) Minutes added in v0.2.0

func (f *Formatter) Minutes() string

Minutes display minutes. ex. 123 minutes

func (*Formatter) Nanoseconds added in v0.2.0

func (f *Formatter) Nanoseconds() string

Nanoseconds display. ex 810821916 nanoseconds

func (*Formatter) Seconds added in v0.2.0

func (f *Formatter) Seconds() string

Seconds display seconds. ex. 65555 seconds

func (*Formatter) Short added in v0.2.0

func (f *Formatter) Short() string

Short description (days, hours, minutes, seconds) of time diff

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

ParseError is used when parse failed

func (ParseError) Error

func (e ParseError) Error() string

type Parser

type Parser interface {
	Parse(str string) (time.Time, error)
}

Parser parse date & time

func NewParser

func NewParser(now time.Time) Parser

NewParser returns a new parser

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL