From 66dc016ce6658d51443b094fbff60bbf3370dddb Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Sep 2015 14:22:37 -0400 Subject: [PATCH] ISO8601d: Added ::weekOfYear --- src/ISO8601.cpp | 21 +++++++++++++++++++++ src/ISO8601.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index b1ca9eedf..d9ef406f3 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -933,6 +933,27 @@ int ISO8601d::year () const return t->tm_year + 1900; } +//////////////////////////////////////////////////////////////////////////////// +int ISO8601d::weekOfYear (int weekStart) const +{ + struct tm* t = localtime (&_date); + char weekStr[3]; + + if (weekStart == 0) + strftime(weekStr, sizeof(weekStr), "%U", t); + else if (weekStart == 1) + strftime(weekStr, sizeof(weekStr), "%V", t); + else + throw std::string (STRING_DATE_BAD_WEEKSTART); + + int weekNumber = atoi (weekStr); + + if (weekStart == 0) + weekNumber += 1; + + return weekNumber; +} + //////////////////////////////////////////////////////////////////////////////// void ISO8601p::clear () { diff --git a/src/ISO8601.h b/src/ISO8601.h index 3563bd5b8..db35dff1d 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -57,6 +57,7 @@ public: int week () const; int day () const; int year () const; + int weekOfYear (int) const; private: void clear ();