1 #ifndef LIBFILEZILLA_TIME_HEADER 2 #define LIBFILEZILLA_TIME_HEADER 12 #include "private/windows.hpp" 21 class FZ_PUBLIC_SYMBOL duration;
66 datetime(
zone z,
int year,
int month,
int day,
int hour = -1,
int minute = -1,
int second = -1,
int millisecond = -1);
93 accuracy get_accuracy()
const {
return a_; }
104 bool operator==(
datetime const& op)
const;
105 bool operator!=(
datetime const& op)
const {
return !(*
this == op); }
106 bool operator<(
datetime const& op)
const;
107 bool operator<=(
datetime const& op)
const;
108 bool operator>(
datetime const& op)
const {
return op < *
this; }
120 int compare(
datetime const& op)
const;
149 bool set(
zone z,
int year,
int month,
int day,
int hour = -1,
int minute = -1,
int second = -1,
int millisecond = -1);
160 bool set(std::string
const& str,
zone z);
161 bool set(std::wstring
const& str,
zone z);
164 bool set(FILETIME
const& ft,
accuracy a);
170 #if defined(FZ_UNIX) || defined(FZ_MAC) 185 bool imbue_time(
int hour,
int minute,
int second = -1,
int millisecond = -1);
191 std::string format(std::string
const& format,
zone z)
const;
192 std::wstring format(std::wstring
const& format,
zone z)
const;
199 static bool verify_format(std::string
const& fmt);
200 static bool verify_format(std::wstring
const& fmt);
206 time_t get_time_t()
const;
209 tm get_tm(
zone z)
const;
212 FILETIME get_filetime()
const;
217 int FZ_PRIVATE_SYMBOL compare_slow(
datetime const& op)
const;
219 bool FZ_PRIVATE_SYMBOL clamped();
221 enum invalid_t : int64_t {
222 invalid = std::numeric_limits<int64_t>::min()
245 int64_t get_days()
const {
return ms_ / 1000 / 3600 / 24; }
246 int64_t get_hours()
const {
return ms_ / 1000 / 3600; }
247 int64_t get_minutes()
const {
return ms_ / 1000 / 60; }
248 int64_t get_seconds()
const {
return ms_ / 1000; }
249 int64_t get_milliseconds()
const {
return ms_; }
252 static duration from_days(int64_t m) {
253 return duration(m * 1000 * 60 * 60 * 24);
255 static duration from_hours(int64_t m) {
256 return duration(m * 1000 * 60 * 60);
258 static duration from_minutes(int64_t m) {
261 static duration from_seconds(int64_t m) {
264 static duration from_milliseconds(int64_t m) {
278 explicit operator bool()
const {
282 bool operator<(
duration const& op)
const {
return ms_ < op.ms_; }
283 bool operator<=(
duration const& op)
const {
return ms_ <= op.ms_; }
284 bool operator>(
duration const& op)
const {
return ms_ > op.ms_; }
285 bool operator>=(
duration const& op)
const {
return ms_ >= op.ms_; }
289 explicit duration(int64_t ms) : ms_(ms) {}
338 typedef std::chrono::steady_clock clock_type;
339 static_assert(std::chrono::steady_clock::is_steady,
"Nonconforming stdlib, your steady_clock isn't steady");
347 explicit operator bool()
const {
348 return t_ != clock_type::time_point();
353 t_ += std::chrono::milliseconds(d.get_milliseconds());
359 t_ -= std::chrono::milliseconds(d.get_milliseconds());
368 clock_type::time_point t_;
384 return duration::from_milliseconds(std::chrono::duration_cast<std::chrono::milliseconds>(a.t_ - b.t_).count());
bool operator==(monotonic_clock const &a, monotonic_clock const &b)
Definition: time.hpp:388
bool earlier_than(datetime const &op) const
Equivalent to compare(op) < 0.
Definition: time.hpp:123
bool operator<(monotonic_clock const &a, monotonic_clock const &b)
Definition: time.hpp:394
int get_milliseconds() const
Get millisecond part of timestamp.
Definition: time.hpp:203
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:40
accuracy
The datetime's accuracy.
Definition: time.hpp:46
bool later_than(datetime const &op) const
Equivalent to compare(op) > 0.
Definition: time.hpp:126
A monotonic clock (aka steady clock) is independent from walltime.
Definition: time.hpp:318
bool operator>(monotonic_clock const &a, monotonic_clock const &b)
Definition: time.hpp:406
The namespace used by libfilezilla.
Definition: apply.hpp:16
zone
When importing or exporting a timestamp, zone is used to explicitly specify whether the conversion is...
Definition: time.hpp:58
The duration class represents a time interval in milliseconds.
Definition: time.hpp:236
Sets some global macros and further includes string.hpp.
bool operator<=(monotonic_clock const &a, monotonic_clock const &b)
Definition: time.hpp:400
bool operator>=(monotonic_clock const &a, monotonic_clock const &b)
Definition: time.hpp:412
static monotonic_clock now()
Gets the current point in time time.
Definition: time.hpp:343