8 #ifndef BOOSTER_POSIX_TIME_H
9 #define BOOSTER_POSIX_TIME_H
11 #include <booster/config.h>
32 ptime(
long long seconds=0,
int nano=0) :
96 return ptime(v/one_e3,v%one_e3 * one_e6);
111 return ptime(v/one_e6,v%one_e6 * one_e3);
126 return ptime(v/one_e9,v%one_e9);
154 return ptime(v*3600);
168 return ptime(v*(3600*24));
176 return double(t.sec) + double(t.nsec) * 1e-9;
183 double sec = floor(d);
184 double subsec = d-sec;
185 long long seconds =
static_cast<long long>(sec);
186 int nano =
static_cast<int>(floor(subsec * 1e9));
187 if(nano < 0) nano = 0;
188 if(nano >= one_e9) nano = one_e9-1;
189 return ptime(seconds,nano);
197 return ptime(sec+other.sec,nsec+other.nsec);
204 return ptime(sec-other.sec,nsec-other.nsec);
207 bool operator==(
ptime const &other)
const
209 return sec==other.sec && nsec == other.nsec;
211 bool operator!=(ptime
const &other)
const
213 return !((*this)==other);
221 return nsec < other.nsec;
225 return other < *
this;
227 bool operator <= (ptime
const &other)
const
229 return !(*
this > other);
231 bool operator >=(ptime
const &other)
const
233 return !(*
this < other);
268 sleep(milliseconds(v));
275 sleep(nanoseconds(v));
280 static void sleep(
ptime const &v );
286 sec += nsec / one_e9;
287 nsec = nsec % one_e9;
296 static const int one_e3 = 1000;
297 static const int one_e6 = 1000000;
298 static const int one_e9 = 1000000000;
307 BOOSTER_API std::ostream &operator<<(std::ostream &,ptime
const &);
312 BOOSTER_API std::istream &
operator>>(std::istream &,ptime &);
static ptime milliseconds(long long v)
Definition: posix_time.h:94
BOOSTER_API std::tm universal_time(time_t pt)
int get_milliseconds() const
Definition: posix_time.h:56
static long long nanoseconds(ptime const &p)
Definition: posix_time.h:117
static ptime from_number(double d)
Definition: posix_time.h:181
static ptime days(long long v)
Definition: posix_time.h:166
static double to_number(ptime const &t)
Definition: posix_time.h:174
std::basic_string< CharType > normalize(std::basic_string< CharType > const &str, norm_type n=norm_default, std::locale const &loc=std::locale())
Definition: conversion.h:159
long long get_seconds() const
Definition: posix_time.h:42
static long long milliseconds(ptime const &p)
Definition: posix_time.h:87
static void millisleep(long long v)
Definition: posix_time.h:266
static long long minutes(ptime const &p)
Definition: posix_time.h:138
static ptime microseconds(long long v)
Definition: posix_time.h:109
int get_nanoseconds() const
Definition: posix_time.h:49
ptime(long long seconds=0, int nano=0)
Definition: posix_time.h:32
static ptime nanoseconds(long long v)
Definition: posix_time.h:124
ptime operator+(ptime const &other) const
Definition: posix_time.h:195
static long long days(ptime const &p)
Definition: posix_time.h:159
static long long hours(ptime const &p)
Definition: posix_time.h:145
static void nanosleep(long long v)
Definition: posix_time.h:273
static long long seconds(ptime const &p)
Definition: posix_time.h:71
BOOSTER_API std::istream & operator>>(std::istream &, ptime &)
static ptime const zero
Definition: posix_time.h:261
int get_microseconds() const
Definition: posix_time.h:63
This class represents POSIX time.
Definition: posix_time.h:26
bool operator<(string_key const &l, char const *r)
Definition: string_key.h:431
static long long microseconds(ptime const &p)
Definition: posix_time.h:102
static ptime minutes(long long v)
Definition: posix_time.h:131
ptime operator-(ptime const &other) const
Definition: posix_time.h:202
bool operator>(string_key const &l, char const *r)
Definition: string_key.h:462
BOOSTER_API std::tm local_time(time_t pt)
static ptime seconds(long long v)
Definition: posix_time.h:78
static ptime hours(long long v)
Definition: posix_time.h:152