Skip to content

Commit

Permalink
feat: add some usage examples to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdevivo committed Jan 22, 2022
1 parent 6ab2757 commit 9920ed5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
`timediff` is a Go package for printing human readable, relative time differences.
Output is based on [ranges defined in the Day.js](https://day.js.org/docs/en/display/from-now) JavaScript library, and can be customized if needed.

```golang
str1 := timediff.TimeDiff(time.Now().Add(-10 * time.Second))
fmt.Println(str1) // a few seconds ago

str2 := timediff.TimeDiff(time.Now().Add(-3 * time.Minute))
fmt.Println(str2) // 3 minutes ago

str3 := timediff.TimeDiff(time.Now().Add(-23 * time.Hour))
fmt.Println(str3) // a day ago

str4 := timediff.TimeDiff(time.Now().Add(23 * time.Hour))
fmt.Println(str4) // in a day

str5 := timediff.TimeDiff(time.Now().Add(10 * time.Hour))
fmt.Println(str5) // in 10 hours
```

Here are examples of durations and their corresponding string outputs (taken from test output), using default options:

```
Expand Down

0 comments on commit 9920ed5

Please sign in to comment.