format

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package format provides utilities for parsing and formatting time strings in various formats.

Index

Constants

This section is empty.

Variables

View Source
var StateColours = map[string]text.Color{
	"100%":                            text.FgGreen,
	"active":                          text.FgGreen,
	"allow":                           text.FgGreen,
	"available":                       text.FgGreen,
	"attached":                        text.FgGreen,
	"blackhole":                       text.FgRed,
	"completed":                       text.FgGreen,
	"configuring-enhanced-monitoring": text.FgYellow,
	"create_complete":                 text.FgGreen,
	"create-complete":                 text.FgGreen,
	"create_in_progress":              text.FgYellow,
	"create-in-progress":              text.FgYellow,
	"create_failed":                   text.FgRed,
	"create-failed":                   text.FgRed,
	"creating":                        text.FgYellow,
	"delete_complete":                 text.FgGreen,
	"delete-complete":                 text.FgGreen,
	"delete_failed":                   text.FgRed,
	"delete-failed":                   text.FgRed,
	"deleted":                         text.FgRed,
	"deleting":                        text.FgRed,
	"deny":                            text.FgRed,
	"error":                           text.FgRed,
	"failed":                          text.FgRed,
	"healthy":                         text.FgGreen,
	"import_complete":                 text.FgGreen,
	"import_in_progress":              text.FgYellow,
	"import_rollback_complete":        text.FgGreen,
	"import_rollback_failed":          text.FgRed,
	"import_rollback_in_progress":     text.FgYellow,
	"in-use":                          text.FgGreen,
	"modify_complete":                 text.FgGreen,
	"modify-complete":                 text.FgGreen,
	"modify_failed":                   text.FgRed,
	"modify-failed":                   text.FgRed,
	"modify_in_progress":              text.FgYellow,
	"modify-in-progress":              text.FgYellow,
	"modifying":                       text.FgYellow,
	"pending":                         text.FgYellow,
	"rebooting":                       text.FgYellow,
	"restore_complete":                text.FgGreen,
	"restore-complete":                text.FgGreen,
	"restore_failed":                  text.FgRed,
	"restore-failed":                  text.FgRed,
	"restore_in_progress":             text.FgYellow,
	"restore-in-progress":             text.FgYellow,
	"rollback_complete":               text.FgRed,
	"rollback-complete":               text.FgRed,
	"rollback_failed":                 text.FgRed,
	"rollback-failed":                 text.FgRed,
	"rollback_in_progress":            text.FgYellow,
	"rollback-in-progress":            text.FgYellow,
	"running":                         text.FgGreen,
	"starting":                        text.FgYellow,
	"shutting-down":                   text.FgRed,
	"stopped":                         text.FgRed,
	"stopping":                        text.FgYellow,
	"terminated":                      text.FgRed,
	"update_complete":                 text.FgGreen,
	"update_in_progress":              text.FgBlue,
	"update_rollback_complete":        text.FgRed,
	"update_rollback_failed":          text.FgRed,
	"update_rollback_in_progress":     text.FgRed,
	"upgrading":                       text.FgYellow,
}

StateColours is a map of state to colour.

Functions

func BoolToLabel

func BoolToLabel(b *bool, trueLabel, falseLabel string) string

BoolToLabel returns trueLabel if b is true, falseLabel if b is false, or "" if b is nil.

func BoolToStringOrDefault

func BoolToStringOrDefault(b *bool, defaultValue string) string

BoolToStringOrDefault safely converts *bool to string, "" if nil.

func Int32ToStringOrDefault

func Int32ToStringOrDefault(i *int32, defaultValue string) string

Int32ToStringOrDefault safely converts *int32 to string, "" if nil.

func Int32ToStringOrEmpty

func Int32ToStringOrEmpty(i *int32) string

Int32ToStringOrEmpty safely converts a *int32 to string, returns "" if nil.

func Int64ToStringOrDefault

func Int64ToStringOrDefault(i *int64, defaultValue string) string

Int64ToStringOrDefault safely converts *int64 to string, "" if nil.

func Int64ToStringOrEmpty

func Int64ToStringOrEmpty(i *int64) string

Int64ToStringOrEmpty safely converts a *int64 to string, returns "" if nil.

func IntToStringOrDefault

func IntToStringOrDefault(i *int, defaultValue string) string

IntToStringOrDefault safely converts *int to string, "" if nil.

func ParseTime

func ParseTime(timeStr string) (time.Time, error)

ParseTime attempts to parse a time string in multiple formats: 1. Human-readable duration (e.g., "2 hours", "30 minutes") 2. RFC3339 format (e.g., "2024-03-20T15:04:05Z") 3. Natural language parsing (e.g., "tomorrow at 3pm", "next week")

Returns the parsed time.Time and any error encountered during parsing.

func Status

func Status(state string) string

Status formats the provided state with the appropriate colour. If the state is not found in the StateColours map, the state is returned unchanged.

func StatusOrDefault

func StatusOrDefault(s string, defaultValue string) string

StatusOrDefault returns format.Status(s) or "" if s is empty.

func StringOrDefault

func StringOrDefault(s *string, defaultValue string) string

StringOrDefault safely dereferences a *string, returning "" if nil.

func StringOrEmpty

func StringOrEmpty(s *string) string

StringOrEmpt safely dereferences a *string, returning "" if nil.

func TimeToStringOrDefault

func TimeToStringOrDefault(t *time.Time, defaultValue string) string

TimeToStringOrDefault formats *time.Time or returns "" if nil.

func TimeToStringOrEmpty

func TimeToStringOrEmpty(t *time.Time) string

TimeToStringOrEmpty formats a *time.Time or returns "" if nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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