Design Pattern Examples
Overview of object-oriented design patterns
lusplus/helpers/DateTime.h
Go to the documentation of this file.
1
5
6#pragma once
7#ifndef __DATETIME_H__
8#define __DATETIME_H__
9
10#include <time.h>
11#include <string>
12
13namespace Helpers
14{
21 {
22 private:
23 time_t timestamp;
24
25 public:
30 : timestamp(0)
31 {}
32
37 DateTime(time_t _timestamp) : timestamp(_timestamp) {}
48 DateTime& operator=(const DateTime& e) { timestamp = e.timestamp; return *this; }
49
55 std::string ToString();
56
62 static DateTime Now();
63 };
64
65} // end namespace
66
67#endif // __DATETIME_H__
Represents a timestamp composed of a date and a time encoded in a time_t value. Provides ways of gett...
DateTime & operator=(const DateTime &e)
Copy operator. Copy from another DateTime.
static DateTime Now()
Return the current date and time.
Definition: DateTime.cpp:35
DateTime(const DateTime &e)
Copy constructor. Construct from another DateTime.
DateTime(time_t _timestamp)
Constructor that takes a time_t.
DateTime()
Default constructor.
std::string ToString()
Format the DateTime as a string. The format is "standard" (in this case, preset to 02/22/2023 10:26:1...
Definition: DateTime.cpp:17
The namespace containing all the "helper" functions in the C++ code.