seconds

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FromSecondsCmd = &cobra.Command{
	Aliases: []string{"from-second", "from-sec"},
	Use:     "from-seconds <duration>",
	Args:    cobra.ExactArgs(1),
	GroupID: cmdgroups.Utilities,
	Short:   "Convert the given amount of seconds into a human-readable duration",
	Long: `Converts the given amount of seconds into a human-readable duration string.

The following units are used:
- 's' for seconds
- 'm' for minutes
- 'h' for hours
- 'd' for days
- 'y' for years (1y = 365d)

Examples:

	> kpu from-seconds 3600
	1h

	> kpu from-seconds 32842800
	1y15d3h
	`,
	Run: func(cmd *cobra.Command, args []string) {
		ValidateFromSecondsCommand(args)

		dAsInt64, ok := strconv.ParseInt(strings.TrimSuffix(args[0], "s"), 10, 64)
		if ok != nil {
			utils.Fatal(1, "expected a number, got %s", args[0])
		}
		d := time.Duration(dAsInt64) * time.Second
		fmt.Println(utils.FormatDuration(d))
	},
}

FromSecondsCmd represents the from-seconds command

View Source
var ToSecondsCmd = &cobra.Command{
	Aliases: []string{"to-second", "to-sec"},
	Use:     "to-seconds <duration>",
	Args:    cobra.ExactArgs(1),
	GroupID: cmdgroups.Utilities,
	Short:   "Convert the given duration to seconds",
	Long: `Converts the given duration to seconds.

A duration consists of one or more natural numbers, each followed by a unit, e.g. '1h30m'.

The following units are supported:
- 's' for seconds
- 'm' for minutes
- 'h' for hours
- 'd' for days
- 'w' for weeks (1w = 7d)
- 'M' for months (1M = 30d)
- 'y' for years (1y = 365d)

Note that due to the simplified logic, neither 12 months nor 52 weeks add up to the 365 days of a year.

Examples:

	> kpu to-seconds 1h
	3600

	> kpu to-seconds 1y15d3h
	32842800
	`,
	Run: func(cmd *cobra.Command, args []string) {
		ValidateToSecondsCommand(args)

		d, err := utils.StringToDuration(args[0])
		if err != nil {
			utils.Fatal(1, "error converting duration to seconds: %s", err.Error())
		}

		fmt.Printf("%d\n", int64(d.Seconds()))
	},
}

ToSecondsCmd represents the to-seconds command

Functions

func ValidateFromSecondsCommand

func ValidateFromSecondsCommand(args []string)

func ValidateToSecondsCommand

func ValidateToSecondsCommand(args []string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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