Molecular Dynamics Simulation  1.0
Functions
FormatTime.cpp File Reference
#include "FormatTime.h"
#include "io/logger/Logger.h"
Include dependency graph for FormatTime.cpp:

Go to the source code of this file.

Functions

std::string format_seconds_eta (int total_seconds)
 Formats the given seconds into a string of the form "HH:MM:SS". More...
 
std::string format_mup_s (double mup_s)
 Formats the given mup/s into a string. More...
 
std::string format_seconds_total (double total_seconds)
 Formats the given seconds into a string of the form "HHh MMm SSs MMMms". More...
 

Function Documentation

◆ format_mup_s()

std::string format_mup_s ( double  mup_s)

Formats the given mup/s into a string.

Parameters
mup_smup/s to be formatted
Returns
std::string Formatted string

If the given mup/s are negative, "N/A" is returned. If the given mup/s are greater than 1000, the value is divided by 1000 and a "k" is appended. If the given mup/s are greater than 1000000, the value is divided by 1000000 and a "M" is appended.

Definition at line 17 of file FormatTime.cpp.

17  {
18  if (mup_s < 0) {
19  return "N/A";
20  }
21 
22  std::string suffix = "";
23  if (mup_s > 1000000) {
24  mup_s /= 1000000;
25  suffix = "M";
26  } else if (mup_s > 1000) {
27  mup_s /= 1000;
28  suffix = "k";
29  }
30 
31  return fmt::format("{:.2f}{}", mup_s, suffix);
32 }

◆ format_seconds_eta()

std::string format_seconds_eta ( int  total_seconds)

Formats the given seconds into a string of the form "HH:MM:SS".

Parameters
total_secondsSeconds to be formatted
Returns
std::string Formatted string

If the given seconds are negative, "N/A" is returned.

Definition at line 5 of file FormatTime.cpp.

5  {
6  if (total_seconds < 0) {
7  return "N/A";
8  }
9 
10  int hours = total_seconds / 3600;
11  int minutes = (total_seconds % 3600) / 60;
12  int seconds = total_seconds % 60;
13 
14  return fmt::format("{:02d}:{:02d}:{:02d}", hours, minutes, seconds);
15 }

◆ format_seconds_total()

std::string format_seconds_total ( double  total_seconds)

Formats the given seconds into a string of the form "HHh MMm SSs MMMms".

Parameters
total_secondsSeconds to be formatted
Returns
std::string Formatted string

If the given seconds are negative, "N/A" is returned.

Definition at line 34 of file FormatTime.cpp.

34  {
35  if (total_seconds < 0) {
36  return "N/A";
37  }
38 
39  int hours = static_cast<int>(total_seconds) / 3600;
40  int minutes = (static_cast<int>(total_seconds) % 3600) / 60;
41  int seconds = static_cast<int>(total_seconds) % 60;
42  int millis = static_cast<int>(total_seconds * 1000) % 1000;
43 
44  return fmt::format("{}h {}m {}s {}ms", hours, minutes, seconds, millis);
45 }