@@ -23,47 +23,49 @@ class Snowflake implements Comparable<Snowflake> {
2323 static const bulkDeleteLimit = Duration (days: 14 );
2424
2525 /// A snowflake with a value of 0.
26- static const zero = Snowflake (0 );
26+ static var zero = Snowflake (0 );
2727
2828 /// The value of this snowflake.
2929 ///
3030 /// While this is stored in a signed [int] , Discord treats this as an unsigned value.
31- final int value;
31+ final BigInt value;
3232
3333 /// The time at which this snowflake was created.
34- DateTime get timestamp => epoch.add (Duration (milliseconds: millisecondsSinceEpoch));
34+ DateTime get timestamp => epoch.add (Duration (milliseconds: millisecondsSinceEpoch. toInt () ));
3535
3636 /// The number of milliseconds since the [epoch] .
3737 ///
3838 /// Discord uses a non-standard epoch for their snowflakes. As such,
3939 /// [DateTime.fromMillisecondsSinceEpoch] will not work with this value. Users should instead use
4040 /// the [timestamp] getter.
41- int get millisecondsSinceEpoch => value >> 22 ;
41+ BigInt get millisecondsSinceEpoch => value >> 22 ;
4242
4343 /// The internal worker ID for this snowflake.
4444 ///
4545 /// {@template internal_field}
4646 /// This is an internal field and has no practical application.
4747 /// {@endtemplate}
48- int get workerId => (value & 0x3E0000 ) >> 17 ;
48+ BigInt get workerId => (value & BigInt . parse ( " 0x3E0000" ) ) >> 17 ;
4949
5050 /// The internal process ID for this snowflake.
5151 ///
5252 /// {@macro internal_field}
53- int get processId => (value & 0x1F000 ) >> 12 ;
53+ BigInt get processId => (value & BigInt . parse ( " 0x1F000" ) ) >> 12 ;
5454
5555 /// The internal increment value for this snowflake.
5656 ///
5757 /// {@macro internal_field}
58- int get increment => value & 0xFFF ;
58+ BigInt get increment => value & BigInt . parse ( " 0xFFF" ) ;
5959
6060 /// Whether this snowflake has a value of `0` .
61- bool get isZero => value == 0 ;
61+ bool get isZero => value. toInt () == 0 ;
6262
6363 /// Create a new snowflake from an integer value.
6464 ///
6565 /// {@macro snowflake}
66- const Snowflake (this .value);
66+ const Snowflake .fromBigInt (this .value);
67+
68+ Snowflake (int value): value = BigInt .from (value);
6769
6870 /// Parse a string or integer value to a snowflake.
6971 ///
@@ -75,13 +77,13 @@ class Snowflake implements Comparable<Snowflake> {
7577 // TODO: This method will fail once snowflakes become larger than 2^63.
7678 // We need to parse the unsigned [value] into a signed [int].
7779 factory Snowflake .parse (Object /* String | int */ value) {
78- assert (value is String || value is int );
80+ assert (value is String || value is int || value is BigInt );
7981
80- if (value is ! int ) {
81- value = int .parse (value.toString ());
82+ if (value is ! BigInt ) {
83+ value = BigInt .parse (value.toString ());
8284 }
8385
84- return Snowflake (value);
86+ return Snowflake . fromBigInt (value);
8587 }
8688
8789 /// Create a snowflake with a timestamp equal to the current time.
@@ -100,7 +102,7 @@ class Snowflake implements Comparable<Snowflake> {
100102 'Cannot create a Snowflake before the epoch.' ,
101103 );
102104
103- return Snowflake (dateTime.difference (epoch).inMilliseconds << 22 );
105+ return Snowflake . parse (dateTime.difference (epoch).inMilliseconds << 22 );
104106 }
105107
106108 /// Create a snowflake representing the oldest time at which bulk delete operations will work.
0 commit comments