github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/util/timewrapper.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package util 8 9 import ( 10 "time" 11 12 afgotime "github.com/hyperledger/aries-framework-go/component/models/util/time" 13 ) 14 15 // TimeWrapper overrides marshalling of time.Time. If a TimeWrapper is created from a time string, or 16 // unmarshalled from JSON, it saves the string literal, which it uses when marshalling. 17 // If a TimeWrapper is created using NewTime or a struct literal, it marshals with the default 18 // time.RFC3339 format. 19 type TimeWrapper = afgotime.TimeWrapper 20 21 // TimeWithTrailingZeroMsec overrides marshalling of time.Time. It keeps a format of initial unmarshalling 22 // in case when date has zero a fractional second (e.g. ".000"). 23 // For example, time.Time marshals 2018-03-15T00:00:00.000Z to 2018-03-15T00:00:00Z 24 // while TimeWithTrailingZeroMsec marshals to the initial 2018-03-15T00:00:00.000Z value. 25 // 26 // Deprecated: use TimeWrapper instead. 27 type TimeWithTrailingZeroMsec = afgotime.TimeWithTrailingZeroMsec 28 29 // NewTime creates a TimeWrapper wrapped around the given time.Time. 30 // It functions as a normal time.Time object. 31 func NewTime(t time.Time) *TimeWrapper { 32 return afgotime.NewTime(t) 33 } 34 35 // NewTimeWithTrailingZeroMsec creates a TimeWrapper wrapped around the given time.Time. 36 // 37 // Deprecated: use NewTime instead. For sub-zero precision, 38 // use ParseTimeWrapper on a string with the desired precision. 39 func NewTimeWithTrailingZeroMsec(t time.Time, _ int) *TimeWrapper { 40 return afgotime.NewTimeWithTrailingZeroMsec(t, 0) 41 } 42 43 // ParseTimeWithTrailingZeroMsec parses a formatted string and returns the time value it represents. 44 // 45 // Deprecated: use ParseTimeWrapper instead. 46 func ParseTimeWithTrailingZeroMsec(timeStr string) (*TimeWrapper, error) { 47 return afgotime.ParseTimeWithTrailingZeroMsec(timeStr) 48 } 49 50 // ParseTimeWrapper parses a formatted string and returns the time value it represents. 51 func ParseTimeWrapper(timeStr string) (*TimeWrapper, error) { 52 return afgotime.ParseTimeWrapper(timeStr) 53 }