mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 13:37:20 +02:00
Dates
- Added Date::startof{Day,Week,Month,Year} methods to facilitate the history, ghistory and burndown charts.
This commit is contained in:
parent
891136788f
commit
125058093f
3 changed files with 40 additions and 1 deletions
26
src/Date.cpp
26
src/Date.cpp
|
@ -460,6 +460,32 @@ const std::string Date::toString (const std::string& format /*= "m/d/Y" */) cons
|
||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Date Date::startOfDay () const
|
||||||
|
{
|
||||||
|
return Date (month (), day (), year ());
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Date Date::startOfWeek () const
|
||||||
|
{
|
||||||
|
Date sow (mT);
|
||||||
|
sow -= (dayOfWeek () * 86400);
|
||||||
|
return Date (sow.month (), sow.day (), sow.year ());
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Date Date::startOfMonth () const
|
||||||
|
{
|
||||||
|
return Date (month (), 1, year ());
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Date Date::startOfYear () const
|
||||||
|
{
|
||||||
|
return Date (1, 1, year ());
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Date::valid (const std::string& input, const std::string& format)
|
bool Date::valid (const std::string& input, const std::string& format)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,12 @@ public:
|
||||||
std::string toISO ();
|
std::string toISO ();
|
||||||
void toMDY (int&, int&, int&);
|
void toMDY (int&, int&, int&);
|
||||||
const std::string toString (const std::string& format = "m/d/Y") const;
|
const std::string toString (const std::string& format = "m/d/Y") const;
|
||||||
|
|
||||||
|
Date startOfDay () const;
|
||||||
|
Date startOfWeek () const;
|
||||||
|
Date startOfMonth () const;
|
||||||
|
Date startOfYear () const;
|
||||||
|
|
||||||
static bool valid (const std::string&, const std::string& format = "m/d/Y");
|
static bool valid (const std::string&, const std::string& format = "m/d/Y");
|
||||||
static bool valid (const int, const int, const int, const int, const int, const int);
|
static bool valid (const int, const int, const int, const int, const int, const int);
|
||||||
static bool valid (const int, const int, const int);
|
static bool valid (const int, const int, const int);
|
||||||
|
|
|
@ -34,7 +34,7 @@ Context context;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (154);
|
UnitTest t (158);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -160,6 +160,13 @@ int main (int argc, char** argv)
|
||||||
Date iso (1000000000);
|
Date iso (1000000000);
|
||||||
t.is (iso.toISO (), "20010909T014640Z", "1,000,000,000 -> 20010909T014640Z");
|
t.is (iso.toISO (), "20010909T014640Z", "1,000,000,000 -> 20010909T014640Z");
|
||||||
|
|
||||||
|
// Quantization.
|
||||||
|
Date quant (1234567890);
|
||||||
|
t.is (quant.startOfDay ().toString ("YMDHNS"), "20090213000000", "1234567890 -> 2/13/2009 18:31:30 -> 2/13/2009 0:00:00");
|
||||||
|
t.is (quant.startOfWeek ().toString ("YMDHNS"), "20090208000000", "1234567890 -> 2/13/2009 18:31:30 -> 2/8/2009 0:00:00");
|
||||||
|
t.is (quant.startOfMonth ().toString ("YMDHNS"), "20090201000000", "1234567890 -> 2/13/2009 18:31:30 -> 2/1/2009 0:00:00");
|
||||||
|
t.is (quant.startOfYear ().toString ("YMDHNS"), "20090101000000", "1234567890 -> 2/13/2009 18:31:30 -> 1/1/2009 0:00:00");
|
||||||
|
|
||||||
// Date parsing.
|
// Date parsing.
|
||||||
Date fromString1 ("1/1/2008");
|
Date fromString1 ("1/1/2008");
|
||||||
t.is (fromString1.month (), 1, "ctor (std::string) -> m");
|
t.is (fromString1.month (), 1, "ctor (std::string) -> m");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue