Skip to content

📅 Go implementation of systemd relative time adjustments

License

Notifications You must be signed in to change notification settings

gnufred/go-systemd-time

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-systemd-time

This is a temporary for of the original repo https://github.com/trstringer/go-systemd-time/

Intro

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%