Skip to content

Commit

Permalink
Remove unwanted newline character at end of timestamp (sonic-net#3111)
Browse files Browse the repository at this point in the history
* Remove unwanted newline character at end of timestamp
* Cleaner approach to generate timestamp string with no newline character
* Use UTC rather than local time in timestamp
  • Loading branch information
arista-nwolfe authored and mssonicbld committed Aug 8, 2024
1 parent a5dd46d commit 6d250a9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3110,12 +3110,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)
{
FieldValueTuple tuple("last_down_time", std::ctime(&now_c));
char buffer[32];
// Format: Www Mmm dd hh:mm:ss yyyy
std::strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", std::gmtime(&now_c));
FieldValueTuple tuple("last_down_time", buffer);
tuples.push_back(tuple);
}
else if (pstatus == SAI_PORT_OPER_STATUS_UP)
{
FieldValueTuple tuple("last_up_time", std::ctime(&now_c));
char buffer[32];
// Format: Www Mmm dd hh:mm:ss yyyy
std::strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", std::gmtime(&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 6d250a9

Please sign in to comment.