private static void HandleZone(PatternCursor pattern, SteppedPatternBuilder <ZonedDateTime, ZonedDateTimeParseBucket> builder) { builder.AddField(PatternFields.Zone, pattern.Current); builder.AddParseAction(ParseZone); builder.AddFormatAction((value, sb) => sb.Append(value.Zone.Id)); }
private static void HandleZoneAbbreviation(PatternCursor pattern, SteppedPatternBuilder <ZonedDateTime, ZonedDateTimeParseBucket> builder) { builder.AddField(PatternFields.ZoneAbbreviation, pattern.Current); builder.SetFormatOnly(); builder.AddFormatAction((value, sb) => sb.Append(value.GetZoneInterval().Name)); }
public void FormatOnly_ParsingFails() { var builder = new SteppedPatternBuilder <LocalDate, SampleBucket>( NodaFormatInfo.InvariantInfo, () => new SampleBucket()); builder.AddFormatAction((date, sb) => sb.Append("Formatted")); builder.SetFormatOnly(); var pattern = builder.Build(LocalDate.MinIsoValue); var value = new ValueCursor("xyz"); var result = pattern.ParsePartial(value); Assert.AreEqual(ParseResult <LocalDate> .FormatOnlyPattern, result); result = pattern.Parse("xyz"); Assert.AreEqual(ParseResult <LocalDate> .FormatOnlyPattern, result); }
private static void HandleOffset(PatternCursor pattern, SteppedPatternBuilder <OffsetDateTime, OffsetDateTimeParseBucket> builder) { builder.AddField(PatternFields.EmbeddedOffset, pattern.Current); string embeddedPattern = pattern.GetEmbeddedPattern('<', '>'); var offsetPattern = OffsetPattern.Create(embeddedPattern, builder.FormatInfo).UnderlyingPattern; builder.AddParseAction((value, bucket) => { var result = offsetPattern.ParsePartial(value); if (!result.Success) { return(result.ConvertError <OffsetDateTime>()); } bucket.Offset = result.Value; return(null); }); builder.AddFormatAction((value, sb) => offsetPattern.AppendFormat(value.Offset, sb)); }