@@ -12,6 +12,7 @@ use std::{
1212 hash:: { Hash , Hasher } ,
1313 ptr:: null_mut,
1414 sync:: atomic:: { AtomicPtr , AtomicU64 , Ordering } ,
15+ time:: SystemTime ,
1516} ;
1617use uuid:: { Builder , Bytes , Context , Timestamp , Uuid , Variant , Version } ;
1718
@@ -305,13 +306,17 @@ impl UUID {
305306#[ pyo3( signature = ( node=None , clock_seq=None ) ) ]
306307fn uuid1 ( node : Option < u64 > , clock_seq : Option < u64 > ) -> PyResult < UUID > {
307308 let node = match node {
308- Some ( node) => node. to_ne_bytes ( ) ,
309- None => _getnode ( ) . to_ne_bytes ( ) ,
309+ Some ( node) => node. to_be_bytes ( ) ,
310+ None => _getnode ( ) . to_be_bytes ( ) ,
310311 } ;
311- let node = & [ node [ 0 ] , node [ 1 ] , node[ 2 ] , node [ 3 ] , node [ 4 ] , node [ 5 ] ] ;
312+ let node: & [ u8 ; 6 ] = node[ 2 .. 8 ] . try_into ( ) . unwrap ( ) ;
312313 let uuid = match clock_seq {
313314 Some ( clock_seq) => {
314- let ts = Timestamp :: from_unix ( & Context :: new_random ( ) , clock_seq, 0 ) ;
315+ let dur = SystemTime :: now ( )
316+ . duration_since ( SystemTime :: UNIX_EPOCH )
317+ . unwrap ( ) ;
318+ let ts =
319+ Timestamp :: from_unix_time ( dur. as_secs ( ) , dur. subsec_nanos ( ) , clock_seq as u128 , 14 ) ;
315320 Uuid :: new_v1 ( ts, node)
316321 }
317322 None => Uuid :: now_v1 ( node) ,
@@ -354,17 +359,16 @@ fn uuid5(namespace: &UUID, name: StringOrBytes) -> PyResult<UUID> {
354359#[ pyo3( signature = ( node=None , timestamp=None , nanos=None ) ) ]
355360fn uuid6 ( node : Option < u64 > , timestamp : Option < u64 > , nanos : Option < u32 > ) -> PyResult < UUID > {
356361 let node = match node {
357- Some ( node) => node. to_ne_bytes ( ) ,
358- None => _getnode ( ) . to_ne_bytes ( ) ,
362+ Some ( node) => node. to_be_bytes ( ) ,
363+ None => _getnode ( ) . to_be_bytes ( ) ,
359364 } ;
360- let node = & [ node [ 0 ] , node [ 1 ] , node[ 2 ] , node [ 3 ] , node [ 4 ] , node [ 5 ] ] ;
365+ let node: & [ u8 ; 6 ] = node[ 2 .. 8 ] . try_into ( ) . unwrap ( ) ;
361366
362367 let uuid = match timestamp {
363368 Some ( timestamp) => {
364- let timestamp =
365- Timestamp :: from_unix ( & Context :: new_random ( ) , timestamp, nanos. unwrap_or ( 0 ) ) ;
369+ let ts = Timestamp :: from_unix ( & Context :: new_random ( ) , timestamp, nanos. unwrap_or ( 0 ) ) ;
366370 return Ok ( UUID {
367- uuid : Uuid :: new_v6 ( timestamp , node) ,
371+ uuid : Uuid :: new_v6 ( ts , node) ,
368372 } ) ;
369373 }
370374 None => Uuid :: now_v6 ( node) ,
0 commit comments