2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "debug_utils.h"
22 * Number of digits after decimal point used in geo coordinates.
24 #define GEO_LOCATION_PRECISION 7
26 std::string ctx::DebugUtils::humanReadableDateTime(time_t timestamp, std::string format, size_t size, bool utc)
34 result = gmtime_r(×tamp, &timeinfo);
36 result = localtime_r(×tamp, &timeinfo);
40 strftime(buffer, size, format.c_str(), &timeinfo);
42 snprintf(buffer, size, "NULL");
44 return std::string(buffer);
47 void ctx::DebugUtils::printPlace2Stream(const Place &place, std::ostream &out)
49 out << "PLACE:" << std::endl;
50 out << "__CATEGORY: " << place.name << std::endl;
51 if (place.locationValid) {
52 out << "__LOCATION: lat=" << std::setprecision(GEO_LOCATION_PRECISION + 2) << place.location.latitude;
53 out << ", lon=" << place.location.longitude << std::setprecision(5) << std::endl;
55 out << "__WIFI:" << std::endl;
56 for (std::pair<std::string, std::string> ap : place.wifiAps) {
57 out << "____ " << ap.first << " : " << ap.second << std::endl;
59 out << "__CREATE_DATE: " << humanReadableDateTime(place.createDate, "%F %T", 80) << std::endl;