util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationTilNext

func DurationTilNext(start time.Time, now time.Time, between time.Duration) time.Duration

DurationTilNext calculates the duration until the between occurrence of a periodic event.

Parameters: - start: A start time for the periodic event - now: The current time - between: The duration between occurrences of the event

Returns: The duration until the between occurrence of the event

Examples:

  1. For a minutely event: start = 2023-01-01 00:00:00 now = 2023-01-01 00:01:30 between = 1 minute Result: 30 seconds (until 2023-01-01 00:02:00)

  2. For an hourly event: start = 2023-01-01 00:00:00 now = 2023-01-01 02:45:00 between = 1 hour Result: 15 minutes (until 2023-01-01 03:00:00)

  3. For a custom duration event (every 45 minutes): start = 2023-01-01 00:00:00 now = 2023-01-01 01:20:00 between = 45 minutes Result: 25 minutes (until 2023-01-01 01:45:00)

func FormatDuration added in v0.2.0

func FormatDuration(duration time.Duration) string

func GetUniqueShortNames

func GetUniqueShortNames(nameSet map[string]bool, fromRight bool, minChars int) map[string]string

GetUniqueShortNames takes in the set of names and tries to create a unique set of substrings of them, starting at minChars length and increasing if necessary. If fromRight is true, it starts from the end of each name. Returns a mapping of name -> short name with the names in nameSet as keys.

func GetUniqueShortNamesFromEdges

func GetUniqueShortNamesFromEdges(nameSet map[string]bool, minCharsEachSide int) map[string]string

GetUniqueShortNamesFromEdges does the same thing as GetUniqueShortNames, but removes chars in the middle of the name instead of the beginning or end. if e.g. apple would return app..ple, just return apple

func JoinWithEqualSpacing

func JoinWithEqualSpacing(width int, items ...string) string

func StyleStyledString added in v0.4.0

func StyleStyledString(s string, st lipgloss.Style) string

StyleStyledString is for styling a string that contains ANSI escape codes.

func TimeSince

func TimeSince(t time.Time) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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