Coverage Report

Created: 2024-10-11 06:23

/builds/MusicScience37Projects/numerical-analysis/numerical-collection-cpp/src/num_collect/logging/time_stamp.cpp
Line
Count
Source
1
/*
2
 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3
 *
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
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
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.
15
 */
16
/*!
17
 * \file
18
 * \brief Implementation of time_stamp class.
19
 */
20
#include "num_collect/logging/time_stamp.h"
21
22
#include <cassert>
23
#include <ctime>
24
25
namespace num_collect::logging {
26
27
time_stamp::time_stamp(std::time_t seconds, std::uint32_t nanoseconds) noexcept
28
39.1k
    : seconds_(seconds), nanoseconds_(nanoseconds) {}
29
30
39.1k
auto time_stamp::seconds() const noexcept -> std::time_t { return seconds_; }
31
32
39.1k
auto time_stamp::nanoseconds() const noexcept -> std::uint32_t {
33
39.1k
    return nanoseconds_;
34
39.1k
}
35
36
39.1k
auto time_stamp::now() noexcept -> time_stamp {
37
39.1k
    std::timespec spec{};
38
39.1k
    const auto result = std::timespec_get(&spec, TIME_UTC);
39
39.1k
    assert(result == TIME_UTC);
40
39.1k
    (void)result;
41
39.1k
    return time_stamp(spec.tv_sec, static_cast<std::uint32_t>(spec.tv_nsec));
42
39.1k
}
43
44
}  // namespace num_collect::logging