I am trying to compare two Joda dates for equality in my unit tests. Although my date string is the timezone slice I can definitely make my expected time zone with Any ideas about fixing it? Example Code Just got the answer itself. There is an option for Expected is built with
new date time (...) while
has been parsed from that string to
dateTimeFormatter is parsed with.
+02: 00 , the date parsed is the time zone
Europe / Berlin . This semant is correct (at least during DST), although two dates are not
identical .
DateTimeZone. ForID ("Europe / Berlin") , but it will not be completely accurate IMHO
+01: 00 during the winter in Europe / Berlin and < Code> +02: 00 Input is offset during the summer, the input string clearly states
+02: 00 , so if the input unit is in winter, my unit test will fail.
DateTime Formatter = ISODateTimeFormat.dateTime (); Date Time Expected = New Date Time (2013, 6, 22, 11, 7, 22, 123, DateTime Offset (2)); String input = "2013-06-22T11: 07: 22.123 + 02: 00"; Date time pars = format Parsed time; System.out.println ("Expected:" + Expected + "(" + Expected.Gronronology () + ")"); System.out.println ("Parsed:" + Parsed + "(" + Parsed.GatRrnology (+) + ");); System.out.println ("Similar:" + Expected.Accles (Parsed)); Expected output
]: 00]) Parsed: 2013-06-22T11: 07: 22.123 + 02: 00 (isogronology [Europe / Berlin]) Equal: Incorrect
DateTimeFormatter which prevents it from resolving time zone offset:
ISODateTimeFormat.dateTime (). WithOffsetParsed ()
No comments:
Post a Comment