@@ -5,8 +5,6 @@ use crate::{
55 types:: Type ,
66} ;
77
8- use std:: str:: FromStr ;
9-
108/// Infaillible `Epoch::now()` call.
119pub ( crate ) fn now ( ) -> Epoch {
1210 Epoch :: now ( ) . unwrap_or ( Epoch :: from_gregorian_utc_at_midnight ( 2000 , 1 , 1 ) )
@@ -265,38 +263,8 @@ pub(crate) fn parse_ionex_utc(s: &str) -> Result<Epoch, ParsingError> {
265263 Ok ( Epoch :: from_gregorian_utc ( y, m, d, hh, mm, ss, 0 ) )
266264}
267265
268- /*
269- * Until Hifitime provides a decomposition method in timescale other than UTC
270- * we have this tweak to decompose %Y %M %D %HH %MM %SS and without nanoseconds
271- */
272- pub ( crate ) fn epoch_decompose ( e : Epoch ) -> ( i32 , u8 , u8 , u8 , u8 , u8 , u32 ) {
273- let isofmt = e. to_gregorian_str ( e. time_scale ) ;
274- let mut datetime = isofmt. split ( 'T' ) ;
275- let date = datetime. next ( ) . unwrap ( ) ;
276- let mut date = date. split ( '-' ) ;
277-
278- let time = datetime. next ( ) . unwrap ( ) ;
279- let mut time_scale = time. split ( ' ' ) ;
280- let time = time_scale. next ( ) . unwrap ( ) ;
281- let mut time = time. split ( ':' ) ;
282-
283- let years = date. next ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) ;
284- let months = date. next ( ) . unwrap ( ) . parse :: < u8 > ( ) . unwrap ( ) ;
285- let days = date. next ( ) . unwrap ( ) . parse :: < u8 > ( ) . unwrap ( ) ;
286-
287- let hours = time. next ( ) . unwrap ( ) . parse :: < u8 > ( ) . unwrap ( ) ;
288- let mins = time. next ( ) . unwrap ( ) . parse :: < u8 > ( ) . unwrap ( ) ;
289- let seconds = f64:: from_str ( time. next ( ) . unwrap ( ) ) . unwrap ( ) ;
290-
291- (
292- years,
293- months,
294- days,
295- hours,
296- mins,
297- seconds. floor ( ) as u8 ,
298- ( seconds. fract ( ) * 1E9 ) . round ( ) as u32 ,
299- )
266+ pub ( crate ) fn epoch_decompose ( epoch : Epoch ) -> ( i32 , u8 , u8 , u8 , u8 , u8 , u32 ) {
267+ epoch. to_gregorian ( epoch. time_scale )
300268}
301269
302270#[ cfg( test) ]
@@ -336,6 +304,7 @@ mod test {
336304 assert_eq ! ( e. time_scale, TimeScale :: UTC ) ;
337305 assert_eq ! ( format( e, Type :: NavigationData , 2 ) , "21 1 1 16 15 0.0" ) ;
338306 }
307+
339308 #[ test]
340309 fn epoch_parse_nav_v2_nanos ( ) {
341310 let e = parse_utc ( "20 12 31 23 45 0.1" ) ;
@@ -346,6 +315,7 @@ mod test {
346315 assert_eq ! ( ns, 100_000_000 ) ;
347316 assert_eq ! ( format( e, Type :: NavigationData , 2 ) , "20 12 31 23 45 0.1" ) ;
348317 }
318+
349319 #[ test]
350320 fn epoch_parse_nav_v3 ( ) {
351321 let e = parse_utc ( "2021 01 01 00 00 00 " ) ;
@@ -401,6 +371,7 @@ mod test {
401371 assert_eq ! ( ns, 0 ) ;
402372 assert_eq ! ( format( e, Type :: NavigationData , 3 ) , "2020 06 25 09 49 04" ) ;
403373 }
374+
404375 #[ test]
405376 fn epoch_parse_obs_v2 ( ) {
406377 let e = parse_utc ( " 21 12 21 0 0 0.0000000" ) ;
@@ -468,6 +439,7 @@ mod test {
468439 "21 1 1 0 7 30.0000000"
469440 ) ;
470441 }
442+
471443 #[ test]
472444 fn epoch_parse_obs_v3 ( ) {
473445 let e = parse_utc ( " 2022 01 09 00 00 0.0000000" ) ;
@@ -534,6 +506,7 @@ mod test {
534506 "2022 03 04 00 02 30.0000000"
535507 ) ;
536508 }
509+
537510 #[ test]
538511 fn epoch_parse_obs_v2_nanos ( ) {
539512 let e = parse_utc ( " 21 1 1 0 7 39.1234567" ) ;
@@ -547,6 +520,7 @@ mod test {
547520 "21 1 1 0 7 39.1234567"
548521 ) ;
549522 }
523+
550524 #[ test]
551525 fn epoch_parse_obs_v3_nanos ( ) {
552526 let e = parse_utc ( "2022 01 09 00 00 0.1000000" ) ;
@@ -582,6 +556,7 @@ mod test {
582556 "2022 01 09 00 00 8.7654321"
583557 ) ;
584558 }
559+
585560 #[ test]
586561 fn epoch_parse_meteo_v2 ( ) {
587562 let e = parse_utc ( " 22 1 4 0 0 0 " ) ;
@@ -597,6 +572,7 @@ mod test {
597572 assert_eq ! ( ns, 0 ) ;
598573 assert_eq ! ( format( e, Type :: MeteoData , 2 ) , "22 1 4 0 0 0" ) ;
599574 }
575+
600576 #[ test]
601577 fn ionex_parsing ( ) {
602578 for ( desc, expected) in [ (
@@ -609,6 +585,7 @@ mod test {
609585 assert_eq ! ( epoch, expected, "invalid IONEX/UTC epoch" ) ;
610586 }
611587 }
588+
612589 #[ test]
613590 fn epoch_decomposition ( ) {
614591 for ( epoch, y, m, d, hh, mm, ss, ns) in [
@@ -630,6 +607,7 @@ mod test {
630607 ) ;
631608 }
632609 }
610+
633611 #[ test]
634612 fn test_formatted_month ( ) {
635613 assert_eq ! ( parse_formatted_month( "Jan" ) . unwrap( ) , 1 ) ;
0 commit comments