Skip to content

Commit

Permalink
feat(discord-client): add discord_timestamp_us(microseconds)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anotra committed Mar 24, 2022
1 parent a6b54dc commit 5dcc700
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cog-utils/cog-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ cog_timestamp_ms(void)
return 0;
}

/* returns current timestamp in microseconds */
uint64_t
cog_timestamp_us(void)
{
struct PsnipClockTimespec t;
if (0 == psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &t)) {
return (uint64_t)t.seconds * 1000000 + (uint64_t)t.nanoseconds / 1000;
}
return 0;
}

/* this can be used for checking if a user-given string does not
* exceeds a arbitrary threshold length */
size_t
Expand Down
7 changes: 7 additions & 0 deletions cog-utils/cog-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ int cog_sleep_ms(const long tms);
*/
uint64_t cog_timestamp_ms(void);

/**
* @brief Get the current timestamp in microseconds
*
* @return the timestamp on success, 0 on failure
*/
uint64_t cog_timestamp_us(void);

/**
* @brief Check if arbitrary string length is exceeded
*
Expand Down
8 changes: 8 additions & 0 deletions include/discord.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ int discord_get_ping(struct discord *client);
*/
uint64_t discord_timestamp(struct discord *client);

/**
* @brief Get the current timestamp (in microseconds)
*
* @param client the client created with discord_init()
* @return the timestamp in microseconds
*/
uint64_t discord_timestamp_us(struct discord *client);

/**
* @brief Retrieve client's logging module for configuration purposes
* @see logconf_setup(), logconf_set_quiet(), logconf_set_level()
Expand Down
6 changes: 6 additions & 0 deletions src/discord-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ discord_timestamp(struct discord *client)
(void)client;
return cog_timestamp_ms();
}
uint64_t
discord_timestamp_us(struct discord *client)
{
(void)client;
return cog_timestamp_us();
}

struct logconf *
discord_get_logconf(struct discord *client)
Expand Down

0 comments on commit 5dcc700

Please sign in to comment.