agdtime

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package agdtime contains time-related utilities.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location struct {
	time.Location
}

Location is a wrapper around time.Location that can de/serialize itself from and to JSON.

TODO(a.garipov): Move to timeutil.

Example
package main

import (
	"bytes"
	"encoding/json"
	"fmt"

	"github.com/AdguardTeam/AdGuardDNS/internal/agdtime"
)

func main() {
	var req struct {
		TimeZone *agdtime.Location `json:"tmz"`
	}

	l, err := agdtime.LoadLocation("Europe/Brussels")
	if err != nil {
		panic(err)
	}

	req.TimeZone = l
	buf := &bytes.Buffer{}
	err = json.NewEncoder(buf).Encode(req)
	if err != nil {
		panic(err)
	}

	fmt.Print(buf)

	req.TimeZone = nil
	err = json.NewDecoder(buf).Decode(&req)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%+v\n", req)

}
Output:

{"tmz":"Europe/Brussels"}
{TimeZone:Europe/Brussels}

func LoadLocation

func LoadLocation(name string) (l *Location, err error)

LoadLocation is a wrapper around time.LoadLocation that returns a *Location instead.

func UTC

func UTC() (l *Location)

UTC returns time.UTC as *Location.

func (Location) MarshalText

func (l Location) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface for Location.

func (*Location) UnmarshalText

func (l *Location) UnmarshalText(b []byte) (err error)

UnmarshalText implements the encoding.TextUnmarshaler interface for *Location.

Jump to

Keyboard shortcuts

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