mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-02 05:30:23 +02:00
- Partial fix to bug - snapshot.
This commit is contained in:
parent
7ec523d5ea
commit
cede865693
2 changed files with 22 additions and 57 deletions
75
src/Date.cpp
75
src/Date.cpp
|
@ -57,7 +57,7 @@ Date::Date (const int m, const int d, const int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Date::Date (const std::string& mdy, const std::string format /* = "m/d/Y" */)
|
Date::Date (const std::string& mdy, const std::string& format /* = "m/d/Y" */)
|
||||||
{
|
{
|
||||||
int month = 0;
|
int month = 0;
|
||||||
int day = 0;
|
int day = 0;
|
||||||
|
@ -221,65 +221,30 @@ void Date::toMDY (int& m, int& d, int& y)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Date::toString (const std::string& format /*= "m/d/Y"*/)
|
const std::string Date::toString (const std::string& format /*= "m/d/Y" */) const
|
||||||
{
|
{
|
||||||
std::string formatted;
|
std::cout << "# Date::toString (" << format << ")" << std::endl;
|
||||||
|
|
||||||
|
char buffer[12];
|
||||||
|
std::string formatted ("");
|
||||||
|
formatted.resize (24);
|
||||||
for (unsigned int i = 0; i < format.length (); ++i)
|
for (unsigned int i = 0; i < format.length (); ++i)
|
||||||
{
|
{
|
||||||
switch (format[i])
|
char c = format[i];
|
||||||
|
std::cout << "# before " << c << " formatted=" << formatted << " format=" << format << std::endl;
|
||||||
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'm':
|
case 'm': sprintf (buffer, "%d", this->month ()); break;
|
||||||
{
|
case 'M': sprintf (buffer, "%02d", this->month ()); break;
|
||||||
char m[3];
|
case 'd': sprintf (buffer, "%d", this->day ()); break;
|
||||||
sprintf (m, "%d", this->month ());
|
case 'D': sprintf (buffer, "%02d", this->day ()); break;
|
||||||
formatted += m;
|
case 'y': sprintf (buffer, "%02d", this->year () % 100); break;
|
||||||
}
|
case 'Y': sprintf (buffer, "%d", this->year ()); break;
|
||||||
break;
|
default: sprintf (buffer, "%c", c); break;
|
||||||
|
|
||||||
case 'M':
|
|
||||||
{
|
|
||||||
char m[3];
|
|
||||||
sprintf (m, "%02d", this->month ());
|
|
||||||
formatted += m;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'd':
|
|
||||||
{
|
|
||||||
char d[3];
|
|
||||||
sprintf (d, "%d", this->day ());
|
|
||||||
formatted += d;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'D':
|
|
||||||
{
|
|
||||||
char d[3];
|
|
||||||
sprintf (d, "%02d", this->day ());
|
|
||||||
formatted += d;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
{
|
|
||||||
char y[3];
|
|
||||||
sprintf (y, "%02d", this->year () % 100);
|
|
||||||
formatted += y;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'Y':
|
|
||||||
{
|
|
||||||
char y[5];
|
|
||||||
sprintf (y, "%d", this->year ());
|
|
||||||
formatted += y;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
formatted += format[i];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formatted += buffer;
|
||||||
|
std::cout << "# after " << c << " formatted=" << formatted << " format=" << format << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatted;
|
return formatted;
|
||||||
|
|
|
@ -37,14 +37,14 @@ public:
|
||||||
Date ();
|
Date ();
|
||||||
Date (time_t);
|
Date (time_t);
|
||||||
Date (const int, const int, const int);
|
Date (const int, const int, const int);
|
||||||
Date (const std::string&, const std::string format = "m/d/Y");
|
Date (const std::string&, const std::string& format = "m/d/Y");
|
||||||
Date (const Date&);
|
Date (const Date&);
|
||||||
virtual ~Date ();
|
virtual ~Date ();
|
||||||
|
|
||||||
void toEpoch (time_t&);
|
void toEpoch (time_t&);
|
||||||
time_t toEpoch ();
|
time_t toEpoch ();
|
||||||
void toMDY (int&, int&, int&);
|
void toMDY (int&, int&, int&);
|
||||||
std::string toString (const std::string& format = "m/d/Y");
|
const std::string toString (const std::string& format = "m/d/Y") const;
|
||||||
static bool valid (const int, const int, const int);
|
static bool valid (const int, const int, const int);
|
||||||
|
|
||||||
static bool leapYear (int);
|
static bool leapYear (int);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue