]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/monotime.h
Merge pull request #4330 from donaldsharp/robo_covo
[mirror_frr.git] / lib / monotime.h
index 7bd338649830901ebb713592174f5ef9adf5d06e..6aac966ea14a2aee8e6872ca68893a58f953f620 100644 (file)
 #include <time.h>
 #include <sys/time.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifndef TIMESPEC_TO_TIMEVAL
 /* should be in sys/time.h on BSD & Linux libcs */
 #define TIMESPEC_TO_TIMEVAL(tv, ts)                                            \
@@ -49,6 +53,10 @@ static inline time_t monotime(struct timeval *tvo)
        return ts.tv_sec;
 }
 
+#define ONE_DAY_SECOND 60*60*24
+#define ONE_WEEK_SECOND ONE_DAY_SECOND*7
+#define ONE_YEAR_SECOND ONE_DAY_SECOND*365
+
 /* the following two return microseconds, not time_t!
  *
  * also, they're negative forms of each other, but having both makes the
@@ -76,4 +84,19 @@ static inline int64_t monotime_until(const struct timeval *ref,
        return (int64_t)tv.tv_sec * 1000000LL + tv.tv_usec;
 }
 
+static inline char *time_to_string(time_t ts)
+{
+       struct timeval tv;
+       time_t tbuf;
+
+       monotime(&tv);
+       tbuf = time(NULL) - (tv.tv_sec - ts);
+
+       return ctime(&tbuf);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _FRR_MONOTIME_H */