types

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 11 Imported by: 23

Documentation

Index

Constants

View Source
const (
	// Microsecond is a thousandth of a millisecond
	Microsecond = 1
	// Millisecond is a thousandth of a second
	Millisecond = Microsecond * 1000
	// Second is the duration of 9 192 631 770 periods of the
	// radiation corresponding to the transition between the two
	// hyperfine levels of the ground state of the cesium 133 atom,
	// per the 13th CGPM (1967).
	Second = Millisecond * 1000
	// Minute is exactly 60 Seconds
	Minute = Second * 60
	// Hour is exactly 60 Minutes
	Hour = Minute * 60
	// Day is exactly 24 Hours
	Day = Hour * 24
	// Month is exactly 30 Days
	Month = Day * 30
	// Year is exactly 365 days
	Year = Day * 365
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration int64

A Duration is the difference between two Timestamps.

It can be negative if the timestamps are out of order.

func DurationFrom

func DurationFrom(d time.Duration) Duration

DurationFrom creates a Duration given a time.Duration object

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration creates a duration from a duration string

Allowable durations broadly follow the RFC3339 duration specification: `\dy\dm\dd(t\dh\dm\ds)`. Note that `m` is used for both months and minutes: `1m` is one month, and `t1m` is one minute. Per RFC3339, leading `p` chars are allowed.

There is no `w` symbol for weeks; use multiples of days or months instead.

func (*Duration) DecodeMsg

func (z *Duration) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Duration) EncodeMsg

func (z Duration) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Duration) MarshalMsg

func (z Duration) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Duration) Msgsize

func (z Duration) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Duration) String

func (d Duration) String() string

String represents a Duration as a human-readable string

func (Duration) TimeDuration

func (d Duration) TimeDuration() time.Duration

TimeDuration converts a Duration into a time.Duration

func (*Duration) UnmarshalMsg

func (z *Duration) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

func (*Duration) UpdateWeightedAverageAge

func (d *Duration) UpdateWeightedAverageAge(
	sinceLastUpdate Duration,
	transferQty Ndau,
	previousBalance Ndau,
) error

UpdateWeightedAverageAge computes the weighted average age. Note that this function may cause order-dependent behavior; it does integer division, and for small values, the order in which updates to WAA are applied may be significant. We found and fixed a bug related to this in the CreditEAI calculation; see duration_test.go for details.

type Ndau

type Ndau int64

Ndau is a value that holds a single amount of ndau. Unlike an int64, it is prevented from overflowing.

func ParseNdau

func ParseNdau(s string) (Ndau, error)

ParseNdau inverts n.String(): it converts a quantity of ndau expressed as a decimal number into a quantity of Ndau, without ever going through an intermediate floating-point step in which it may lose precision or behave nondeterministically.

func (Ndau) Abs

func (n Ndau) Abs() Ndau

Abs returns the absolute value without converting to float NOTE THAT THIS FAILS IN THE CASE WHERE n == MinInt64 (this value acts as much like -0 as it does MinInt). In particular, the value consists of only the negative (high) bit and the rest are zeros.

As quantities on the blockchain can't be negative, we are going to ignore this case in favor of simplicity.

In particular, this function a) can be inlined, and b) has no conditionals.

func (Ndau) Add

func (n Ndau) Add(other Ndau) (Ndau, error)

Add adds a value to an Ndau It may return an overflow error

func (Ndau) Compare

func (n Ndau) Compare(rhs Ndau) int

Compare is the sorting operator; it returns -1 if n < rhs, 1 if n > rhs, and 0 if they are equal.

func (*Ndau) DecodeMsg

func (z *Ndau) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Ndau) EncodeMsg

func (z Ndau) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Ndau) MarshalMsg

func (z Ndau) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Ndau) Msgsize

func (z Ndau) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Ndau) String

func (n Ndau) String() string

String returns the value of n formatted in a standard format, as if it is a decimal value of ndau. The full napu value is displayed, but trailing zeros are suppressed.

func (Ndau) Sub

func (n Ndau) Sub(other Ndau) (Ndau, error)

Sub subtracts, and may overflow

func (*Ndau) UnmarshalMsg

func (z *Ndau) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Timestamp

type Timestamp int64

A Timestamp is a single moment in time.

It is monotonically increasing with the passage of time, and represents the number of microseconds since the epoch. It has no notion of leap time, time zones, or other complicating human factors. A timestamp can never be negative, but for mathematical simplicity we represent it with an int64. The total range of timestamps is almost 300,000 years.

func ParseTimestamp

func ParseTimestamp(s string) (Timestamp, error)

ParseTimestamp creates a timestamp from an ISO-3933 string

func TimestampFrom

func TimestampFrom(t time.Time) (Timestamp, error)

TimestampFrom creates a Timestamp given a time.Time object

func (Timestamp) Add

func (t Timestamp) Add(d Duration) Timestamp

Add adds the supplied Duration to the given Timestamp If the result is negative, returns 0 If the result overflows, returns MaxTimestamp

func (Timestamp) AsTime

func (t Timestamp) AsTime() time.Time

AsTime converts a Timestamp into a time.Time object

TODO: implement this in a way which ensures its monotonic properties

func (Timestamp) Compare

func (t Timestamp) Compare(o Timestamp) int

Compare implements comparison for Timestamp. (useful in sorting)

func (*Timestamp) DecodeMsg

func (z *Timestamp) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Timestamp) EncodeMsg

func (z Timestamp) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Timestamp) MarshalMsg

func (z Timestamp) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Timestamp) Msgsize

func (z Timestamp) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Timestamp) Since

func (t Timestamp) Since(o Timestamp) Duration

Since measures the Duration between two Timestamps. It will be positive when the argument is older, so present.Since(past) > 0

func (Timestamp) String

func (t Timestamp) String() string

func (Timestamp) Sub

func (t Timestamp) Sub(d Duration) Timestamp

Sub subtracts the supplied Duration from the given Timestamp

func (*Timestamp) UnmarshalMsg

func (z *Timestamp) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Timestamp) UnmarshalText

func (t *Timestamp) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

Jump to

Keyboard shortcuts

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