Sara

Context :

With my team I am developing a feature that can calculate weekly, monthly, yearly reports. After pulling the develop-branch on my computer, multiple tests went haywire. Tests for weekly reports had been added and those failed on my computer because of week numbers. After checking with all colleagues (Mac-users) and the Jenkins jobs that run all tests after commit (running on Unix) it seemed my Windows was the only one with failing tests.

So lets look at one of the failing tests :

        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-52");
        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-53");
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(1.0);
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-1");
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(6.0);
        assertThat(row19.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-2");
        assertThat(row19.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);

Result :

        org.junit.ComparisonFailure: 
        Expected :"2017-53"
        Actual   :"2018-1"

What was happening :

Different countries have different time/date standards :

  • The calendar that is used.
  • The order in which the year, month and day are represented.
  • How weeks are identified (see seven-day week)
  • Whether written months are identified by name, by number (1–12), or by Roman numeral (I-XII).
  • Whether the 24-hour clock, 12-hour clock or 6-hour clock is used.
  • The punctuation used to separate elements in all-numeric dates and times.
  • Which days are considered the weekend.

My machine was using the settings from Great Britain, and my colleagues were using different settings. Meaning our week starts on different days(Sunday / Monday) and our year had a different amount of weeks due to this. My year only had 52 weeks. Their years consisted of an additional incomplete week with the last/first days of the year.

Iso standards : Wikipedia can give you a very dry explanation of how it all works, but just trying a few 31/12/YYYY on an ISO conform time converter can show you how it works.

If the week contains 4 or more days in year X, the week is in year X.Image description

Image description

How we fixed it :

Since we work for an international company we will have to implement a standard, and communicate this to all that use our API. We chose to use the settings from Great Britain, meaning that 2017 only has 52 weeks. Weeks should have 7 days, and should start on a Monday. Fully in line with the ISO standards.

To set the locale settings on the local servers and maven we used this :

         -Duser.language=en -Duser.country=GB

The tests were adapted to test if ISO standards and GB locale is used :

        assertThat(row2.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-38");
        assertThat(row2.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-52");
        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-1");
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-2");
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);

Tip of the day :

Because you are the only one having the bug, it's not a given that the issue is on your machine.

Because you are a minority, it does not mean you are wrong.