clock

package module
v0.0.0-...-ea529e0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2014 License: Apache-2.0 Imports: 2 Imported by: 0

README

clock

Clock is a small, portable Go module for retrieving and setting the system clock.

On Linux/Darwin based systems it will use syscall.Gettimeofday() syscall.Settimeofday(). On Windows based systems it will use w32.GetSystemTime() and w32.SetSystemTime().

Example usage

package main

import (
	"time"

	"github.com/PaulMaddox/clock"
)

func main() {

    // Get the time
	t, err := clock.Get()
	if err != nil {
		panic(err)
	}

    // Set the time to 12hrs in the future
	t2 := t.Add(12 * time.Hour)
	if err := clock.Set(t2); err != nil {
		panic(err)
	}

}

Documentation

Overview

Package clock is a portable library for setting the system clock. Supports nanosecond resolution for Linux/Darwin, and second resolution on Windows. All time values get/set are UTC. Tested on Linux/Darwin/Windows.

 package main

 import (
		"time"
		"github.com/PaulMaddox/clock"
 )

 func main() {

		// Get the time
		t, err := clock.Get()
		if err != nil {
			panic(err)
		}

		// Set the time
		t2 := t.Add(12 * time.Hour)
		if err := clock.Set(t2); err != nil {
			panic(err)
		}
 }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() (*time.Time, error)

Get retrieves the current system time, either via syscall.Gettimeofday on Linux/Darwin or via kernel32.GetSystemTime() on Windows. It then parses the result into a standard time.Time struct.

func Set

func Set(input time.Time) error

Set sets the current system time, either via syscall.Settimeofday on Linux/Darwin or via kernel32.SetSystemtime() on Windows.

Types

This section is empty.

Jump to

Keyboard shortcuts

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