more Spamhaus checking and EHLO id lookup
[ghsmtp.git] / Now.hpp
blobc93921172feb5cbbebd45baffdfd727a5c9f7e53
1 #ifndef NOW_DOT_HPP
2 #define NOW_DOT_HPP
4 #include <sys/time.h>
6 #include <glog/logging.h>
8 class Now {
9 public:
10 Now();
12 auto sec() const { return tv_.tv_sec; }
13 auto usec() const { return tv_.tv_usec; }
14 const char* c_str() const { return c_str_; }
16 private:
17 timeval tv_;
18 char c_str_[32]; // RFC 5322 date-time section 3.3.
20 friend std::ostream& operator<<(std::ostream& s, Now const& now)
22 return s << now.c_str_;
26 inline Now::Now()
28 PCHECK(gettimeofday(&tv_, nullptr) == 0);
29 tm* ptm = CHECK_NOTNULL(localtime(&tv_.tv_sec));
30 CHECK_EQ(strftime(c_str_, sizeof c_str_, "%a, %d %b %Y %H:%M:%S %z", ptm),
31 sizeof(c_str_) - 1);
34 #endif // NOW_DOT_HPP