string
- datetime()
+ datetime(time_t t1, bool utc, bool classic)
{
- time_t t1 = time(NULL);
struct tm t2;
- gmtime_r(&t1, &t2);
+ utc ? gmtime_r(&t1, &t2) : localtime_r(&t1, &t2);
char buf[64 + 1];
- if (strftime(buf, sizeof(buf), "%F %T %Z", &t2) == 0)
+ if (strftime(buf, sizeof(buf), classic ? "%F %T" : "%c", &t2) == 0)
return string("unknown");
return string(buf);
}
+ time_t
+ scan_datetime(const string& str, bool utc)
+ {
+ struct tm s;
+ memset(&s, 0, sizeof(s));
+ const char* p = strptime(str.c_str(), "%F %T", &s);
+ if (!p || *p != '\0')
+ return (time_t)(-1);
+ return utc ? timegm(&s) : timelocal(&s);
+ }
+
+
StopWatch::StopWatch()
{
gettimeofday(&start_tv, NULL);
#include <sys/types.h>
#include <glob.h>
#include <string.h>
+#include <boost/algorithm/string.hpp>
#include "snapper/Snapshot.h"
#include "snapper/AppUtil.h"
if (snapshot.pre_num != 0)
s << " pre-num:" << snapshot.pre_num;
- s << " date:\"" << snapshot.date << "\"";
+ s << " date:\"" << datetime(snapshot.date, true, true) << "\"";
if (!snapshot.description.empty())
s << " description:\"" << snapshot.description << "\"";
getChildValue(node, "num", snapshot.num);
assert(num == snapshot.num);
- getChildValue(node, "date", snapshot.date);
+ if (getChildValue(node, "date", tmp))
+ {
+ // TODO: remove someday
+ if (boost::ends_with(tmp, " GMT"))
+ tmp.erase(19);
+
+ assert(tmp.size() == 19);
+
+ snapshot.date = scan_datetime(tmp, true);
+ }
getChildValue(node, "description", snapshot.description);
Snapshot snapshot;
snapshot.type = SINGLE;
snapshot.num = 0;
- snapshot.date = "now";
+ snapshot.date = (time_t)(-1);
snapshot.description = "current";
entries.push_back(snapshot);
setChildValue(node, "num", num);
- setChildValue(node, "date", date);
+ setChildValue(node, "date", datetime(date, true, true));
if (type == SINGLE || type == PRE)
setChildValue(node, "description", description);
Snapshot snapshot;
snapshot.type = SINGLE;
snapshot.num = nextNumber();
- snapshot.date = datetime();
+ snapshot.date = time(NULL);
snapshot.description = description;
snapshot.writeInfo();
Snapshot snapshot;
snapshot.type = PRE;
snapshot.num = nextNumber();
- snapshot.date = datetime();
+ snapshot.date = time(NULL);
snapshot.description = description;
snapshot.writeInfo();
Snapshot snapshot;
snapshot.type = POST;
snapshot.num = nextNumber();
- snapshot.date = datetime();
+ snapshot.date = time(NULL);
snapshot.pre_num = pre->getNum();
snapshot.writeInfo();
row.add(toString(it->getType()));
row.add(decString(it->getNum()));
row.add(it->getType() == POST ? decString(it->getPreNum()) : "");
- row.add(it->getDate());
+ row.add(it->isCurrent() ? "" : datetime(it->getDate(), false, false));
row.add(it->getDescription());
table.add(row);
}
int
main(int argc, char** argv)
{
+ setlocale (LC_ALL, "");
+
list<string> args;
initDefaultLogger();
y2mil( "argc:" << argc );