Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-14683

TFS Plugin parses pt_BR dates incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Major Major
    • tfs-plugin
    • None
    • Windows 7 x86

      The TFS SCM plugin cannot parse the date output by the TFS detailed history command if the system locale is set to Brazilian Portuguese.

      Therefore, SCM polling always fails to detect any changes, for the month and day of the last change get swapped.

      For instance:

      Started on Aug 3, 2012 4:30:38 PM
      [foundation-v2.06b] $ C:\apps\TEE-CLC-10.1.0\tf.cmd history $/<redacted> -noprompt -version:D2012-08-02T19:17:11Z~D2012-08-03T19:30:39Z -recursive -format:detailed -server:<redacted> ********
      Changeset: 107235
      User: <redacted>
      Date: 03/08/2012 10:13:46

      This date is August 3rd, 2012, but the TFS plugins interprets it as March 8th because it attempts to parse the date string with Java's deprecated Date.parse method:

      hudson.plugins.tfs.util.DateUtil:

      @SuppressWarnings("deprecation")
      public static Date parseDate(String dateString, Locale locale, TimeZone timezone) throws ParseException {
      Date date = null;
      dateString = dateString.replaceAll("(p|P)\\.(m|M)
      .", "PM").replaceAll("(a|A)\\.(m|M)
      .", "AM");
      try

      { // Use the deprecated Date.parse method as this is very good at detecting // dates commonly output by the US and UK standard locales of dotnet that // are output by the Microsoft command line client. date = new Date(Date.parse(dateString)); }

      catch (IllegalArgumentException e)

      { // ignore - parse failed. }

      if (date == null)

      { // The old fashioned way did not work. Let's try it using a more // complex alternative. DateFormat[] formats = createDateFormatsForLocaleAndTimeZone(locale, timezone); return parseWithFormats(dateString, formats); }

      return date;
      }

      I copied this class to a standalone project on Eclipse and printed the parsed date. The result with the original code for 03/08/2012 10:13:46 was:

      Thu Mar 08 10:13:46 BRT 2012

      After I changed the class to remove the call to the deprecated method, the date was parsed correctly:

      Fri Aug 03 10:13:46 BRT 2012

            redsolo redsolo
            gabspeck Gabriel Speckhahn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: