Uploaded image for project: 'Kylin'
  1. Kylin
  2. KYLIN-5519

DateFormatTest shouldn't rely on user's timezone

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.0-alpha
    • 5.0-alpha
    • Tools, Build and Test
    • None

    Description

      When I run "mvn clean test", I got the following error:

       

      [INFO] Results:
      [INFO]
      [ERROR] Failures:
      [ERROR]   DateFormatTest.testStringToMillis:200 expected:<1669824000000> but was:<1669852800000>
      [ERROR]   DateFormatTest.testStringToMillisSupplement:220 expected:<1669824000000> but was:<1669852800000> 

      When look into the "DateFormatTest.testStringToMillis", it has no timezone specified when converting a Date time to epoch time. In the DateFormat.getDateFormat(), it uses the default timezone:

      public static FastDateFormat getDateFormat(String datePattern) {
          FastDateFormat r = formatMap.get(datePattern);
          if (r == null) {
              r = FastDateFormat.getInstance(datePattern, TimeZone.getDefault());
              formatMap.put(datePattern, r);
          }
          return r;
      } 

       

      The function and test case shouldn't rely on user's default timezone. Which caused it may fail on another timezone. 

      Attachments

        Activity

          People

            shaofengshi Shao Feng Shi
            shaofengshi Shao Feng Shi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: