Documentation ¶
Overview ¶
Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func Check(t time.Time) error
- func CheckPb(t *timestamppb.Timestamp) error
- func CheckTimeRange(timeRange *modelv1.TimeRange) error
- func MToN(ms time.Time) time.Time
- func NowMilli() time.Time
- func ParseDuration(s string) (time.Duration, error)
- func SetClock(ctx context.Context, clock Clock) context.Context
- type Clock
- type MockClock
- type TimeRange
- func NewInclusiveTimeRange(start, end time.Time) TimeRange
- func NewInclusiveTimeRangeDuration(start time.Time, duration time.Duration) TimeRange
- func NewSectionTimeRange(start, end time.Time) TimeRange
- func NewTimeRange(start, end time.Time, includeStart, includeEnd bool) TimeRange
- func NewTimeRangeDuration(start time.Time, duration time.Duration, includeStart, includeEnd bool) TimeRange
Constants ¶
const ( // MinNanoTime is the minimum time that can be represented. // // 1677-09-21 00:12:43.145224192 +0000 UTC MinNanoTime = int64(math.MinInt64) // MaxNanoTime is the maximum time that can be represented. // // 2262-04-11 23:47:16.854775807 +0000 UTC MaxNanoTime = int64(math.MaxInt64) )
Variables ¶
var ( MaxMilliTime = time.UnixMilli(maxNanoTime.UnixMilli()) MaxMilliPbTime = timestamppb.New(MaxMilliTime) DefaultBeginPbTime = timestamppb.New(time.Unix(0, 0)) DefaultTimeRange = &modelv1.TimeRange{ Begin: DefaultBeginPbTime, End: MaxMilliPbTime, } ErrTimeOutOfRange = errors.Errorf("time is out of range %d - %d", MinNanoTime, MaxNanoTime) ErrTimeNotMillisecond = errors.Errorf("time is not millisecond precision") ErrTimeEmpty = errors.Errorf("time is empty") )
Functions ¶
func CheckPb ¶
func CheckPb(t *timestamppb.Timestamp) error
CheckPb checks that a protobuf timestamp is valid
func CheckTimeRange ¶
CheckTimeRange checks that a protobuf time range is valid
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".
Types ¶
type Clock ¶
Clock represents an interface contains all functions in the standard library time.