Skip to content

Commit

Permalink
Cleaner approach to generate timestamp string with no newline character
Browse files Browse the repository at this point in the history
  • Loading branch information
arista-nwolfe committed May 2, 2024
1 parent 414028a commit 64c61e9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3120,18 +3120,18 @@ void PortsOrch::updateDbPortFlapCount(Port& port, sai_port_oper_status_t pstatus
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
if (pstatus == SAI_PORT_OPER_STATUS_DOWN)
{
// std::ctime returns a string with an unwanted newline character so we trim it
char * timeStr = std::ctime(&now_c);
timeStr[strlen(timeStr)-1] = '\0';
FieldValueTuple tuple("last_down_time", timeStr);
char buffer[32];
// Format: Www Mmm dd hh:mm:ss yyyy
std::strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", std::localtime(&now_c));
FieldValueTuple tuple("last_down_time", buffer);
tuples.push_back(tuple);
}
else if (pstatus == SAI_PORT_OPER_STATUS_UP)
{
// std::ctime returns a string with an unwanted newline character so we trim it
char * timeStr = std::ctime(&now_c);
timeStr[strlen(timeStr)-1] = '\0';
FieldValueTuple tuple("last_up_time", timeStr);
char buffer[32];
// Format: Www Mmm dd hh:mm:ss yyyy
std::strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", std::localtime(&now_c));
FieldValueTuple tuple("last_up_time", buffer);
tuples.push_back(tuple);
}
m_portTable->set(port.m_alias, tuples);
Expand Down

0 comments on commit 64c61e9

Please sign in to comment.