-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.h
36 lines (30 loc) · 810 Bytes
/
Action.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include <string>
#include "lib/fmt-4.0.0/fmt/time.h"
using std::string;
class Action {
private:
const std::time_t _datetime;
const string _content;
virtual const string do_toString() const {
return _content;
}
protected:
// present since our derived classes use base constuctor of no args
Action():
_datetime(time(nullptr)) {}
Action(const string& content):
_datetime(time(nullptr)), _content(content) {}
public:
virtual ~Action() {};
// It seems better to return string, not string&
const string toString() const {
return do_toString();
}
const std::time_t& datetime() const {
return _datetime;
}
const string datetimeString() const {
return fmt::format("{:%Y-%m-%d %H:%M:%S}", *localtime(&_datetime));
}
};