1313// See the License for the specific language governing permissions and
1414// limitations under the License.
1515
16+ use std:: cmp:: Ordering ;
1617use std:: convert:: TryFrom ;
18+ use std:: hash:: Hash ;
19+ use std:: hash:: Hasher ;
1720use std:: ops:: Neg ;
1821use std:: panic:: RefUnwindSafe ;
1922
@@ -252,11 +255,7 @@ impl NativeType for days_ms {
252255 Copy ,
253256 Clone ,
254257 Default ,
255- PartialEq ,
256- PartialOrd ,
257- Ord ,
258258 Eq ,
259- Hash ,
260259 Zeroable ,
261260 Pod ,
262261 Serialize ,
@@ -268,6 +267,33 @@ impl NativeType for days_ms {
268267#[ repr( C ) ]
269268pub struct months_days_micros ( pub i128 ) ;
270269
270+ const MICROS_PER_DAY : i64 = 24 * 3600 * 1_000_000 ;
271+ const MICROS_PER_MONTH : i64 = 30 * MICROS_PER_DAY ;
272+
273+ impl Hash for months_days_micros {
274+ fn hash < H : Hasher > ( & self , state : & mut H ) {
275+ self . total_micros ( ) . hash ( state)
276+ }
277+ }
278+ impl PartialEq for months_days_micros {
279+ fn eq ( & self , other : & Self ) -> bool {
280+ self . total_micros ( ) == other. total_micros ( )
281+ }
282+ }
283+ impl PartialOrd for months_days_micros {
284+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
285+ Some ( self . cmp ( other) )
286+ }
287+ }
288+
289+ impl Ord for months_days_micros {
290+ fn cmp ( & self , other : & Self ) -> Ordering {
291+ let total_micros = self . total_micros ( ) ;
292+ let other_micros = other. total_micros ( ) ;
293+ total_micros. cmp ( & other_micros)
294+ }
295+ }
296+
271297impl months_days_micros {
272298 pub fn new ( months : i32 , days : i32 , microseconds : i64 ) -> Self {
273299 let months_bits = ( months as i128 ) << 96 ;
@@ -291,10 +317,16 @@ impl months_days_micros {
291317 pub fn microseconds ( & self ) -> i64 {
292318 ( self . 0 & 0xFFFFFFFFFFFFFFFF ) as i64
293319 }
320+
321+ pub fn total_micros ( & self ) -> i64 {
322+ ( self . months ( ) as i64 * MICROS_PER_MONTH )
323+ + ( self . days ( ) as i64 * MICROS_PER_DAY )
324+ + self . microseconds ( )
325+ }
294326}
295327
296328impl NativeType for months_days_micros {
297- const PRIMITIVE : PrimitiveType = PrimitiveType :: MonthDayNano ;
329+ const PRIMITIVE : PrimitiveType = PrimitiveType :: MonthDayMicros ;
298330 type Bytes = [ u8 ; 16 ] ;
299331 #[ inline]
300332 fn to_le_bytes ( & self ) -> Self :: Bytes {
0 commit comments