clockValue.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "clockValue.H"
29 #include <sstream>
30 #include <iomanip>
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 std::string Foam::clockValue::str() const
35 {
36  std::ostringstream os;
37 
38  // seconds
39  const unsigned long ss =
40  std::chrono::duration_cast<std::chrono::seconds>(value_).count();
41 
42  // days
43  const auto dd = (ss / 86400);
44 
45  // hours
46  const int hh = ((ss / 3600) % 24);
47 
48  if (dd) os << dd << '-';
49 
50  if (dd || hh)
51  {
52  os << std::setw(2) << std::setfill('0')
53  << hh << ':';
54  }
55 
56  // minutes
57  os << std::setw(2) << std::setfill('0')
58  << ((ss / 60) % 60) << ':';
59 
60  // seconds
61  os << std::setw(2) << std::setfill('0')
62  << (ss % 60);
63 
64  // milliseconds. As none or 3 decimal places
65  const long ms =
66  (
67  std::chrono::duration_cast<std::chrono::milliseconds>(value_).count()
68  - (ss * 1000)
69  );
70 
71  if (ms > 0)
72  {
73  os << '.' << std::setw(3) << std::setfill('0') << ms;
74  }
75 
76  return os.str();
77 }
78 
79 
80 // ************************************************************************* //
clockValue.H
Foam::clockValue::str
std::string str() const
Format as day-hh:mm:ss string.
Definition: clockValue.C:34
os
OBJstream os(runTime.globalPath()/outputName)
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::setfill
Omanip< char > setfill(char fillch)
Definition: IOmanip.H:175