mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
improve timestamp
This commit is contained in:
parent
b2503ae789
commit
fcd9772e00
@ -60,10 +60,11 @@ class VeilidVersion extends Equatable {
|
|||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
/// Timestamp
|
/// Timestamp
|
||||||
@immutable
|
@immutable
|
||||||
class Timestamp extends Equatable {
|
class Timestamp extends Equatable implements Comparable<Timestamp> {
|
||||||
const Timestamp({required this.value});
|
const Timestamp({required this.value});
|
||||||
factory Timestamp.fromInt64(Int64 i64) =>
|
factory Timestamp.fromInt64(Int64 i64) => Timestamp(
|
||||||
Timestamp(value: BigInt.parse(i64.toStringUnsigned()));
|
value: (BigInt.from((i64 >> 32).toUnsigned(32).toInt()) << 32) |
|
||||||
|
BigInt.from(i64.toUnsigned(32).toInt()));
|
||||||
factory Timestamp.fromString(String s) => Timestamp(value: BigInt.parse(s));
|
factory Timestamp.fromString(String s) => Timestamp(value: BigInt.parse(s));
|
||||||
factory Timestamp.fromJson(dynamic json) =>
|
factory Timestamp.fromJson(dynamic json) =>
|
||||||
Timestamp.fromString(json as String);
|
Timestamp.fromString(json as String);
|
||||||
@ -71,10 +72,14 @@ class Timestamp extends Equatable {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [value];
|
List<Object> get props => [value];
|
||||||
|
|
||||||
|
@override
|
||||||
|
int compareTo(Timestamp other) => value.compareTo(other.value);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => value.toString();
|
String toString() => value.toString();
|
||||||
String toJson() => toString();
|
String toJson() => toString();
|
||||||
Int64 toInt64() => Int64.parseInt(value.toString());
|
Int64 toInt64() => Int64.fromInts(
|
||||||
|
(value >> 32).toUnsigned(32).toInt(), value.toUnsigned(32).toInt());
|
||||||
|
|
||||||
TimestampDuration diff(Timestamp other) =>
|
TimestampDuration diff(Timestamp other) =>
|
||||||
TimestampDuration(value: value - other.value);
|
TimestampDuration(value: value - other.value);
|
||||||
@ -84,10 +89,12 @@ class Timestamp extends Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class TimestampDuration extends Equatable {
|
class TimestampDuration extends Equatable
|
||||||
|
implements Comparable<TimestampDuration> {
|
||||||
const TimestampDuration({required this.value});
|
const TimestampDuration({required this.value});
|
||||||
factory TimestampDuration.fromInt64(Int64 i64) =>
|
factory TimestampDuration.fromInt64(Int64 i64) => TimestampDuration(
|
||||||
TimestampDuration(value: BigInt.parse(i64.toStringUnsigned()));
|
value: (BigInt.from((i64 >> 32).toUnsigned(32).toInt()) << 32) |
|
||||||
|
BigInt.from(i64.toUnsigned(32).toInt()));
|
||||||
factory TimestampDuration.fromString(String s) =>
|
factory TimestampDuration.fromString(String s) =>
|
||||||
TimestampDuration(value: BigInt.parse(s));
|
TimestampDuration(value: BigInt.parse(s));
|
||||||
factory TimestampDuration.fromJson(dynamic json) =>
|
factory TimestampDuration.fromJson(dynamic json) =>
|
||||||
@ -96,10 +103,14 @@ class TimestampDuration extends Equatable {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [value];
|
List<Object> get props => [value];
|
||||||
|
|
||||||
|
@override
|
||||||
|
int compareTo(TimestampDuration other) => value.compareTo(other.value);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => value.toString();
|
String toString() => value.toString();
|
||||||
String toJson() => toString();
|
String toJson() => toString();
|
||||||
Int64 toInt64() => Int64.parseInt(value.toString());
|
Int64 toInt64() => Int64.fromInts(
|
||||||
|
(value >> 32).toUnsigned(32).toInt(), value.toUnsigned(32).toInt());
|
||||||
|
|
||||||
int toMillis() => (value ~/ BigInt.from(1000)).toInt();
|
int toMillis() => (value ~/ BigInt.from(1000)).toInt();
|
||||||
BigInt toMicros() => value;
|
BigInt toMicros() => value;
|
||||||
|
Loading…
Reference in New Issue
Block a user