Kea 1.5.0
boost_time_utils.cc
Go to the documentation of this file.
1// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
10#include <sstream>
11#include <iomanip>
12
13std::string
14isc::util::ptimeToText(boost::posix_time::ptime t) {
15 boost::gregorian::date d = t.date();
16 std::stringstream s;
17 s << d.year()
18 << "-" << std::setw(2) << std::setfill('0') << d.month().as_number()
19 << "-" << std::setw(2) << std::setfill('0') << d.day()
20 << " " << durationToText(t.time_of_day());
21 return (s.str());
22}
23
24std::string
25isc::util::durationToText(boost::posix_time::time_duration dur) {
26 std::stringstream s;
27 s << std::setw(2) << std::setfill('0') << dur.hours()
28 << ":" << std::setw(2) << std::setfill('0') << dur.minutes()
29 << ":" << std::setw(2) << std::setfill('0') << dur.seconds()
30 << "." << std::setw(boost::posix_time::time_duration::num_fractional_digits())
31 << std::setfill('0')
32 << dur.fractional_seconds();
33
34 return (s.str());
35}
std::string ptimeToText(boost::posix_time::ptime t)
Converts ptime structure to text.
std::string durationToText(boost::posix_time::time_duration dur)
Converts StatsDuration to text.