summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/time.cc15
-rw-r--r--base/time.hh4
2 files changed, 10 insertions, 9 deletions
diff --git a/base/time.cc b/base/time.cc
index d2e8f60a5..9a484a883 100644
--- a/base/time.cc
+++ b/base/time.cc
@@ -47,10 +47,11 @@ convert(const timeval &tv)
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
}
-Time::Time()
+Time::Time(bool set_now)
{
time = new _timeval;
- ::gettimeofday(&time->tv, NULL);
+ if (set_now)
+ set();
}
Time::Time(const timeval &val)
@@ -77,15 +78,15 @@ Time::get() const
}
void
-Time::set(const timeval &tv)
+Time::set()
{
- memcpy(&time->tv, &tv, sizeof(timeval));
+ ::gettimeofday(&time->tv, NULL);
}
void
-Time::reset()
+Time::set(const timeval &tv)
{
- ::gettimeofday(&time->tv, NULL);
+ memcpy(&time->tv, &tv, sizeof(timeval));
}
double
@@ -127,4 +128,4 @@ operator-(const Time &l, const Time &r)
return tv;
}
-const Time Time::start;
+const Time Time::start(true);
diff --git a/base/time.hh b/base/time.hh
index 64da52e1d..1f8c7e747 100644
--- a/base/time.hh
+++ b/base/time.hh
@@ -42,15 +42,15 @@ class Time
mutable _timeval *time;
public:
- Time();
+ explicit Time(bool set_now = false);
Time(const timeval &val);
Time(const Time &val);
~Time();
+ void set();
const timeval &get() const;
void set(const timeval &val);
- void reset();
double operator()() const;
std::string date(std::string format = "") const;