mtime

package
v2.44.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0, BSD-3-Clause, MIT Imports: 3 Imported by: 37

Documentation

Overview

Package mtime contains a millisecond representation of time. The purpose of this representation is alignment with the Beam specification, where we need extreme values outside the range of time.Time for windowing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Time

type Time int64

Time is the number of milli-seconds since the Unix epoch. The valid range of times is bounded by what can be represented a _micro_-seconds-since-epoch.

const (
	// MinTimestamp is the minimum value for any Beam timestamp. Often referred to
	// as "-infinity". This value and MaxTimestamp are chosen so that their
	// microseconds-since-epoch can be safely represented with an int64 and boundary
	// values can be represented correctly with millisecond precision.
	MinTimestamp Time = math.MinInt64 / 1000

	// MaxTimestamp is the maximum value for any Beam timestamp. Often referred to
	// as "+infinity".
	MaxTimestamp Time = math.MaxInt64 / 1000

	// EndOfGlobalWindowTime is the timestamp at the end of the global window. It
	// is a day before the max timestamp.
	// TODO(https://github.com/apache/beam/issues/18951) Use GLOBAL_WINDOW_MAX_TIMESTAMP_MILLIS from the Runner API constants
	EndOfGlobalWindowTime = MaxTimestamp - 24*60*60*1000

	// ZeroTimestamp is the default zero value time. It corresponds to the unix epoch.
	ZeroTimestamp Time = 0
)

func FromDuration

func FromDuration(d time.Duration) Time

FromDuration returns a timestamp from a time.Duration-since-epoch value.

func FromMilliseconds

func FromMilliseconds(unixMilliseconds int64) Time

FromMilliseconds returns a timestamp from a raw milliseconds-since-epoch value.

func FromTime

func FromTime(t time.Time) Time

FromTime returns a milli-second precision timestamp from a time.Time.

func Max

func Max(a, b Time) Time

Max returns the largest (latest) time.

func Min

func Min(a, b Time) Time

Min returns the smallest (earliest) time.

func Normalize

func Normalize(t Time) Time

Normalize ensures a Time is within [MinTimestamp,MaxTimestamp].

func Now

func Now() Time

Now returns the current time.

func (Time) Add

func (t Time) Add(d time.Duration) Time

Add returns the time plus the duration. Input Durations of less than one millisecond will not increment the time due to a loss of precision when converting to milliseconds.

func (Time) Milliseconds

func (t Time) Milliseconds() int64

Milliseconds returns the number of milli-seconds since the Unix epoch.

func (Time) String

func (t Time) String() string

func (Time) Subtract

func (t Time) Subtract(d time.Duration) Time

Subtract returns the time minus the duration. Input Durations of less than one millisecond will not increment the time due to a loss of precision when converting to milliseconds.

func (Time) ToTime added in v2.39.0

func (t Time) ToTime() time.Time

ToTime returns the Time represented as a time.Time

Jump to

Keyboard shortcuts

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