mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-04 01:27:20 +02:00
Duration
- Migrated methods and unit tests from OldDuration to Duration.
This commit is contained in:
parent
f77074785b
commit
965284875c
3 changed files with 79 additions and 2 deletions
|
@ -25,10 +25,12 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <Nibbler.h>
|
||||
#include <Lexer.h>
|
||||
#include <Duration.h>
|
||||
#include <text.h>
|
||||
|
||||
#define DAY 86400
|
||||
#define HOUR 3600
|
||||
|
@ -107,11 +109,50 @@ Duration::Duration ()
|
|||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Duration::Duration (const std::string& input)
|
||||
: _secs (0)
|
||||
{
|
||||
if (digitsOnly (input))
|
||||
{
|
||||
time_t value = (time_t) strtol (input.c_str (), NULL, 10);
|
||||
if (value == 0 || value > 60)
|
||||
{
|
||||
_secs = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::string::size_type idx = 0;
|
||||
parse (input, idx);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Duration::~Duration ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Duration::operator< (const Duration& other)
|
||||
{
|
||||
return _secs < other._secs;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Duration::operator> (const Duration& other)
|
||||
{
|
||||
return _secs > other._secs;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Duration& Duration::operator= (const Duration& other)
|
||||
{
|
||||
if (this != &other)
|
||||
_secs = other._secs;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Duration::operator time_t () const
|
||||
{
|
||||
|
|
|
@ -34,9 +34,12 @@ class Duration
|
|||
{
|
||||
public:
|
||||
Duration (); // Default constructor
|
||||
Duration (const std::string&); // Parse
|
||||
~Duration (); // Destructor
|
||||
Duration (const Duration&); // Unimplemented
|
||||
Duration& operator= (const Duration&); // Unimplemented
|
||||
bool operator< (const Duration&);
|
||||
bool operator> (const Duration&);
|
||||
Duration& operator= (const Duration&);
|
||||
operator time_t () const;
|
||||
bool parse (const std::string&, std::string::size_type&);
|
||||
void clear ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue