When dealing with week numbering issues across different regions or cultures, standardization challenges often arise. For instance, Christian traditions typically consider Sunday as the first day of the week. Programming languages also have their own conventions—some start counting weeks from week 0, while others start from week 1. For data analysts, inconsistencies in standards can lead to significant ambiguities.
In the use of Apache DolphinScheduler, issues related to date handling often become prominent during the transition between years. To avoid ambiguities caused by date formats, the author recommends strictly adhering to the ISO 8601 standard.
Starting with Java 8, Java's date formatting supports the ISO 8601 standard. Uppercase Y
represents the week-based year, while lowercase y
represents the calendar year. Many developers overlook this case sensitivity during development, leading to pitfalls when handling dates at the end or beginning of each year.
Reference: Java SE 11 DateTimeFormatter Documentation
ISO 8601 Rules for Week and Week-Based Year Calculation
- A year has either 52 or 53 weeks.
- A complete week runs from Monday to Sunday.
- Monday is the first day of the week, and Sunday is the seventh.
- The first week of the year is the week containing the first Thursday of the year. For example, January 5, 2017, was the first Thursday of that year, so the week from 2017-01-02 to 2017-01-08 was the first week of 2017.
- The last week of the year is the week containing the last Thursday of the year. For example, December 29, 2016, was the last Thursday of that year, so the week from 2016-12-26 to 2017-01-01 was the last week of 2016.
- The "week-based year" is the year to which the current week belongs. For instance:
- January 1, 2017, belongs to the week-based year 2016.
- January 1, 2, and 3, 2016, belong to the week-based year 2015.
- December 30 and 31, 2024, belong to the week-based year 2025.
As a reminder, always pay attention to the case sensitivity of Y
and y
in date formatting and follow the ISO 8601 rules to avoid unnecessary issues.
Top comments (0)