1 // Copyright (C) 2015-2019 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 #ifndef KEA_BOOST_TIME_UTILS_H 8 #define KEA_BOOST_TIME_UTILS_H 9 10 #include <boost/date_time/posix_time/posix_time.hpp> 11 #include <string> 12 13 namespace isc { 14 namespace util { 15 16 /// @brief The number of digits of fractional seconds supplied by the 17 /// underlying class, boost::posix_time. Typically 6 = microseconds. 18 const size_t MAX_FSECS_PRECISION=boost::posix_time::time_duration::num_fractional_digits(); 19 20 /// @brief Converts ptime structure to text 21 /// 22 /// This is Kea implementation for converting ptime to strings. 23 /// It's a functional equivalent of boost::posix_time::to_simple_string. We do 24 /// not use it, though, because it would introduce unclear dependency on 25 /// boost_time_date library. First, we try to avoid depending on boost libraries 26 /// (we tend to use only the headers). Second, this dependency is system 27 /// specific, i.e. it is required on Ubuntu and FreeBSD, but doesn't seem to 28 /// be needed on OS X. Since the functionality needed is minor, we decided to 29 /// reimplement it on our own, rather than introduce extra dependencies. 30 /// This explanation also applies to @ref durationToText. 31 /// @param t ptime value to convert to text 32 /// @param fsecs_precision number of digits of precision for fractional seconds. 33 /// Default is given by boost::posix_time::time_duration::num_fractional_digits(). 34 /// Zero omits the value. 35 /// 36 /// @return a string representing time 37 std::string ptimeToText(boost::posix_time::ptime t, 38 size_t fsecs_precision = MAX_FSECS_PRECISION); 39 40 /// @brief Converts StatsDuration to text 41 /// 42 /// This is Kea equivalent of boost::posix_time::to_simple_string(time_duration). 43 /// See @ref ptimeToText for explanation why we chose our own implementation. 44 /// @param dur duration value to convert to text 45 /// @param fsecs_precision number of digits of precision for fractional seconds. 46 /// Default is given by boost::posix_time::time_duration::num_fractional_digits(). 47 /// Zero omits the value. 48 /// 49 /// @return a string representing time 50 std::string durationToText(boost::posix_time::time_duration dur, 51 size_t fsecs_precision = MAX_FSECS_PRECISION); 52 53 }; // end of isc::util namespace 54 }; // end of isc namespace 55 56 #endif 57