datepb

package
v0.0.0-...-6251ae7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package datepb provides utilities for googleapis/types/date.Date conversion.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Date

func Date(ts time.Time) *date.Date

Date converts a standard time.Time to a googleapis/type/date.Date in UTC timezone.

func Interval

func Interval(date *date.Date) (start, end time.Time)

Interval returns a start and end time.Time for the given period in UTC. The precision of the period is determined by the populated fields. start is always at 00:00 on the beginning of the period. end is the period increased by 1, minus 1ns. For example:

  • if day is non-zero the period starts at 00:00 and ends 1ns before end of day.
  • if day is zero and month is non-zero the period starts on the first day 00:00 and ends 1ns before the end of the last day of the month.
  • if day and month are zero, the period starts on 1st of January 00:00 and ends on 31st of December 23:59:00
Example (Day)
start, end := Interval(&date.Date{
	Year:  1986,
	Month: 3,
	Day:   25,
})

fmt.Println(start, end)
Output:

1986-03-25 00:00:00 +0000 UTC 1986-03-25 23:59:59.999999999 +0000 UTC
Example (Month)
start, end := Interval(&date.Date{
	Year:  1986,
	Month: 3,
})

fmt.Println(start, end)
Output:

1986-03-01 00:00:00 +0000 UTC 1986-03-31 23:59:59.999999999 +0000 UTC
Example (Year)
start, end := Interval(&date.Date{
	Year: 1986,
})

fmt.Println(start, end)
Output:

1986-01-01 00:00:00 +0000 UTC 1986-12-31 23:59:59.999999999 +0000 UTC

func Time

func Time(date *date.Date) time.Time

Time converts a googleapis/type/date.Date to a standard time.Time in UTC timezone. A date can represent:

  • a full year when month and day are empty. The time will be 1st of january 00:00 UTC in the given year.
  • a full month when day is empty.
  • an exact date with year, month and day.

Overlowing or negative values are normalized by Go's time.Date() function.

func Today

func Today() *date.Date

Today returns today's date.

Types

This section is empty.

Jump to

Keyboard shortcuts

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