@@ -12,7 +12,7 @@ use crate::{
1212 DifferenceOperation , DifferenceSettings , DisplayOffset , ResolvedRoundingOptions ,
1313 RoundingOptions , ToStringRoundingOptions , Unit , UnitGroup ,
1414 } ,
15- parsers:: { parse_instant , IxdtfStringBuilder } ,
15+ parsers:: { IxdtfStringBuilder , TemporalParser } ,
1616 provider:: TimeZoneProvider ,
1717 rounding:: { IncrementRounder , Round } ,
1818 unix_time:: EpochNanoseconds ,
@@ -278,10 +278,12 @@ impl Instant {
278278
279279 // Converts a UTF-8 encoded string into a `Instant`.
280280 pub fn from_utf8 ( s : & [ u8 ] ) -> TemporalResult < Self > {
281- let ixdtf_record = parse_instant ( s) ?;
281+ let parser = TemporalParser :: new ( ) ;
282+ let parsed = parser. parse_instant ( core:: str:: from_utf8 ( s)
283+ . map_err ( |_| TemporalError :: syntax ( ) . with_message ( "Invalid UTF-8 in instant string" ) ) ?) ?;
282284
283- // Find the offset
284- let ns_offset = match ixdtf_record . offset {
285+ // Find the offset
286+ let ns_offset = match parsed . offset {
285287 UtcOffsetRecordOrZ :: Offset ( offset) => {
286288 let ns = offset
287289 . fraction ( )
@@ -296,21 +298,19 @@ impl Instant {
296298 UtcOffsetRecordOrZ :: Z => 0 ,
297299 } ;
298300
299- let time_nanoseconds = ixdtf_record
300- . time
301- . fraction
302- . and_then ( |x| x. to_nanoseconds ( ) )
303- . unwrap_or ( 0 ) ;
301+ let time_nanoseconds = parsed. iso . time . millisecond as u32 * 1_000_000
302+ + parsed. iso . time . microsecond as u32 * 1_000
303+ + parsed. iso . time . nanosecond as u32 ;
304304 let ( millisecond, rem) = time_nanoseconds. div_rem_euclid ( & 1_000_000 ) ;
305305 let ( microsecond, nanosecond) = rem. div_rem_euclid ( & 1_000 ) ;
306306
307307 let balanced = IsoDateTime :: balance (
308- ixdtf_record . date . year ,
309- ixdtf_record . date . month . into ( ) ,
310- ixdtf_record . date . day . into ( ) ,
311- ixdtf_record . time . hour . into ( ) ,
312- ixdtf_record . time . minute . into ( ) ,
313- ixdtf_record . time . second . clamp ( 0 , 59 ) . into ( ) ,
308+ parsed . iso . date . year ,
309+ parsed . iso . date . month . into ( ) ,
310+ parsed . iso . date . day . into ( ) ,
311+ parsed . iso . time . hour . into ( ) ,
312+ parsed . iso . time . minute . into ( ) ,
313+ parsed . iso . time . second . clamp ( 0 , 59 ) . into ( ) ,
314314 millisecond. into ( ) ,
315315 microsecond. into ( ) ,
316316 i128:: from ( nanosecond) - i128:: from ( ns_offset) ,
0 commit comments