time

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Overview

Package time contains some useful functions to manage timestamps in the same representation that PostgreSQL uses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToPostgresFormat

func ConvertToPostgresFormat(timestamp string) string

ConvertToPostgresFormat converts timestamps to PostgreSQL time format, if needed. e.g. "2006-01-02T15:04:05Z07:00" --> "2006-01-02 15:04:05.000000Z07:00" If the conversion fails, the input timestamp is returned as it is.

func DifferenceBetweenTimestamps

func DifferenceBetweenTimestamps(first, second string) (time.Duration, error)

DifferenceBetweenTimestamps returns the time.Duration difference between two timestamps strings in time.RFC3339.

func GetCurrentTimestamp

func GetCurrentTimestamp() string

GetCurrentTimestamp returns the current timestamp as a string in RFC3339Micro format

func GetCurrentTimestampWithFormat

func GetCurrentTimestampWithFormat(format string) string

GetCurrentTimestampWithFormat returns the current timestamp as a string with the specified format

func ToCompactISO8601

func ToCompactISO8601(t time.Time) string

ToCompactISO8601 converts a time.Time into a compacted version of the ISO8601 timestamp, removing any separators for brevity.

For example:

Given: 2022-01-02 15:04:05 (UTC)
Returns: 20220102150405

This compact format is useful for generating concise, yet human-readable timestamps that can serve as suffixes for backup-related objects or any other contexts where space or character count might be a concern.

Types

This section is empty.

Jump to

Keyboard shortcuts

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