From 77f0f852a5b624a3eb4601d0e92ab3d9a8376957 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 24 Mar 2024 12:13:06 -0400 Subject: [PATCH] add extra timestamp functions --- veilid-flutter/lib/veilid.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/veilid-flutter/lib/veilid.dart b/veilid-flutter/lib/veilid.dart index 7f0d9aea..fbcd6f54 100644 --- a/veilid-flutter/lib/veilid.dart +++ b/veilid-flutter/lib/veilid.dart @@ -77,6 +77,11 @@ class Timestamp extends Equatable implements Comparable { @override int compareTo(Timestamp other) => value.compareTo(other.value); + bool operator <(Timestamp other) => compareTo(other) < 0; + bool operator <=(Timestamp other) => compareTo(other) <= 0; + bool operator >(Timestamp other) => compareTo(other) > 0; + bool operator >=(Timestamp other) => compareTo(other) >= 0; + @override String toString() => value.toString(); String toJson() => toString(); @@ -97,6 +102,11 @@ class TimestampDuration extends Equatable factory TimestampDuration.fromInt64(Int64 i64) => TimestampDuration( value: (BigInt.from((i64 >> 32).toUnsigned(32).toInt()) << 32) | BigInt.from(i64.toUnsigned(32).toInt())); + factory TimestampDuration.fromMillis(int millis) => + TimestampDuration(value: BigInt.from(millis) * BigInt.from(1000)); + factory TimestampDuration.fromDuration(Duration d) => TimestampDuration( + value: BigInt.from(d.inSeconds) * BigInt.from(1000000) + + BigInt.from(d.inMicroseconds % 1000000)); factory TimestampDuration.fromString(String s) => TimestampDuration(value: BigInt.parse(s)); factory TimestampDuration.fromJson(dynamic json) => @@ -108,6 +118,11 @@ class TimestampDuration extends Equatable @override int compareTo(TimestampDuration other) => value.compareTo(other.value); + bool operator <(TimestampDuration other) => compareTo(other) < 0; + bool operator <=(TimestampDuration other) => compareTo(other) <= 0; + bool operator >(TimestampDuration other) => compareTo(other) > 0; + bool operator >=(TimestampDuration other) => compareTo(other) >= 0; + @override String toString() => value.toString(); String toJson() => toString();