Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

trstringer/go-systemd-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

27 Commits

Repository files navigation

go-systemd-time

ci

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

package main
import (
	"fmt"
	"os"
	"time"
	"github.com/trstringer/go-systemd-time/pkg/systemdtime"
)
func main() {
	now := time.Now()
	timeFormat := "3:04 PM on January 2, 2006"
	fmt.Printf("Now is %s\n", now.Format(timeFormat))
	adjustedTime, err := systemdtime.AdjustTime(now, "2d")
	if err != nil {
		fmt.Printf("error adjusting time: %v\n", err)
		os.Exit(1)
	}
	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
	*/
}

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 and run go test -v ./....

About

πŸ“… Go implementation of systemd relative time adjustments

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /