timet

package module
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

README

go-timet

Go Reference GitHub Actions Go Report Card codecov

go-timet is time package template collection.

  • I've coded many times.
  • I've checked the specification many times.
  • I've checked the implementation many times.
  • I've made mistakes many times.

Contents

Elapsed time

A structure and methods for measuring elapsed time.

  • Create an instance with ElapsedTime{}.
  • Start() to start measurement.
  • Stop() to end measurement.
  • Get the elapsed time with ElapsedTime().
Unit of duration

A set of functions for creating units of duration.

unit function equal to
nanosecond (ns) NS(n) n * time.Nanosecond
microsecond (μs) US(n) n * time.Microsecond
millisecond (ms) MS(n) n * time.Millisecond
second (s) S(n) n * time.Second
minute (m) M(n) n * time.Minute
hour (h) H(n) n * time.Hour

Documentation

Overview

Package timet is time package template collection.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func H

func H(n int64) time.Duration

H returns n hour duration.

This is the same as "n * time.Hour".

Example
d := H(1)
fmt.Println(d)
fmt.Println(d == 1*time.Hour)
Output:

1h0m0s
true

func M

func M(n int64) time.Duration

M returns n minute duration.

This is the same as "n * time.Minute".

Example
d := M(1)
fmt.Println(d)
fmt.Println(d == 1*time.Minute)
Output:

1m0s
true

func MS

func MS(n int64) time.Duration

MS returns n millisecond duration.

This is the same as "n * time.Millisecond".

Example
d := MS(1)
fmt.Println(d)
fmt.Println(d == 1*time.Millisecond)
Output:

1ms
true

func NS

func NS(n int64) time.Duration

NS returns n nanosecond duration.

This is the same as "n * time.Nanosecond".

Example
d := NS(1)
fmt.Println(d)
fmt.Println(d == 1*time.Nanosecond)
Output:

1ns
true

func S

func S(n int64) time.Duration

S returns n second duration.

This is the same as "n * time.Second".

Example
d := S(1)
fmt.Println(d)
fmt.Println(d == 1*time.Second)
Output:

1s
true

func US

func US(n int64) time.Duration

US returns n microsecond duration.

This is the same as "n * time.Microsecond".

Example
d := US(1)
fmt.Println(d)
fmt.Println(d == 1*time.Microsecond)
Output:

1µs
true

Types

type ElapsedTime

type ElapsedTime struct {
	Begin time.Time
	End   time.Time
}

ElapsedTime represents an active elapsed time instance.

func (*ElapsedTime) Elapsed

func (s *ElapsedTime) Elapsed() time.Duration

Elapsed returns elapsed time.

func (*ElapsedTime) MarshalJSON

func (s *ElapsedTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ElapsedTime) Start

func (s *ElapsedTime) Start()

Start starts measure.

func (*ElapsedTime) Stop

func (s *ElapsedTime) Stop()

Stop ends measure.

func (*ElapsedTime) String

func (s *ElapsedTime) String() string

String returns a string representing the elapsed time.

func (*ElapsedTime) Time

func (s *ElapsedTime) Time() (time.Time, time.Time)

Time returns start time and end time.

func (*ElapsedTime) UnmarshalJSON

func (s *ElapsedTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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