Documentation
¶
Overview ¶
Package timezone is the timezone behavior: the timezone of the host.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Behavior = behavior.Register(behavior.Define( "timezone", "The timezone of the host", behavior.Node, behavior.API, behavior.Area(area.Config), behavior.CLI, behavior.Platform(behavior.PlatformLinux, newReader), behavior.Platform(behavior.PlatformDarwin, newReader), behavior.Read("get", Get). Describe("Get the timezone of the host"). Explain("Reads the IANA name of the timezone and its offset from UTC now: the "+ "zone that /etc/localtime links to, or /etc/timezone on Linux."). Example("A Linux host on UTC", GetInput{}, Entry{Timezone: "UTC", UTCOffset: "+00:00"}, behavior.OnPlatform(behavior.PlatformLinux), behavior.Exists("/etc/timezone", "UTC\n"), ). Example("A Mac on UTC", GetInput{}, Entry{Timezone: "UTC", UTCOffset: "+00:00"}, behavior.OnPlatform(behavior.PlatformDarwin), behavior.Links("/etc/localtime", "/var/db/timezone/zoneinfo/UTC"), ), behavior.Write("update", Update). On(behavior.PlatformDebian). Runs("timedatectl"). Sudo("timedatectl"). Describe("Set the timezone of the host"). Explain("Sets the timezone with timedatectl set-timezone. A host that already "+ "has the timezone does not change and reports changed: false. It runs on "+ "the Debian family only, and elsewhere reports skipped."). Example("Set a new timezone", UpdateInput{Timezone: "America/New_York"}, Result{Timezone: "America/New_York", Changed: true}, behavior.Prints(show, "UTC\n"), behavior.PrintsAfter("timedatectl set-timezone America/New_York", show, "America/New_York\n"), behavior.Ran("timedatectl", "set-timezone", "America/New_York"), behavior.Reads(GetInput{}, Entry{Timezone: "America/New_York"}), ). Example("A host that already has the timezone", UpdateInput{Timezone: "UTC"}, Result{Timezone: "UTC"}, behavior.After(UpdateInput{Timezone: "UTC"}), behavior.Prints(show, "America/New_York\n"), behavior.PrintsAfter("timedatectl set-timezone UTC", show, "UTC\n"), behavior.Reads(GetInput{}, Entry{Timezone: "UTC"}), ). Fails("A name that is not a timezone", UpdateInput{Timezone: "../../etc/passwd"}, "not a valid timezone name"). Fails("A name that starts with a dash", UpdateInput{Timezone: "-UTC"}, "not a valid timezone name"). Fails("A name longer than 64 characters", UpdateInput{Timezone: strings.Repeat("a", 65)}, "timezone"), ))
Behavior is the timezone of the host. gohai reads it on every platform; timedatectl sets it on the Debian family.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Timezone string `json:"timezone" doc:"The IANA name of the timezone, such as America/New_York"`
UTCOffset string `json:"utc_offset" doc:"The offset from UTC now, such as -05:00"`
}
Entry is the timezone of the host.
type Provider ¶
type Provider interface {
// Timezone is the timezone of the host now.
Timezone(ctx context.Context) (Entry, error)
// SetTimezone sets the timezone, and reports whether it changed.
SetTimezone(ctx context.Context, name string) (bool, error)
}
Provider reads and sets the timezone of the host.
type Result ¶
type Result struct {
Timezone string `json:"timezone" doc:"The timezone of the host"`
Changed bool `json:"changed" doc:"Whether the host changed"`
}
Result is the timezone after the update.
type UpdateInput ¶
type UpdateInput struct {
Timezone string `` /* 142-byte string literal not displayed */
}
UpdateInput is the timezone to set.