@@ -44,14 +44,14 @@ pub struct PrimitiveDateTime {
4444impl Hash for PrimitiveDateTime {
4545 #[ inline]
4646 fn hash < H : Hasher > ( & self , state : & mut H ) {
47- self . as_u128 ( ) . hash ( state) ;
47+ self . as_i128 ( ) . hash ( state) ;
4848 }
4949}
5050
5151impl PartialEq for PrimitiveDateTime {
5252 #[ inline]
5353 fn eq ( & self , other : & Self ) -> bool {
54- self . as_u128 ( ) . eq ( & other. as_u128 ( ) )
54+ self . as_i128 ( ) . eq ( & other. as_i128 ( ) )
5555 }
5656}
5757
@@ -65,17 +65,21 @@ impl PartialOrd for PrimitiveDateTime {
6565impl Ord for PrimitiveDateTime {
6666 #[ inline]
6767 fn cmp ( & self , other : & Self ) -> Ordering {
68- self . as_u128 ( ) . cmp ( & other. as_u128 ( ) )
68+ self . as_i128 ( ) . cmp ( & other. as_i128 ( ) )
6969 }
7070}
7171
7272impl PrimitiveDateTime {
73- /// Provide a representation of `PrimitiveDateTime` as a `u128 `. This value can be used for
73+ /// Provide a representation of `PrimitiveDateTime` as a `i128 `. This value can be used for
7474 /// equality, hashing, and ordering.
75+ ///
76+ /// **Note**: This value is explicitly signed, so do not cast this to or treat this as an
77+ /// unsigned integer. Doing so will lead to incorrect results for values with differing
78+ /// signs.
7579 #[ inline]
76- const fn as_u128 ( self ) -> u128 {
77- let time = self . time . as_u64 ( ) as u128 ;
78- let date = self . date . as_u32 ( ) as u128 ;
80+ const fn as_i128 ( self ) -> i128 {
81+ let time = self . time . as_u64 ( ) as i128 ;
82+ let date = self . date . as_i32 ( ) as i128 ;
7983 ( date << 64 ) | time
8084 }
8185
0 commit comments