/src/logging-log4cxx/src/main/cpp/date.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. 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 | | #include <log4cxx/logstring.h> |
18 | | #include <log4cxx/helpers/date.h> |
19 | | #include <chrono> |
20 | | |
21 | 4.98k | #define LOG4CXX_USEC_PER_SEC 1000000LL |
22 | | #ifndef INT64_C |
23 | | #define INT64_C(x) x ## LL |
24 | | #endif |
25 | | |
26 | | using namespace LOG4CXX_NS; |
27 | | using namespace LOG4CXX_NS::helpers; |
28 | | |
29 | | IMPLEMENT_LOG4CXX_OBJECT(Date) |
30 | | |
31 | | namespace { |
32 | | Date::GetCurrentTimeFn getCurrentTimeFn = 0; |
33 | | } |
34 | | |
35 | 5.60k | Date::Date() : time(currentTime()) |
36 | 5.60k | { |
37 | 5.60k | } |
38 | | |
39 | 2.49k | Date::Date(log4cxx_time_t t) : time(t) |
40 | 2.49k | { |
41 | 2.49k | } |
42 | | |
43 | | Date::~Date() |
44 | 8.10k | { |
45 | 8.10k | } |
46 | | |
47 | | log4cxx_time_t Date::getMicrosecondsPerDay() |
48 | 0 | { |
49 | 0 | return 86400000000ull; |
50 | 0 | } |
51 | | |
52 | | log4cxx_time_t Date::getMicrosecondsPerSecond() |
53 | 0 | { |
54 | 0 | return LOG4CXX_USEC_PER_SEC; |
55 | 0 | } |
56 | | |
57 | | |
58 | | log4cxx_time_t Date::getNextSecond() const |
59 | 2.49k | { |
60 | 2.49k | return ((time / LOG4CXX_USEC_PER_SEC) + 1) * LOG4CXX_USEC_PER_SEC; |
61 | 2.49k | } |
62 | | |
63 | 0 | void Date::setGetCurrentTimeFunction(GetCurrentTimeFn fn){ |
64 | 0 | getCurrentTimeFn = fn; |
65 | 0 | } |
66 | | |
67 | 508k | log4cxx_time_t Date::currentTime(){ |
68 | 508k | return getCurrentTimeFn ? getCurrentTimeFn() : getCurrentTimeStd(); |
69 | 508k | } |
70 | | |
71 | 508k | log4cxx_time_t Date::getCurrentTimeStd(){ |
72 | 508k | return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); |
73 | 508k | } |