GNUnet 0.28.0-dev.5
 
Loading...
Searching...
No Matches
time.c File Reference

functions for handling time and time arithmetic More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for time.c:

Go to the source code of this file.

Macros

#define __STDC_NO_ATOMICS__   1
 
#define ATOMIC
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "util-time", __VA_ARGS__)
 

Functions

void GNUNET_TIME_set_offset (long long offset)
 Set the timestamp offset for this instance.
 
long long GNUNET_TIME_get_offset ()
 Get the timestamp offset for this instance.
 
bool GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1, struct GNUNET_TIME_Absolute a2, struct GNUNET_TIME_Relative t)
 Test if a1 and a2 are equal within a margin of error of t.
 
struct GNUNET_TIME_Timestamp GNUNET_TIME_absolute_to_timestamp (struct GNUNET_TIME_Absolute at)
 Round an absolute time to a timestamp.
 
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton (struct GNUNET_TIME_Timestamp t)
 Convert timestamp to network byte order.
 
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh (struct GNUNET_TIME_TimestampNBO tn)
 Convert timestamp from network byte order.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get ()
 Get the current time.
 
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_get ()
 Get timestamp representing the current time.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_ ()
 Return relative time of 0ms.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_ ()
 Return absolute time of 0ms.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_ ()
 Return relative time of 1 microsecond.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_ ()
 Return relative time of 1ms.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_ ()
 Return relative time of 1s.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_ ()
 Return relative time of 1 minute.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_ ()
 Return relative time of 1 hour.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_ ()
 Return "forever".
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_ ()
 Return "forever".
 
const char * GNUNET_TIME_timestamp2s (struct GNUNET_TIME_Timestamp ts)
 Convert ts to human-readable timestamp.
 
const char * GNUNET_TIME_absolute2s (struct GNUNET_TIME_Absolute t)
 Like asctime, except for GNUnet time.
 
const char * GNUNET_TIME_relative2s (struct GNUNET_TIME_Relative delta, bool do_round)
 Give relative time in human-readable fancy format.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
 Convert relative time to an absolute time in the future.
 
struct GNUNET_TIME_Timestamp GNUNET_TIME_relative_to_timestamp (struct GNUNET_TIME_Relative rel)
 Convert relative time to a timestamp in the future.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
 Return the minimum of two relative time values.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
 Return the maximum of two relative time values.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
 Return the minimum of two absolute time values.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
 Return the maximum of two absolute time values.
 
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_max (struct GNUNET_TIME_Timestamp t1, struct GNUNET_TIME_Timestamp t2)
 Return the maximum of two timestamps.
 
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_min (struct GNUNET_TIME_Timestamp t1, struct GNUNET_TIME_Timestamp t2)
 Return the minimum of two timestamps.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_round_down (struct GNUNET_TIME_Absolute at, struct GNUNET_TIME_Relative rt)
 Round down absolute time at to multiple of rt.
 
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future)
 Given a timestamp in the future, how much time remains until then?
 
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
 Compute the time difference between the given start and end times.
 
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence)
 Get the duration of an operation as the difference of the current time and the given start time "hence".
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
 Add a given relative duration to the given start time.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
 Subtract a given relative duration from the given start time.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Multiply relative time by a given factor.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor)
 Multiply relative time by a given factor.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Saturating multiply relative time by a given factor.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Divide relative time by a given factor.
 
struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished, uint64_t total)
 Calculate the estimate time of arrival/completion for an operation.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
 Add relative times together.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
 Subtract relative timestamp from the other.
 
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a)
 Convert relative time to network byte order.
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a)
 Convert relative time from network byte order.
 
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a)
 Convert absolute time to network byte order.
 
bool GNUNET_TIME_absolute_is_never (struct GNUNET_TIME_Absolute abs)
 Test if abs is never.
 
bool GNUNET_TIME_relative_is_forever (struct GNUNET_TIME_Relative rel)
 Test if rel is forever.
 
bool GNUNET_TIME_relative_is_zero (struct GNUNET_TIME_Relative rel)
 Test if rel is zero.
 
bool GNUNET_TIME_absolute_is_past (struct GNUNET_TIME_Absolute abs)
 Test if abs is truly in the past (excluding now).
 
bool GNUNET_TIME_absolute_is_future (struct GNUNET_TIME_Absolute abs)
 Test if abs is truly in the future (excluding now).
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch)
 Convert milliseconds after the UNIX epoch to absolute time.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch)
 Convert seconds after the UNIX epoch to absolute time.
 
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch)
 Convert seconds after the UNIX epoch to timestamp.
 
uint64_t GNUNET_TIME_timestamp_to_s (struct GNUNET_TIME_Timestamp ts)
 Convert timestamp to number of seconds after the UNIX epoch.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a)
 Convert absolute time from network byte order.
 
unsigned int GNUNET_TIME_get_current_year ()
 Return the current year (e.g.
 
unsigned int GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at)
 Convert an expiration time to the respective year (rounds)
 
static time_t my_timegm (struct tm *tm)
 As suggested in the timegm() man page.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_year_to_time (unsigned int year)
 Convert a year to an expiration time of January 1st of that year.
 
struct GNUNET_TIME_Relative GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
 Randomized exponential back-off, starting at 1 ms and going up by a factor of 2+r, where 0 <= r <= 0.5, up to a maximum of the given threshold.
 
bool GNUNET_TIME_absolute_is_zero (struct GNUNET_TIME_Absolute abs)
 Test if abs is truly zero.
 
struct GNUNET_TIME_Relative GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
 Return a random time value between 0.5*r and 1.5*r.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Obtain the current time and make sure it is monotonically increasing.
 
static struct tm * time_to_tm (const time_t *seconds, struct tm *tm, bool utc)
 Convert seconds since the Epoch to broken-down time.
 
static time_t tm_to_time (struct tm *tm, bool utc)
 Convert broken-down time to seconds since the Epoch.
 
static struct GNUNET_TIME_Absolute round_up (struct GNUNET_TIME_Absolute at, enum GNUNET_TIME_RounderInterval ri, bool utc)
 Round up the given at to the interval ri.
 
static struct GNUNET_TIME_Absolute round_down (struct GNUNET_TIME_Absolute at, enum GNUNET_TIME_RounderInterval ri, bool utc)
 Round at down to the start of the interval ri.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_round_up (struct GNUNET_TIME_Absolute at, enum GNUNET_TIME_RounderInterval ri)
 Round up the given at to the interval ri.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_round_up_utc (struct GNUNET_TIME_Absolute at, enum GNUNET_TIME_RounderInterval ri)
 Round up the given at to the interval ri, using UTC calendar boundaries.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_round_down (struct GNUNET_TIME_Absolute at, enum GNUNET_TIME_RounderInterval ri)
 Round @at down to the start of the next interval ri.
 
struct GNUNET_TIME_Absolute GNUNET_TIME_round_down_utc (struct GNUNET_TIME_Absolute at, enum GNUNET_TIME_RounderInterval ri)
 Round @at down to the start of the next interval ri, using UTC calendar boundaries.
 
enum GNUNET_TIME_RounderInterval GNUNET_TIME_relative_to_round_interval (struct GNUNET_TIME_Relative rel)
 Convert a relative time to the corresponding rounding interval.
 
enum GNUNET_GenericReturnValue GNUNET_TIME_string_to_round_interval (const char *ri_str, enum GNUNET_TIME_RounderInterval *ri)
 Convert rounding interval given as a string to the enum value.
 
const char * GNUNET_TIME_round_interval2s (enum GNUNET_TIME_RounderInterval ri)
 Convert rounding interval to string.
 
void GNUNET_util_time_fini (void)
 
void __attribute__ ((destructor))
 Destructor.
 

Variables

static long long timestamp_offset
 Variable used to simulate clock skew.
 
struct { 
 
   enum GNUNET_TIME_RounderInterval   ri 
 
   const char *   str 
 
ri_lookup_table [] 
 Lookup table mapping rounding interval enum values to their string representations.
 

Detailed Description

functions for handling time and time arithmetic

Author
Christian Grothoff

Definition in file time.c.

Macro Definition Documentation

◆ __STDC_NO_ATOMICS__

#define __STDC_NO_ATOMICS__   1

Definition at line 36 of file time.c.

◆ ATOMIC

#define ATOMIC

Definition at line 37 of file time.c.

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-time", __VA_ARGS__)

Definition at line 41 of file time.c.

Function Documentation

◆ my_timegm()

static time_t my_timegm ( struct tm *  tm)
static

As suggested in the timegm() man page.

Definition at line 779 of file time.c.

780{
781 time_t ret;
782 char *tz;
783
784 tz = getenv ("TZ");
785 setenv ("TZ", "", 1);
786 tzset ();
787 ret = mktime (tm);
788 if (tz)
789 setenv ("TZ", tz, 1);
790 else
791 unsetenv ("TZ");
792 tzset ();
793 return ret;
794}
char * getenv()
static int ret
Final status code.
Definition gnunet-arm.c:93

References getenv(), and ret.

Referenced by GNUNET_TIME_year_to_time(), and tm_to_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ time_to_tm()

static struct tm * time_to_tm ( const time_t *  seconds,
struct tm *  tm,
bool  utc 
)
static

Convert seconds since the Epoch to broken-down time.

Parameters
secondstime to convert
[out]tmset to the broken-down time
utctrue to break seconds down in UTC, false to use the local time zone
Returns
tm on success, NULL on error

Definition at line 992 of file time.c.

995{
996 return utc
997 ? gmtime_r (seconds,
998 tm)
999 : localtime_r (seconds,
1000 tm);
1001}

Referenced by round_down(), and round_up().

Here is the caller graph for this function:

◆ tm_to_time()

static time_t tm_to_time ( struct tm *  tm,
bool  utc 
)
static

Convert broken-down time to seconds since the Epoch.

Parameters
[in,out]tmbroken-down time to convert, will be normalized
utctrue if tm is UTC, false if it is local time
Returns
seconds since the Epoch

Definition at line 1012 of file time.c.

1014{
1015 if (! utc)
1016 return mktime (tm);
1017#ifdef HAVE_TIMEGM
1018 return timegm (tm);
1019#else
1020 return my_timegm (tm);
1021#endif
1022}
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
Definition time.c:779

References my_timegm().

Referenced by round_down(), and round_up().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ round_up()

static struct GNUNET_TIME_Absolute round_up ( struct GNUNET_TIME_Absolute  at,
enum GNUNET_TIME_RounderInterval  ri,
bool  utc 
)
static

Round up the given at to the interval ri.

Parameters
atsome absolute time to round
rihow much to round up
utctrue to align to UTC calendar boundaries, false to align to local time zone boundaries
Returns
rounded up value of at

Definition at line 1035 of file time.c.

1038{
1040 time_t seconds;
1041 struct tm timeinfo;
1042
1044 return at;
1045 if (GNUNET_TIME_RI_NONE == ri)
1046 return at;
1047 seconds = at.abs_value_us / 1000000;
1048 if (NULL == time_to_tm (&seconds,
1049 &timeinfo,
1050 utc))
1051 {
1052 GNUNET_break (0);
1053 return at;
1054 }
1055 switch (ri)
1056 {
1058 /* eh, we did this above!? */
1059 GNUNET_break (0);
1060 return at;
1062 if (0 != at.abs_value_us % 1000000)
1063 result.abs_value_us = (seconds + 1) * 1000000ULL;
1064 else
1065 result = at;
1066 return result;
1068 if ( (timeinfo.tm_sec > 0) ||
1069 (0 != at.abs_value_us % 1000000) )
1070 {
1071 timeinfo.tm_sec = 0;
1072 timeinfo.tm_min += 1;
1073 }
1074 break;
1076 /* Round up to next hour */
1077 if ( (timeinfo.tm_min > 0) ||
1078 (timeinfo.tm_sec > 0) ||
1079 (0 != (at.abs_value_us % 1000000)) )
1080 {
1081 timeinfo.tm_sec = 0;
1082 timeinfo.tm_min = 0;
1083 timeinfo.tm_hour += 1;
1084 }
1085 break;
1086 case GNUNET_TIME_RI_DAY:
1087 if ( (timeinfo.tm_hour > 0) ||
1088 (timeinfo.tm_min > 0) ||
1089 (timeinfo.tm_sec > 0) ||
1090 (0 != at.abs_value_us % 1000000) )
1091 {
1092 timeinfo.tm_sec = 0;
1093 timeinfo.tm_min = 0;
1094 timeinfo.tm_hour = 0;
1095 timeinfo.tm_mday += 1;
1096 }
1097 break;
1099 /* Round up to next Monday (ISO 8601 week starts on Monday) */
1100 {
1101 /* tm_way == 0 => Sunday */
1102 int days_until_monday = (8 - timeinfo.tm_wday) % 7;
1103
1104 if ( (0 == days_until_monday) &&
1105 ( (timeinfo.tm_hour > 0) ||
1106 (timeinfo.tm_min > 0) ||
1107 (timeinfo.tm_sec > 0) ||
1108 (0 != at.abs_value_us % 1000000) ) )
1109 days_until_monday = 7;
1110 if (days_until_monday > 0)
1111 {
1112 timeinfo.tm_sec = 0;
1113 timeinfo.tm_min = 0;
1114 timeinfo.tm_hour = 0;
1115 timeinfo.tm_mday += days_until_monday;
1116 }
1117 }
1118 break;
1120 if ( (timeinfo.tm_mday > 1) ||
1121 (timeinfo.tm_hour > 0) ||
1122 (timeinfo.tm_min > 0) ||
1123 (timeinfo.tm_sec > 0) ||
1124 (0 != (at.abs_value_us % 1000000)) )
1125 {
1126 timeinfo.tm_sec = 0;
1127 timeinfo.tm_min = 0;
1128 timeinfo.tm_hour = 0;
1129 timeinfo.tm_mday = 1;
1130 timeinfo.tm_mon += 1;
1131 }
1132 break;
1134 {
1135 int next_quarter_month = ((timeinfo.tm_mon / 3) + 1) * 3;
1136
1137 if ( (next_quarter_month > timeinfo.tm_mon) ||
1138 (timeinfo.tm_mday > 1) ||
1139 (timeinfo.tm_hour > 0) ||
1140 (timeinfo.tm_min > 0) ||
1141 (timeinfo.tm_sec > 0) ||
1142 (0 != (at.abs_value_us % 1000000)) )
1143 {
1144 timeinfo.tm_sec = 0;
1145 timeinfo.tm_min = 0;
1146 timeinfo.tm_hour = 0;
1147 timeinfo.tm_mday = 1;
1148 timeinfo.tm_mon = next_quarter_month;
1149 }
1150 }
1151 break;
1153 if ( (timeinfo.tm_mon > 0) ||
1154 (timeinfo.tm_mday > 1) ||
1155 (timeinfo.tm_hour > 0) ||
1156 (timeinfo.tm_min > 0) ||
1157 (timeinfo.tm_sec > 0) ||
1158 (0 != (at.abs_value_us % 1000000)) )
1159 {
1160 timeinfo.tm_sec = 0;
1161 timeinfo.tm_min = 0;
1162 timeinfo.tm_hour = 0;
1163 timeinfo.tm_mday = 1;
1164 timeinfo.tm_mon = 0;
1165 timeinfo.tm_year += 1;
1166 }
1167 break;
1168 }
1169 result.abs_value_us = ((uint64_t) tm_to_time (&timeinfo,
1170 utc)) * 1000000ULL;
1171 return result;
1172}
static int result
Global testing status.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition time.c:646
@ GNUNET_TIME_RI_NONE
No rounding up.
@ GNUNET_TIME_RI_MINUTE
Round up to the next minute.
@ GNUNET_TIME_RI_QUARTER
Round up to the next quarter.
@ GNUNET_TIME_RI_HOUR
Round up to the next hour.
@ GNUNET_TIME_RI_SECOND
Round up to a multiple of seconds.
@ GNUNET_TIME_RI_WEEK
Round up to the next calendar week.
@ GNUNET_TIME_RI_DAY
Round up to the next day.
@ GNUNET_TIME_RI_YEAR
Round up to the next year.
@ GNUNET_TIME_RI_MONTH
Round up to the next month.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
static struct tm * time_to_tm(const time_t *seconds, struct tm *tm, bool utc)
Convert seconds since the Epoch to broken-down time.
Definition time.c:992
static time_t tm_to_time(struct tm *tm, bool utc)
Convert broken-down time to seconds since the Epoch.
Definition time.c:1012
enum GNUNET_TIME_RounderInterval ri
Definition time.c:1358

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_TIME_absolute_is_never(), GNUNET_TIME_RI_DAY, GNUNET_TIME_RI_HOUR, GNUNET_TIME_RI_MINUTE, GNUNET_TIME_RI_MONTH, GNUNET_TIME_RI_NONE, GNUNET_TIME_RI_QUARTER, GNUNET_TIME_RI_SECOND, GNUNET_TIME_RI_WEEK, GNUNET_TIME_RI_YEAR, result, ri, time_to_tm(), and tm_to_time().

Referenced by GNUNET_TIME_round_up(), and GNUNET_TIME_round_up_utc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ round_down()

static struct GNUNET_TIME_Absolute round_down ( struct GNUNET_TIME_Absolute  at,
enum GNUNET_TIME_RounderInterval  ri,
bool  utc 
)
static

Round at down to the start of the interval ri.

Parameters
atsome absolute time to round
rihow much to round down
utctrue to align to UTC calendar boundaries, false to align to local time zone boundaries
Returns
rounded down value of at

Definition at line 1185 of file time.c.

1188{
1190 time_t seconds;
1191 struct tm timeinfo;
1192
1194 return at;
1195 if (GNUNET_TIME_RI_NONE == ri)
1196 return at;
1197 seconds = at.abs_value_us / 1000000;
1198 if (NULL == time_to_tm (&seconds,
1199 &timeinfo,
1200 utc))
1201 {
1202 GNUNET_break (0);
1203 return at;
1204 }
1205 switch (ri)
1206 {
1208 /* eh, we did this above!? */
1209 GNUNET_break (0);
1210 return at;
1212 result.abs_value_us = seconds * 1000000ULL;
1213 return result;
1215 timeinfo.tm_sec = 0;
1216 break;
1218 timeinfo.tm_sec = 0;
1219 timeinfo.tm_min = 0;
1220 break;
1221 case GNUNET_TIME_RI_DAY:
1222 timeinfo.tm_sec = 0;
1223 timeinfo.tm_min = 0;
1224 timeinfo.tm_hour = 0;
1225 break;
1227 /* Round down to Monday of current week (ISO 8601 week starts Monday) */
1228 {
1229 /* tm_way == 0 => Sunday */
1230 int days_since_monday = (0 == timeinfo.tm_wday)
1231 ? 6
1232 : (timeinfo.tm_wday - 1);
1233
1234 timeinfo.tm_sec = 0;
1235 timeinfo.tm_min = 0;
1236 timeinfo.tm_hour = 0;
1237 timeinfo.tm_mday -= days_since_monday;
1238 }
1239 break;
1241 timeinfo.tm_sec = 0;
1242 timeinfo.tm_min = 0;
1243 timeinfo.tm_hour = 0;
1244 timeinfo.tm_mday = 1;
1245 break;
1247 {
1248 int quarter_start_month = (timeinfo.tm_mon / 3) * 3;
1249
1250 timeinfo.tm_sec = 0;
1251 timeinfo.tm_min = 0;
1252 timeinfo.tm_hour = 0;
1253 timeinfo.tm_mday = 1;
1254 timeinfo.tm_mon = quarter_start_month;
1255 }
1256 break;
1258 timeinfo.tm_sec = 0;
1259 timeinfo.tm_min = 0;
1260 timeinfo.tm_hour = 0;
1261 timeinfo.tm_mday = 1;
1262 timeinfo.tm_mon = 0;
1263 break;
1264 }
1265 result.abs_value_us = (uint64_t) tm_to_time (&timeinfo,
1266 utc) * 1000000ULL;
1267 return result;
1268}

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_TIME_absolute_is_never(), GNUNET_TIME_RI_DAY, GNUNET_TIME_RI_HOUR, GNUNET_TIME_RI_MINUTE, GNUNET_TIME_RI_MONTH, GNUNET_TIME_RI_NONE, GNUNET_TIME_RI_QUARTER, GNUNET_TIME_RI_SECOND, GNUNET_TIME_RI_WEEK, GNUNET_TIME_RI_YEAR, result, ri, time_to_tm(), and tm_to_time().

Referenced by GNUNET_TIME_round_down(), and GNUNET_TIME_round_down_utc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_util_time_fini()

void GNUNET_util_time_fini ( void  )

◆ __attribute__()

void __attribute__ ( (destructor)  )

Destructor.

Definition at line 1420 of file time.c.

1422{
1424}
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition time.c:860

References GNUNET_TIME_absolute_get_monotonic().

Here is the call graph for this function:

Variable Documentation

◆ timestamp_offset

long long timestamp_offset
static

Variable used to simulate clock skew.

Used for testing, never in production.

Definition at line 46 of file time.c.

Referenced by GNUNET_TIME_absolute_get(), GNUNET_TIME_get_offset(), and GNUNET_TIME_set_offset().

◆ ri

◆ str

◆ [struct]

const struct { ... } ri_lookup_table[]
Initial value:
= {
{ GNUNET_TIME_RI_NONE, "NONE" },
{ GNUNET_TIME_RI_SECOND, "SECOND" },
{ GNUNET_TIME_RI_MINUTE, "MINUTE" },
{ GNUNET_TIME_RI_HOUR, "HOUR" },
{ GNUNET_TIME_RI_DAY, "DAY" },
{ GNUNET_TIME_RI_WEEK, "WEEK" },
{ GNUNET_TIME_RI_MONTH, "MONTH" },
{ GNUNET_TIME_RI_QUARTER, "QUARTER" },
{ GNUNET_TIME_RI_YEAR, "YEAR" },
{ 0, NULL }
}

Lookup table mapping rounding interval enum values to their string representations.

Referenced by GNUNET_TIME_round_interval2s(), and GNUNET_TIME_string_to_round_interval().