Documentation
¶
Index ¶
- Constants
- type Duration
- func (z *Duration) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Duration) EncodeMsg(en *msgp.Writer) (err error)
- func (z Duration) MarshalMsg(b []byte) (o []byte, err error)
- func (d Duration) MarshalText() ([]byte, error)
- func (z Duration) Msgsize() (s int)
- func (d Duration) String() string
- func (d Duration) TimeDuration() time.Duration
- func (z *Duration) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (d *Duration) UnmarshalText(text []byte) error
- func (d *Duration) UpdateWeightedAverageAge(sinceLastUpdate Duration, transferQty Ndau, previousBalance Ndau) error
- type Ndau
- func (n Ndau) Abs() Ndau
- func (n Ndau) Add(other Ndau) (Ndau, error)
- func (n Ndau) Compare(rhs Ndau) int
- func (z *Ndau) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Ndau) EncodeMsg(en *msgp.Writer) (err error)
- func (z Ndau) MarshalMsg(b []byte) (o []byte, err error)
- func (z Ndau) Msgsize() (s int)
- func (n Ndau) String() string
- func (n Ndau) Sub(other Ndau) (Ndau, error)
- func (z *Ndau) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Timestamp
- func (t Timestamp) Add(d Duration) Timestamp
- func (t Timestamp) AsTime() time.Time
- func (t Timestamp) Compare(o Timestamp) int
- func (z *Timestamp) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Timestamp) EncodeMsg(en *msgp.Writer) (err error)
- func (z Timestamp) MarshalMsg(b []byte) (o []byte, err error)
- func (t Timestamp) MarshalText() ([]byte, error)
- func (z Timestamp) Msgsize() (s int)
- func (t Timestamp) Since(o Timestamp) Duration
- func (t Timestamp) String() string
- func (t Timestamp) Sub(d Duration) Timestamp
- func (z *Timestamp) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (t *Timestamp) UnmarshalText(text []byte) error
Constants ¶
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 ¶
DurationFrom creates a Duration given a time.Duration object
func ParseDuration ¶
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) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (Duration) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (Duration) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (Duration) TimeDuration ¶
TimeDuration converts a Duration into a time.Duration
func (*Duration) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*Duration) UnmarshalText ¶
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 ¶
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 ¶
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) Compare ¶
Compare is the sorting operator; it returns -1 if n < rhs, 1 if n > rhs, and 0 if they are equal.
func (Ndau) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (Ndau) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
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 ¶
ParseTimestamp creates a timestamp from an ISO-3933 string
func TimestampFrom ¶
TimestampFrom creates a Timestamp given a time.Time object
func (Timestamp) Add ¶
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 ¶
AsTime converts a Timestamp into a time.Time object
TODO: implement this in a way which ensures its monotonic properties
func (Timestamp) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (Timestamp) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (Timestamp) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (Timestamp) Since ¶
Since measures the Duration between two Timestamps. It will be positive when the argument is older, so present.Since(past) > 0
func (*Timestamp) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*Timestamp) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler