times

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 1 Imported by: 0

README

Go Reference Contributor Covenant Go Report Card

times

Package that deals with time

Usage

We can use this whenever you deal with time.

  1. You can use gadgets like stopwatch that deal with time. This package focus on this feature.
  2. You can use time as an object, Surely.
  3. You can convert time object into string conveniently.

How to

  1. install go
  2. Enter the command line.
  3. Put down go get github.com/simp7/times
  4. Use package in your own projects.

Example

You can see how to use this package by seeing samples.

Contribute

If you want to be a contributor of our project, the door is open! Please read contributing for more information.

Help

  • You can inspect the api in here.
  • If you find out some problems, you can submit issue in here.
  • If you want to contribute, I would like you to read this first.
  • If other help is needed, you can take a contact via email(JHParkOfficial@protonmail.com).

Documentation

Index

Constants

View Source
const (
	Ms   = Unit(time.Millisecond)
	Sec  = Unit(time.Second)
	Min  = Unit(time.Minute)
	Hour = Unit(time.Hour)
)

Ms is Unit that refers to millisecond. Sec is Unit that refers to second. Min is Unit that refers to minute. Hour is Unit that refers to hour.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Add(func(string)) Action //Add returns action that has current function of this object and parameter function.
	Do(string)               //Do executes function that current object has.
}

Action is an interface that includes function. Action would be used in Actions and times.Gadget.

type Actions

type Actions interface {
	Add(Action, Time)        //Add adds Action to Actions in designated time.
	ActionsWhen(Time) Action //ActionsWhen returns Action in designated time.
}

Actions is an interface that includes a set of Action. Actions would be used in times.Gadget.

type Gadget

type Gadget interface {
	Add(action func(current string))                 //Add adds function that would be called when duration of minimum unit has passed. Parameter current in function is string-conversion of current time that inner function can uses.
	AddAlarm(action func(current string), when Time) //AddAlarm adds function that would be called when Gadget reaches in selected time. Parameter current in function is string-conversion of current time that inner function can uses.
	Start()                                          //Start runs Gadget.
	Stop() string                                    //Stop calls Pause and Reset. It also returns string as current.
	Reset()                                          //Reset sets Gadget to the state when it firstly initialized.
	Pause()                                          //Pause stops ticker.
	Present() string                                 //Present returns current time.
}

Gadget is an interface for tools that uses time. Each Gadget has minimum unit as times.Unit, and It has times.TimeFormatter to represent current time as string. Examples of Gadget can be clock, timer, stopwatch.

type Time

type Time interface {
	Tick()                   //Tick is called when time passed. This function add minimum Unit of this object.
	Rewind()                 //Rewind is called when time has been rewound. This function subtract minimum Unit of this object.
	MilliSecond() int        //MilliSecond returns millisecond of this object.
	Second() int             // Second returns second of this object.
	Minute() int             // Minute returns minute of this object.
	Hour() int               //Hour returns hour of this object.
	Day() int                //Day returns day of this object.
	Equal(to Time) bool      //Equal returns true when time of this object equals another one.
	SetMilliSecond(int) Time //SetMilliSecond sets millisecond of this object. This function also returns object itself.
	SetSecond(int) Time      //SetSecond sets millisecond of this object. This function also returns object itself.
	SetMinute(int) Time      //SetMinute sets millisecond of this object. This function also returns object itself.
	SetHour(int) Time        //SetHour sets millisecond of this object. This function also returns object itself.
	SetDay(int) Time         //SetDay sets millisecond of this object. This function also returns object itself.
	Serialize() string       //Serialize returns time data by string. This function is used for specifying time.
}

Time is interface that indicate specific time. Each Time should have time data and minimum Unit.

type TimeFormatter

type TimeFormatter interface {
	Format(t Time) string //Format converts Time into string. This function can be used in structs that implement gadget.Gadget
}

TimeFormatter is an interface that converts Time into string. TimeFormatter is used in times.Gadget for the use of showing times.

type Unit

type Unit time.Duration

Unit is a type that redirection of time.Duration. Unit can be implemented in implementation of times.Gadget to control the tick rate.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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