Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-29 09:22:59

0001 // Copyright (C) 2023 Ahmad Samir <a.samirh78@gmail.com>
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef Q20CHRONO_H
0006 #define Q20CHRONO_H
0007 
0008 #include <QtCore/qtconfigmacros.h>
0009 
0010 #include <chrono>
0011 
0012 //
0013 //  W A R N I N G
0014 //  -------------
0015 //
0016 // This file is not part of the Qt API. Types and functions defined in this
0017 // file can reliably be replaced by their std counterparts, once available.
0018 // You may use these definitions in your own code, but be aware that we
0019 // will remove them once Qt depends on the C++ version that supports
0020 // them in namespace std. There will be NO deprecation warning, the
0021 // definitions will JUST go away.
0022 //
0023 // If you can't agree to these terms, don't use these definitions!
0024 //
0025 // We mean it.
0026 //
0027 
0028 QT_BEGIN_NAMESPACE
0029 
0030 namespace q20 {
0031 namespace chrono {
0032 
0033 #if defined(__GLIBCXX__)
0034 // https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/include/bits/chrono.h
0035 using IntRep = int64_t;
0036 #else
0037 // https://github.com/llvm/llvm-project/blob/main/libcxx/include/__chrono/duration.h
0038 // https://github.com/microsoft/STL/blob/main/stl/inc/__msvc_chrono.hpp
0039 using IntRep = int;
0040 #endif
0041 
0042 // INTEGRITY incident-85878 (timezone and clock_cast are not supported)
0043 #if __cpp_lib_chrono >= 201907L && !defined(Q_OS_INTEGRITY)
0044 using std::chrono::days;
0045 using std::chrono::weeks;
0046 using std::chrono::years;
0047 using std::chrono::months;
0048 
0049 static_assert(std::is_same_v<days::rep, IntRep>);
0050 static_assert(std::is_same_v<weeks::rep, IntRep>);
0051 static_assert(std::is_same_v<years::rep, IntRep>);
0052 static_assert(std::is_same_v<months::rep, IntRep>);
0053 #else
0054 using days = std::chrono::duration<IntRep, std::ratio<86400>>;
0055 using weeks = std::chrono::duration<IntRep, std::ratio_multiply<std::ratio<7>, days::period>>;
0056 using years = std::chrono::duration<IntRep, std::ratio_multiply<std::ratio<146097, 400>, days::period>>;
0057 using months = std::chrono::duration<IntRep, std::ratio_divide<years::period, std::ratio<12>>>;
0058 #endif // __cpp_lib_chrono >= 201907L
0059 } // namespace chrono
0060 } // namespace q20
0061 
0062 QT_END_NAMESPACE
0063 
0064 #endif /* Q20CHRONO_H */