diff --git a/src/utility/datetimeUtils.cpp b/src/utility/datetimeUtils.cpp index cf05a932..6ea5be60 100644 --- a/src/utility/datetimeUtils.cpp +++ b/src/utility/datetimeUtils.cpp @@ -256,7 +256,7 @@ int datetimeUtils::getDayOfWeek(const int year, const int month, const int day) } -int datetimeUtils::getWeekOfYear(const int year, const int month, const int day) +int datetimeUtils::getWeekOfYear(const int year, const int month, const int day, const bool iso) { // Algorithm from http://personal.ecu.edu/mccartyr/ISOwdALG.txt @@ -322,7 +322,7 @@ int datetimeUtils::getWeekOfYear(const int year, const int month, const int day) WeekNumber -= 1; } - if (WeekNumber == 1 && month == 12) + if (!iso && (WeekNumber == 1 && month == 12)) WeekNumber = 53; return WeekNumber; diff --git a/tests/utility/datetimeUtilsTest.cpp b/tests/utility/datetimeUtilsTest.cpp index 4fd3e436..4671e75b 100644 --- a/tests/utility/datetimeUtilsTest.cpp +++ b/tests/utility/datetimeUtilsTest.cpp @@ -143,10 +143,11 @@ VMIME_TEST_SUITE_BEGIN { VASSERT_EQ("1.1", 52, datetimeUtils::getWeekOfYear(2003, 12, 27)); VASSERT_EQ("1.2", 52, datetimeUtils::getWeekOfYear(2003, 12, 28)); - VASSERT_EQ("1.3", 1, datetimeUtils::getWeekOfYear(2003, 12, 29)); - VASSERT_EQ("1.4", 1, datetimeUtils::getWeekOfYear(2004, 1, 4)); - VASSERT_EQ("1.5", 2, datetimeUtils::getWeekOfYear(2004, 1, 5)); - VASSERT_EQ("1.6", 2, datetimeUtils::getWeekOfYear(2004, 1, 11)); + VASSERT_EQ("1.3", 1, datetimeUtils::getWeekOfYear(2003, 12, 29, true)); + VASSERT_EQ("1.4", 53, datetimeUtils::getWeekOfYear(2003, 12, 29, false)); + VASSERT_EQ("1.5", 1, datetimeUtils::getWeekOfYear(2004, 1, 4)); + VASSERT_EQ("1.6", 2, datetimeUtils::getWeekOfYear(2004, 1, 5)); + VASSERT_EQ("1.7", 2, datetimeUtils::getWeekOfYear(2004, 1, 11)); VASSERT_EQ("2.1", 52, datetimeUtils::getWeekOfYear(2004, 12, 26)); VASSERT_EQ("2.2", 53, datetimeUtils::getWeekOfYear(2004, 12, 27)); diff --git a/vmime/utility/datetimeUtils.hpp b/vmime/utility/datetimeUtils.hpp index b56533cb..d5f89beb 100644 --- a/vmime/utility/datetimeUtils.hpp +++ b/vmime/utility/datetimeUtils.hpp @@ -84,9 +84,11 @@ public: * @param year year in 4-digit format * @param month month (1-12), January is 1, December is 12 (see datetime::Months enum) * @param day month day (1-31) + * @param iso if TRUE, use ISO week-numbering year (default is to use calendar year). + * For more information, read here: http://en.wikipedia.org/wiki/ISO_8601#Week_dates * @return the week number (1 is the first week of the year) */ - static int getWeekOfYear(const int year, const int month, const int day); + static int getWeekOfYear(const int year, const int month, const int day, const bool iso = false); };