xref: /5.5.2/platform/include/platform/timeutils.h (revision 5c6a39bc)
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2015 Couchbase, Inc.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17#pragma once
18
19#include <platform/platform.h>
20#include <chrono>
21#include <string>
22
23namespace cb {
24/**
25 * Convert a time (in ns) to a human readable form...
26 *
27 * Up to 9999ns, print as ns
28 * up to 9999µs, print as µs
29 * up to 9999ms, print as ms
30 * up to 599s, print as s
31 *
32 * Anything else is printed as h:m:s
33 *
34 * @param time the time in nanoseconds
35 * @return a string representation of the timestamp
36 */
37PLATFORM_PUBLIC_API
38std::string time2text(const std::chrono::nanoseconds time);
39}
40