/builddir/build/BUILD/gru-0.2.0/src/time/gru_time_utils.c File Reference

#include "gru_time_utils.h"

Functions

void gru_time_add_microseconds (gru_timestamp_t *t, uint64_t count)
 Copyright 2016 Otavio Rodolfo Piske.
void gru_time_add_seconds (gru_timestamp_t *t, uint64_t count)
 Add seconds to a timestamp object.
void gru_time_add_minutes (gru_timestamp_t *t, uint64_t count)
 Add minutes to a timestamp object.
void gru_time_add_hours (gru_timestamp_t *t, uint64_t count)
 Add hours to a timestamp object.
void gru_time_add_days (gru_timestamp_t *t, uint64_t count)
 Add days to a timestamp object.
gru_timestamp_t gru_time_read_str (const char *str)
 Read a string in the format seconds.microseconds and return a struct timeval.
char * gru_time_write_str (const gru_timestamp_t *t)
 Write a timeval structure to a string.
char * gru_time_write_format (const gru_timestamp_t *t, const char *format, gru_status_t *status)
 Writes the input timestamp value according to the given format.
gru_timestamp_t gru_time_now ()
 Gets the current moment in time.
uint64_t gru_time_now_milli ()
 Gets the current moment in time in milliseconds.
gru_timestamp_t gru_time_from_milli (int64_t timestamp)
 Converts milliseconds since epoch to a timestamp.
gru_timestamp_t gru_time_from_milli_char (const char *ts)
 Converts an unformatted string of milliseconds since epoch to a timestamp.
int64_t gru_time_to_milli (const gru_timestamp_t *ts)
 Converts a timestamp to milliseconds.
int64_t gru_time_elapsed_secs (gru_timestamp_t start, gru_timestamp_t end)
 Calculates the elapsed time between two timestamps.
int64_t gru_time_elapsed_milli (gru_timestamp_t start, gru_timestamp_t end)
 Calculates the elapsed time between two timestamps.

Function Documentation

void gru_time_add_days ( gru_timestamp_t t,
uint64_t  count 
)

Add days to a timestamp object.

Parameters:
t timestamp
count number of days to add
void gru_time_add_hours ( gru_timestamp_t t,
uint64_t  count 
)

Add hours to a timestamp object.

Parameters:
t timestamp
count number of hours to add
void gru_time_add_microseconds ( gru_timestamp_t t,
uint64_t  count 
)

Copyright 2016 Otavio Rodolfo Piske.

Add microseconds to a timestamp object.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

void gru_time_add_minutes ( gru_timestamp_t t,
uint64_t  count 
)

Add minutes to a timestamp object.

Parameters:
t timestamp
count number of minutes to add
void gru_time_add_seconds ( gru_timestamp_t t,
uint64_t  count 
)

Add seconds to a timestamp object.

Parameters:
t timestamp
count number of seconds to add
int64_t gru_time_elapsed_milli ( gru_timestamp_t  start,
gru_timestamp_t  end 
)

Calculates the elapsed time between two timestamps.

Parameters:
start Start time
end End time
Note:
The behavior is undefined if the end time is smaller than the start time
Returns:
The elapsed time in milliseconds
int64_t gru_time_elapsed_secs ( gru_timestamp_t  start,
gru_timestamp_t  end 
)

Calculates the elapsed time between two timestamps.

Parameters:
start Start time
end End time
Note:
The behavior is undefined if the end time is smaller than the start time
Returns:
The elapsed time in seconds
gru_timestamp_t gru_time_from_milli ( int64_t  timestamp  ) 

Converts milliseconds since epoch to a timestamp.

Parameters:
timestamp milliseconds since Epoch
Returns:
a timestamp object with the converted data
gru_timestamp_t gru_time_from_milli_char ( const char *  ts  ) 

Converts an unformatted string of milliseconds since epoch to a timestamp.

Parameters:
ts A numeric string representing the milliseconds since epoch (ie.: 1484719545264)
Returns:
a timestamp object with the parsed data
gru_timestamp_t gru_time_now (  ) 

Gets the current moment in time.

Returns:
a timestamp object with the current point in time
uint64_t gru_time_now_milli (  ) 

Gets the current moment in time in milliseconds.

Returns:
current time in milliseconds since Epoch
gru_timestamp_t gru_time_read_str ( const char *  str  ) 

Read a string in the format seconds.microseconds and return a struct timeval.

The microseconds represents the fraction of the seconds value and should not be equal or greater than 1000000. Otherwise, the code will only consider the first 6 bytes of the microseconds string.

Parameters:
str The string in the format seconds.microseconds
Returns:
a timestamp object with the parsed data
Examples:
time/gru_time_conversion_test.c, and time/gru_time_read_test.c.
int64_t gru_time_to_milli ( const gru_timestamp_t ts  ) 

Converts a timestamp to milliseconds.

Parameters:
ts A pointer to a timestamp structure
Returns:
the timestamp as a milliseconds since epoch
Examples:
time/gru_time_conversion_test.c.
char* gru_time_write_format ( const gru_timestamp_t t,
const char *  format,
gru_status_t status 
)

Writes the input timestamp value according to the given format.

Parameters:
t Input timestamp structure
format output format
status status structure that may contain error details in case of failure
Returns:
A pointer to a formatted string or NULL in case of failure. The returned string must be free'd after use
char* gru_time_write_str ( const gru_timestamp_t t  ) 

Write a timeval structure to a string.

Parameters:
t the timeval structure
Returns:
A string that must be free'd after use
Examples:
time/gru_time_read_test.c.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 7 Jan 2019 for GRU - Generic Reusable Utilities by  doxygen 1.6.1