From b632fc7d65cd675874d2ccff3250b64158e03b7a Mon Sep 17 00:00:00 2001 From: Thomas Stringer Date: Wed, 30 Sep 2020 20:40:20 -0400 Subject: [PATCH] change readme --- README.md | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 06d028a..b3f5ea1 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ./...`.