00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__Time_H__
00010 #define __libutilxx__sella__util__Time_H__
00011
00012 #include "../../common.h"
00013
00014 #include <stdint.h>
00015 #include <sys/time.h>
00016 #include <stddef.h>
00017
00018 #include <string>
00019 #include <chrono>
00020
00021 namespace sella {
00022 namespace util {
00023 class Time;
00024 }
00025 }
00026
00027 class sella::util::Time {
00028 public:
00029 static struct timeval htontv(const struct timeval &src) throw ();
00030 static struct timeval ntohtv(const struct timeval &src) throw ();
00031 static void cleartv(struct timeval &src) throw ();
00032 static int comparetv(const struct timeval &a, const struct timeval &b) throw ();
00033 static void copytv(struct timeval &dst, const struct timeval &src) throw ();
00034 static void subtracttv(struct timeval &dst, const struct timeval &src) throw ();
00035 static void addtv(struct timeval &dst, const struct timeval &src) throw ();
00036
00037 static struct timespec htonts(const struct timespec &ts) throw ();
00038 static struct timespec ntohts(const struct timespec &ts) throw ();
00039
00040 static void clearts(struct timespec &ts) throw ();
00041 static int comparets(const struct timespec &a, const struct timespec &b) throw ();
00042 static void copyts(struct timespec &dst, const struct timespec &src) throw ();
00043 static void subtractts(struct timespec &dst, const struct timespec &src) throw ();
00044 static void addts(struct timespec &dst, const struct timespec &src) throw ();
00045
00046 static struct timespec clock_realtime(struct timezone *tz = NULL) throw ();
00047 static struct timespec clock_monotonic(struct timezone *tz = NULL) throw ();
00048 static struct timespec clock_monotonic_raw(struct timezone *tz = NULL) throw ();
00049 static struct timespec clock_process_cputime_id(struct timezone *tz = NULL) throw ();
00050 static struct timespec clock_thread_cputime_id(struct timezone *tz = NULL) throw ();
00051 static uint64_t tstousec(const struct timespec &ts) throw ();
00052 static uint64_t tstomsec(const struct timespec &ts) throw ();
00053 static uint64_t tstosec(const struct timespec &ts) throw ();
00054 static struct timespec sectots(uint64_t sec) throw ();
00055 static struct timespec msectots(uint64_t msec) throw ();
00056 static struct timespec usectots(uint64_t usec) throw ();
00057
00058 static std::string tmtostr(const struct tm &tm, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
00059 static std::string tstostr(const struct timespec &ts, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
00060 static std::string sectostr(uint64_t sec = 0, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
00061 static std::string usectostr(uint64_t usec = 0, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
00062 static std::string msectostr(uint64_t msec = 0, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
00063
00064 static struct timeval gettimeofday(struct timezone *tz = NULL) throw ();
00065 static uint64_t gettimeofday_usec(struct timezone *tz = NULL) throw ();
00066 static uint64_t gettimeofday_msec(struct timezone *tz = NULL) throw ();
00067 static uint64_t gettimeofday_sec(struct timezone *tz = NULL) throw ();
00068 static uint64_t tvtousec(const struct timeval &tv) throw ();
00069 static uint64_t tvtomsec(const struct timeval &tv) throw ();
00070 static uint64_t tvtosec(const struct timeval &tv) throw ();
00071 static struct timeval chronototv(const std::chrono::system_clock::duration &duration) throw ();
00072 static struct timeval chronototv(const std::chrono::system_clock::time_point &tp) throw ();
00073 static struct timeval sectotv(uint64_t sec) throw ();
00074 static struct timeval usectotv(uint64_t usec) throw ();
00075 static struct timeval msectotv(uint64_t msec) throw ();
00076 static struct timeval* add_usectotv(struct timeval &tv, const uint64_t usec) throw ();
00077 static struct timeval* add_msectotv(struct timeval &tv, const uint64_t msec) throw ();
00078 static struct timeval* add_sectotv(struct timeval &tv, const uint64_t sec) throw ();
00079
00080 static std::string getRFC1123Date(void) throw ();
00081 };
00082
00083 #endif
00084
00085
00086
00087