date

package
v3.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package date adds date-based helper functions for templating

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(args plugins.RegistrationArguments) error

Register provides the plugins.RegisterFunc

Types

type Interval

type Interval struct {
	Years   int
	Months  int
	Days    int
	Hours   int
	Minutes int
	Seconds int
}

Interval represents a human-minded diff of two dates which is in no way interchangeable with a time.Duration: The DateInterval takes each date component and subtracts them. This causes the 03/25 to be exactly one month distant from 02/25 even though the distance would be different than with 03/25 and 04/25 which is also exactly one month.

func NewInterval

func NewInterval(a, b time.Time) (i Interval)

NewInterval creates an Interval from two given dates

func (Interval) Format

func (i Interval) Format(tplString string) string

Format takes a template string analog to a strftime string and formats the Interval accordingly:

%Y / %y = Years with / without leading digit to 2 places %M / %m = Months with / without leading digit to 2 places %D / %d = Days with / without leading digit to 2 places %H / %h = Hours with / without leading digit to 2 places %I / %i = Minutes with / without leading digit to 2 places %S / %s = Seconds with / without leading digit to 2 places

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL