Looks right at a quick glance. But some unit tests will confirm it ;-) Stephen
On 22 January 2012 14:16, Taras Tielkes <taras.tiel...@gmail.com> wrote: > Hi Stephen, > > The dateOptionalTimeParser() approach almost does what I want. > However, I'd like to enforce/validate the presence of hour/minute/second. > > I've come up with the following, does it look correct to you? > ---------- > public class ExtendedISODateTimeFormat { > > private static final DateTimeFormatter FORMAT; > > static { > FORMAT = new DateTimeFormatterBuilder() > .append(ISODateTimeFormat.date()) > .append(literalTElement()) > .append(ISODateTimeFormat.hourMinuteSecond()) > .appendOptional(fractionElement()) > .append(offsetElement()) > .toFormatter() > .withZone(DateTimeZone.UTC); > } > > public static DateTimeFormatter dateTimeOptionalMillis() { > return FORMAT; > } > > private static DateTimeFormatter literalTElement() { > return new > DateTimeFormatterBuilder().appendLiteral('T').toFormatter(); > } > > private static DateTimeParser fractionElement() { > return new > DateTimeFormatterBuilder().appendLiteral('.').appendFractionOfSecond(3, > 9).toParser(); > } > > private static DateTimeFormatter offsetElement() { > return new DateTimeFormatterBuilder().appendTimeZoneOffset("Z", > true, 2, 4).toFormatter(); > } > } > ---------- > > Thanks, > -tt > > On Sat, Jan 21, 2012 at 11:00 PM, Stephen Colebourne > <scolebou...@joda.org> wrote: >> ISODateTimeFormat.dateOptionalTimeParser() would work wouldn't it? >> >> New patterns can be created using DateTimeFormatterBuilder, which >> supports optional parts. >> Stephen >> >> On 21 January 2012 18:21, Taras Tielkes <taras.tiel...@gmail.com> wrote: >>> Hi, >>> >>> If I understand correctly, xsd:dateTime permits, but does not require, >>> fractional seconds. >>> Is there a formatter/parser in Joda to work with such values? >>> >>> On ISODateTimeFormat, I see "dateTime()" and "dateTimeNoMillis()", but >>> no "dateTimeOptionalMillis()". >>> Given how widely used xsd:dateTime is, I wonder if I'm overlooking >>> something? >>> >>> Is there an easy way to compose such a pattern? I do want to enforce >>> the presence of both timezone, and full (hh/mm/ss) time, but want to >>> treat milliseconds as optional (during parsing). >>> >>> Thanks in advance, >>> -tt >>> >>> ------------------------------------------------------------------------------ >>> Try before you buy = See our experts in action! >>> The most comprehensive online learning library for Microsoft developers >>> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >>> Metro Style Apps, more. Free future releases when you subscribe now! >>> http://p.sf.net/sfu/learndevnow-dev2 >>> _______________________________________________ >>> Joda-interest mailing list >>> Joda-interest@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/joda-interest >> >> ------------------------------------------------------------------------------ >> Try before you buy = See our experts in action! >> The most comprehensive online learning library for Microsoft developers >> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >> Metro Style Apps, more. Free future releases when you subscribe now! >> http://p.sf.net/sfu/learndevnow-dev2 >> _______________________________________________ >> Joda-interest mailing list >> Joda-interest@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/joda-interest > > ------------------------------------------------------------------------------ > Try before you buy = See our experts in action! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-dev2 > _______________________________________________ > Joda-interest mailing list > Joda-interest@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/joda-interest ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ Joda-interest mailing list Joda-interest@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/joda-interest