time

package
v0.0.0-...-b1c1fed Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Command = &cli.Command{
		Name:  "time",
		Usage: "Common operations handling time.",
		Subcommands: []*cli.Command{
			{
				Name:  "since",
				Usage: "Compute how much time has elapsed since the provided time.",
				Action: func(ctx *cli.Context) error {
					if ctx.NArg() < 1 {
						return fmt.Errorf("missing time as first argument")
					}

					arg0 := ctx.Args().Get(0)

					var t time.Time
					var err error

					for _, format := range supportedFormats {
						t, err = time.Parse(format, arg0)
						if err == nil {
							break
						}
					}

					if err != nil {
						return fmt.Errorf("failed to parse input time using known formats")
					}

					elapsed := time.Since(t)
					out := ""

					if elapsed > day {
						out += strconv.FormatInt(int64(elapsed/day), 10) + "d"
						elapsed = elapsed % day
					}

					out += elapsed.String()
					_, err = ctx.App.Writer.Write([]byte(out))

					return err
				},
			},
		},
		Action: func(ctx *cli.Context) error {
			now := time.Now().Format(time.RFC3339)
			_, err := ctx.App.Writer.Write([]byte(now))

			return err
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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