clock

package
v0.0.0-...-543a44c Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: GPL-3.0 Imports: 1 Imported by: 0

README

Clock

Implement a clock that handles times without dates.

You should be able to add and subtract minutes to it.

Two clocks that represent the same time should be equal to each other.

Running the tests

To run the tests run the command go test from within the exercise directory.

If the test suite contains benchmarks, you can run these with the --bench and --benchmem flags:

go test -v --bench . --benchmem

Keep in mind that each reviewer will run benchmarks on a different machine, with different specs, so the results from these benchmark tests may vary.

Further information

For more detailed information about the Go track, including how to get help if you're having trouble, please visit the exercism.io Go language page.

Source

Pairing session with Erin Drummond https://twitter.com/ebdrummond

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

Clock represents clock with hour and minute

Example (Compare)
// a new clock
clock1 := New(10, 30)

// a second clock, same as the first
clock2 := New(10, 30)

// are the clocks equal?
fmt.Println(clock2 == clock1)

// change the second clock
clock2 = clock2.Add(30)

// are the clocks equal now?
fmt.Println(clock2 == clock1)
Output:

true
false
Example (New)
// a new clock
clock1 := New(10, 30)
fmt.Println(clock1.String())
Output:

10:30

func New

func New(hour, minute int) Clock

New creates new clock

func (Clock) Add

func (c Clock) Add(minutes int) Clock

Add moves clock m minutes forward

Example
// create a clock
clock := New(10, 30)

// add 30 minutes to it
clock = clock.Add(30)
fmt.Println(clock.String())
Output:

11:00

func (Clock) String

func (c Clock) String() string

String returns string representation of clock

func (Clock) Subtract

func (c Clock) Subtract(minutes int) Clock

Subtract moves clock m minutes backward

Example
// create a clock
clock := New(10, 30)

// subtract an hour and a half from it
clock = clock.Subtract(90)
fmt.Println(clock.String())
Output:

09:00

Jump to

Keyboard shortcuts

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