/src/logging-log4cxx/src/main/cpp/date.cpp
| Line | Count | Source | 
| 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 | 0 | #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 | 0 | Date::Date() : time(currentTime()) | 
| 36 | 0 | { | 
| 37 | 0 | } | 
| 38 |  |  | 
| 39 | 0 | Date::Date(log4cxx_time_t t) : time(t) | 
| 40 | 0 | { | 
| 41 | 0 | } | 
| 42 |  |  | 
| 43 |  | Date::~Date() | 
| 44 | 0 | { | 
| 45 | 0 | } | 
| 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 | 0 | { | 
| 60 | 0 |   return ((time / LOG4CXX_USEC_PER_SEC) + 1) * LOG4CXX_USEC_PER_SEC; | 
| 61 | 0 | } | 
| 62 |  |  | 
| 63 | 0 | void Date::setGetCurrentTimeFunction(GetCurrentTimeFn fn){ | 
| 64 | 0 |   getCurrentTimeFn = fn; | 
| 65 | 0 | } | 
| 66 |  |  | 
| 67 | 2.48k | log4cxx_time_t Date::currentTime(){ | 
| 68 | 2.48k |   return getCurrentTimeFn ? getCurrentTimeFn() : getCurrentTimeStd(); | 
| 69 | 2.48k | } | 
| 70 |  |  | 
| 71 | 2.48k | log4cxx_time_t Date::getCurrentTimeStd(){ | 
| 72 | 2.48k |   return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); | 
| 73 | 2.48k | } |