libutil++  1.9.3
 All Classes Functions Variables
Time.h
1 /*
2 ** libutil++
3 ** $Id: Time.h 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__util__Time_H__
10 #define __libutilxx__sella__util__Time_H__
11 
12 #include "../../common.h"
13 
14 #include <stdint.h>
15 #include <sys/time.h>
16 #include <stddef.h>
17 
18 #include <string>
19 #include <chrono>
20 
21 namespace sella {
22  namespace util {
23  class Time;
24  }
25 }
26 
28  public:
29  static struct timeval htontv(const struct timeval &src) throw ();
30  static struct timeval ntohtv(const struct timeval &src) throw ();
31  static void cleartv(struct timeval &src) throw ();
32  static int comparetv(const struct timeval &a, const struct timeval &b) throw ();
33  static struct timeval& copytv(struct timeval &dst, const struct timeval &src) throw ();
34  static struct timeval& subtracttv(struct timeval &dst, const struct timeval &src) throw ();
35  static struct timeval& addtv(struct timeval &dst, const struct timeval &src) throw ();
36 
37  static struct timespec htonts(const struct timespec &ts) throw (); /* Host to Network */
38  static struct timespec ntohts(const struct timespec &ts) throw (); /* Network to Host */
39 
40  static void clearts(struct timespec &ts) throw ();
41  static int comparets(const struct timespec &a, const struct timespec &b) throw ();
42  static struct timespec& copyts(struct timespec &dst, const struct timespec &src) throw ();
43  static struct timespec& subtractts(struct timespec &dst, const struct timespec &src) throw ();
44  static struct timespec& addts(struct timespec &dst, const struct timespec &src) throw ();
45 
46  static struct timespec clock_realtime() throw (); /* Affected by NTP and clock adjustments. */
47  static struct timespec clock_realtime_coarse() throw (); /* Faster but less percise. */
48  static struct timespec clock_monotonic() throw (); /* Not affected by NTP or clock adjustments. */
49  static struct timespec clock_monotonic_coarse() throw (); /* Faster but less percise. */
50  static struct timespec clock_monotonic_raw() throw ();
51  static struct timespec clock_boottime() throw ();
52  static struct timespec clock_process_cputime_id() throw ();
53  static struct timespec clock_thread_cputime_id() throw ();
54  static uint64_t tstousec(const struct timespec &ts) throw ();
55  static uint64_t tstomsec(const struct timespec &ts) throw ();
56  static uint64_t tstosec(const struct timespec &ts) throw ();
57  static struct timespec sectots(uint64_t sec) throw ();
58  static struct timespec msectots(uint64_t msec) throw ();
59  static struct timespec usectots(uint64_t usec) throw ();
60 
61  static std::string tmtostr(const struct tm &tm, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
62  static std::string tstostr(const struct timespec &ts, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
63  static std::string sectostr(uint64_t sec = 0, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
64  static std::string usectostr(uint64_t usec = 0, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
65  static std::string msectostr(uint64_t msec = 0, const char* format = "%a %Y-%m-%d %H:%M:%S %Z") throw ();
66 
67  static struct timeval gettimeofday(struct timezone *tz = NULL) throw ();
68  static uint64_t gettimeofday_usec(struct timezone *tz = NULL) throw ();
69  static uint64_t gettimeofday_msec(struct timezone *tz = NULL) throw ();
70  static uint64_t gettimeofday_sec(struct timezone *tz = NULL) throw ();
71  static uint64_t tvtousec(const struct timeval &tv) throw ();
72  static uint64_t tvtomsec(const struct timeval &tv) throw ();
73  static uint64_t tvtosec(const struct timeval &tv) throw ();
74  static struct timeval chronototv(const std::chrono::system_clock::duration &duration) throw ();
75  static struct timeval chronototv(const std::chrono::system_clock::time_point &tp) throw ();
76  static struct timeval sectotv(uint64_t sec) throw ();
77  static struct timeval usectotv(uint64_t usec) throw ();
78  static struct timeval msectotv(uint64_t msec) throw ();
79  static struct timeval* add_usectotv(struct timeval &tv, const uint64_t usec) throw ();
80  static struct timeval* add_msectotv(struct timeval &tv, const uint64_t msec) throw ();
81  static struct timeval* add_sectotv(struct timeval &tv, const uint64_t sec) throw ();
82 
83  static std::string getRFC1123Date(void) throw ();
84 };
85 
86 #endif
87 
88 /*
89 ** vim: noet ts=3 sw=3
90 */