clock

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

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

Go to latest
Published: Nov 3, 2022 License: BSD-3-Clause Imports: 10 Imported by: 0

README

go-world-clock

There are many world clocks. This one is mine.

Documentation

Documentation is in progress and incomplete at this time.

Go Reference

Usage

import (
	"github.com/aaronland/go-world-clock"
	"log"
        "time"
)

func main(){

	now := time.Now()
	here := now.Local()

	filters := &clock.Filters{
		Timezones: []string{ "Montreal" },
	}

	results, _ := clock.Time(ctx, here, filters)

	for _, r := range results {
		log.Printf("%s %s\n", r.Timezone, r.Time.Format(time.RFC3339))
	}
}

Tools

time

Print the local time as well as the time in one or more timezones.

$> ./bin/time -h
Print the local time as well as the time in one or more timezones.

Usage:
	 ./bin/time [options]

Valid options are:
  -date string
    	YYYY-MM-dd HH:mm. If empty the current time in the computer's locale will be used.
  -in value
    	Zero or more strings to test whether they are contained by a given timezone's longform (major/minor) label.
  -timezone string
    	A valid major/minor timezone location. Required if -date is not empty.
Example:
$> ./bin/time  -in Melbourne -in Cairo -in Honolulu -in China -in Montreal -in London
Pacific/Honolulu         HST	Tuesday    2021-09-14 13:38
👉                       PDT	Tuesday    2021-09-14 16:38 👈
America/Montreal         EDT	Tuesday    2021-09-14 19:38
Europe/London            BST	Wednesday  2021-09-15 00:38
Africa/Cairo             EET	Wednesday  2021-09-15 01:38
Australia/Melbourne      AEST	Wednesday  2021-09-15 09:38

Or specifying a custom date in a timezone:

$> ./bin/time  -date '2021-09-15 03:00' -timezone 'Asia/Singapore' -in London -in 'Los_Angeles'
America/Los_Angeles      PDT	Tuesday    2021-09-14 12:00
Europe/London            BST	Tuesday    2021-09-14 20:00
👉                       +08	Wednesday  2021-09-15 03:00 👈

Documentation

Overview

package clock provides methods for determining the corresponding time in other timezones in the world.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filters

type Filters struct {
	// Zero or more strings to test whether they are contained by a given timezone's longform (major/minor) label.
	Timezones []string
}

type Filter provides definitions for filtering timezone results

type Location

type Location struct {
	// The (string) Who's On First ID associated with the timezone
	Id string
	// The major/minor label for the timezone
	Timezone string
	// The time in that timezone
	Time time.Time
}

type Location contains structured data about the time in a given timezone

func Time

func Time(ctx context.Context, source time.Time, f *Filters) ([]*Location, error)

Time will return zero or more Location records in other timezones for the time defined in source. Results may be limited by passing in a Filter instance with zero or more limits.

Directories

Path Synopsis
cmd
time
time will print the local time as well as the time in one or more timezones.
time will print the local time as well as the time in one or more timezones.
package timezones provides methods for loading timezone information derived from Who's On First data.
package timezones provides methods for loading timezone information derived from Who's On First data.

Jump to

Keyboard shortcuts

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