SystemClock.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_SYSTEM__SYSTEM_CLOCK
18 #define COM_BORA_SOFTWARE__BALAU_SYSTEM__SYSTEM_CLOCK
19 
21 #include <Balau/System/Clock.hpp>
22 
23 namespace Balau::System {
24 
30 class SystemClock : public Clock {
32 
33  public: std::chrono::system_clock::time_point now() const override {
34  return std::chrono::system_clock::now();
35  }
36 
37  public: Date::year_month_day today() const override {
38  return Date::year_month_day {
39  Date::floor<Date::days>(std::chrono::system_clock::now())
40  };
41  }
42 
43  public: std::chrono::nanoseconds nanotime() const override {
44  return std::chrono::duration_cast<std::chrono::nanoseconds>(
45  std::chrono::system_clock::now().time_since_epoch()
46  );
47  }
48 
49  public: std::chrono::milliseconds millitime() const override {
50  return std::chrono::duration_cast<std::chrono::milliseconds>(
51  std::chrono::system_clock::now().time_since_epoch()
52  );
53  }
54 
55  public: std::chrono::centiseconds centitime() const override {
56  return std::chrono::duration_cast<std::chrono::centiseconds>(
57  std::chrono::system_clock::now().time_since_epoch()
58  );
59  }
60 
61  public: std::chrono::deciseconds decitime() const override {
62  return std::chrono::duration_cast<std::chrono::deciseconds>(
63  std::chrono::system_clock::now().time_since_epoch()
64  );
65  }
66 };
67 
68 } // namespace Balau::System
69 
70 #endif // COM_BORA_SOFTWARE__BALAU_SYSTEM__SYSTEM_CLOCK
virtual std::chrono::system_clock::time_point now() const =0
Get the current time point.
The default implementation of the clock API.
Definition: SystemClock.hpp:30
Base interface of clocks.
Definition: Clock.hpp:47
Injection macros used in injectable classes.
virtual std::chrono::deciseconds decitime() const =0
Get the current time in deciseconds since the unix epoch.
virtual std::chrono::milliseconds millitime() const =0
Get the current time in milliseconds since the unix epoch.
#define BalauInject(...)
Annotate an injectable class by specifying the class name and its direct or indirect dependency field...
Definition: Injectable.hpp:26
virtual std::chrono::centiseconds centitime() const =0
Get the current time in centiseconds since the unix epoch.
virtual std::chrono::nanoseconds nanotime() const =0
Get the current time in nanoseconds since the unix epoch.
virtual Date::year_month_day today() const =0
Get the current date.
Base interface of clocks.
System utilities and wrappers.
Definition: HttpServerConfiguration.hpp:30