mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 13:37:20 +02:00
Enhancement - Date::toISO
- Added ISO date format support (19980119T070000Z) to Date class, for use in export.ical. - Added unit test.
This commit is contained in:
parent
8cd8c4753b
commit
3ef6aa9f8e
3 changed files with 25 additions and 1 deletions
20
src/Date.cpp
20
src/Date.cpp
|
@ -25,6 +25,7 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
|
@ -375,6 +376,25 @@ std::string Date::toEpochString ()
|
|||
return epoch.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 19980119T070000Z = YYYYMMDDThhmmssZ
|
||||
std::string Date::toISO ()
|
||||
{
|
||||
struct tm* t = gmtime (&mT);
|
||||
|
||||
std::stringstream iso;
|
||||
iso << std::setw (4) << std::setfill ('0') << t->tm_year + 1900
|
||||
<< std::setw (2) << std::setfill ('0') << t->tm_mon + 1
|
||||
<< std::setw (2) << std::setfill ('0') << t->tm_mday
|
||||
<< "T"
|
||||
<< std::setw (2) << std::setfill ('0') << t->tm_hour
|
||||
<< std::setw (2) << std::setfill ('0') << t->tm_min
|
||||
<< std::setw (2) << std::setfill ('0') << t->tm_sec
|
||||
<< "Z";
|
||||
|
||||
return iso.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Date::toEpoch (time_t& epoch)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue