ISO8601d: Added ::weekOfYear
This commit is contained in:
@@ -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 ()
|
||||
{
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
int week () const;
|
||||
int day () const;
|
||||
int year () const;
|
||||
int weekOfYear (int) const;
|
||||
|
||||
private:
|
||||
void clear ();
|
||||
|
||||
Reference in New Issue
Block a user