File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,20 +7,9 @@ struct TimestampConverter;
77
88impl ElementMapper for TimestampConverter {
99 fn map ( & self , element : Element ) -> Result < Element > {
10- Ok ( match element. ion_type ( ) {
11- IonType :: String => {
12- let s = element. as_string ( ) . unwrap ( ) ;
13- if is_timestamp_like ( s) {
14- if let Ok ( timestamp_element) = Element :: read_one ( s. as_bytes ( ) ) {
15- if timestamp_element. ion_type ( ) == IonType :: Timestamp {
16- return Ok ( timestamp_element) ;
17- }
18- }
19- }
20- element
21- }
22- _ => element,
23- } )
10+ Ok ( element. as_text ( )
11+ . and_then ( as_timestamp)
12+ . unwrap_or ( element) )
2413 }
2514}
2615
@@ -65,3 +54,11 @@ fn is_timestamp_like(s: &str) -> bool {
6554 _ => len > 10 && bytes[ 10 ] == b'T' ,
6655 }
6756}
57+
58+ fn as_timestamp ( s : & str ) -> Option < Element > {
59+ if !is_timestamp_like ( s) {
60+ return None ;
61+ }
62+ Element :: read_one ( s. as_bytes ( ) ) . ok ( )
63+ . filter ( |e| e. ion_type ( ) == IonType :: Timestamp )
64+ }
You can’t perform that action at this time.
0 commit comments