Skip to content

Commit

Permalink
change readme
Browse files Browse the repository at this point in the history
  • Loading branch information
trstringer committed Oct 1, 2020
1 parent b166343 commit b632fc7
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

_Go implementation of systemd time (`man systemd.time`)_

In command line applications, it is convenient to use the notation since `-1day`, or in `5 hours`. This package takes that string (using systemd time specs) and converts it into `time.Duration`. There is also a helper function that can take the raw string time adjustment and a `time.Time` (or `nil` for `time.Now()`) object and apply the adjustment to immutably. See [below for usage](#usage).

## Installation

You can use `dep` to install this vendor dependency, or `go get github.com/trstringer/go-systemd-time/systemdtime`.
In command line applications, it is convenient to use the notation since `-1day`, or in `5 hours`. This package takes that string (using systemd time specs) and converts it into `time.Duration`. There is also a helper function that can take the raw string time adjustment and a `time.Time` (or `nil` for `time.Now()`) object and apply the adjustment to immutably. See below for usage.

## Usage

Expand All @@ -20,39 +16,30 @@ import (
"os"
"time"

"github.com/trstringer/go-systemd-time/systemdtime"
"github.com/trstringer/go-systemd-time/pkg/systemdtime"
)

func main() {
now := time.Now()
fmt.Printf("Current date/time: %s\n", now)
timeFormat := "3:04 PM on January 2, 2006"

twoDaysThreeHoursAgo, err := systemdtime.AdjustTime(&now, "-2 days 3 hr")
if err != nil {
fmt.Printf("Error converting: %v\n", err)
os.Exit(1)
}
fmt.Printf("Two days and three hours ago: %s\n", twoDaysThreeHoursAgo)
fmt.Printf("Now is %s\n", now.Format(timeFormat))

eighteenDaysTwelveMinutesFromNow, err := systemdtime.AdjustTime(&now, "18d12min")
adjustedTime, err := systemdtime.AdjustTime(&now, "2d")
if err != nil {
fmt.Printf("Error converting: %v\n", err)
fmt.Printf("error adjusting time: %v\n", err)
os.Exit(1)
}
fmt.Printf("Eighteen days and twelve minutes from now: %s\n", eighteenDaysTwelveMinutesFromNow)
fmt.Printf("Adjusted is %s\n", adjustedTime.Format(timeFormat))
/*
Now is 8:38 PM on September 30, 2020
Adjusted is 8:38 PM on October 2, 2020
*/
}
```

Output from the above sample...

```
Current date/time: 2018-04-28 10:14:10.545534601 -0400 EDT m=+0.000220259
Two days and three hours ago: 2018-04-26 07:14:10.545534601 -0400 EDT m=-183599.999779741
Eighteen days and twelve minutes from now: 2018-05-16 10:26:10.545534601 -0400 EDT m=+1555920.000220259
```

## Bug reports and running tests

If a bug is found, please write a failing test to uncover the bug.

To run tests, navigate to the root directory run `go test ./test/`.
To run tests, navigate to the root directory and run `go test -v ./...`.

0 comments on commit b632fc7

Please sign in to comment.