agdtime

package
v0.0.0-...-f179113 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 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 Clock

type Clock interface {
	Now() (now time.Time)
}

Clock is an interface for time-related operations.

TODO(a.garipov): Expand with operations like After or Tick.

TODO(a.garipov): Move to golibs/timeutil.

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.

type SystemClock

type SystemClock struct{}

SystemClock is a Clock that uses the functions from package time.

func (SystemClock) Now

func (SystemClock) Now() (now time.Time)

Now implements the Clock interface for SystemClock.

Jump to

Keyboard shortcuts

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