public void ParsePartial_ValidInMiddle() { var value = new ValueCursor("x17:30y"); value.MoveNext(); value.MoveNext(); // Start already looking at the value to parse Assert.AreEqual('1', value.Current); var result = SimpleOffsetPattern.ParsePartial(value); Assert.AreEqual(Offset.FromHoursAndMinutes(17, 30), result.Value); // Finish just after the value Assert.AreEqual('y', value.Current); }
public ParseResult <Offset> ParsePartial(ValueCursor cursor) { if (cursor.Current == 'Z') { cursor.MoveNext(); return(ParseResult <Offset> .ForValue(Offset.Zero)); } return(fullPattern.ParsePartial(cursor)); }
/// <summary> /// Adds parsing/formatting of an embedded pattern, e.g. an offset within a ZonedDateTime/OffsetDateTime. /// </summary> internal void AddEmbeddedPattern <TEmbedded>( IPartialPattern <TEmbedded> embeddedPattern, Action <TBucket, TEmbedded> parseAction, Func <TResult, TEmbedded> valueExtractor) { AddParseAction((value, bucket) => { var result = embeddedPattern.ParsePartial(value); if (!result.Success) { return(result.ConvertError <TResult>()); } parseAction(bucket, result.Value); return(null); }); AddFormatAction((value, sb) => embeddedPattern.AppendFormat(valueExtractor(value), sb)); }