mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ISO8601d: Added ::weekOfYear
This commit is contained in:
parent
af81b24d92
commit
66dc016ce6
2 changed files with 22 additions and 0 deletions
|
@ -933,6 +933,27 @@ int ISO8601d::year () const
|
||||||
return t->tm_year + 1900;
|
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 ()
|
void ISO8601p::clear ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
int week () const;
|
int week () const;
|
||||||
int day () const;
|
int day () const;
|
||||||
int year () const;
|
int year () const;
|
||||||
|
int weekOfYear (int) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear ();
|
void clear ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue