All Projects â†’ trstringer â†’ go-systemd-time

trstringer / go-systemd-time

Licence: GPL-3.0 license
📅 Go implementation of systemd relative time adjustments

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-systemd-time

tir
Have time.ir in shell!
Stars: ✭ 114 (+442.86%)
Mutual labels:  time, date
rutimeparser
Recognize date and time in russian text and return datetime.datetime.
Stars: ✭ 17 (-19.05%)
Mutual labels:  time, date
timelite
String date and time utilities 🕙
Stars: ✭ 17 (-19.05%)
Mutual labels:  time, date
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (+57.14%)
Mutual labels:  time, date
FM-JSON-Types
FileMaker Data Types in JSON
Stars: ✭ 14 (-33.33%)
Mutual labels:  time, date
date-extractor
Extract dates from text
Stars: ✭ 58 (+176.19%)
Mutual labels:  time, date
time machine
A date and time API for Dart
Stars: ✭ 120 (+471.43%)
Mutual labels:  time, date
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (+195.24%)
Mutual labels:  time, date
island-time
A Kotlin Multiplatform library for working with dates and times
Stars: ✭ 69 (+228.57%)
Mutual labels:  time, date
TimesDates.jl
Nanosecond resolution for Time and Date, TimeZones
Stars: ✭ 28 (+33.33%)
Mutual labels:  time, date
jodaTime
Format and Parse date and time with joda layout
Stars: ✭ 67 (+219.05%)
Mutual labels:  time, date
ElevenClock
ElevenClock: Customize Windows 11 taskbar clock
Stars: ✭ 1,494 (+7014.29%)
Mutual labels:  time, date
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+480.95%)
Mutual labels:  time, date
duration
Parse iso8601 duration strings, and use to shift dates/times.
Stars: ✭ 51 (+142.86%)
Mutual labels:  time, date
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (+14.29%)
Mutual labels:  time, date
temps-lite
A smart, good-looking little app which tries to speak your language the way you are used to.
Stars: ✭ 40 (+90.48%)
Mutual labels:  time, date
Travel
Framework agnostic PHP package to control the time.
Stars: ✭ 251 (+1095.24%)
Mutual labels:  time, date
nativescript-datetimepicker
Plugin with date and time picking fields
Stars: ✭ 26 (+23.81%)
Mutual labels:  time, date
kronos
Management of arithmetic operations on dates
Stars: ✭ 23 (+9.52%)
Mutual labels:  time, date
qrono
🕥 Just right date time library
Stars: ✭ 111 (+428.57%)
Mutual labels:  time, date

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 ./....

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].