1// Copyright (C) 2023 Ahmad Samir <a.samirh78@gmail.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef Q20CHRONO_H
5#define Q20CHRONO_H
6
7#include <QtCore/qtconfigmacros.h>
8
9#include <chrono>
10
11//
12// W A R N I N G
13// -------------
14//
15// This file is not part of the Qt API. Types and functions defined in this
16// file can reliably be replaced by their std counterparts, once available.
17// You may use these definitions in your own code, but be aware that we
18// will remove them once Qt depends on the C++ version that supports
19// them in namespace std. There will be NO deprecation warning, the
20// definitions will JUST go away.
21//
22// If you can't agree to these terms, don't use these definitions!
23//
24// We mean it.
25//
26
27QT_BEGIN_NAMESPACE
28
29namespace q20 {
30namespace chrono {
31
32#if defined(__GLIBCXX__)
33// https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/include/bits/chrono.h
34using IntRep = int64_t;
35#else
36// https://github.com/llvm/llvm-project/blob/main/libcxx/include/__chrono/duration.h
37// https://github.com/microsoft/STL/blob/main/stl/inc/__msvc_chrono.hpp
38using IntRep = int;
39#endif
40
41#if __cpp_lib_chrono >= 201907L
42using std::chrono::days;
43using std::chrono::weeks;
44using std::chrono::years;
45using std::chrono::months;
46
47static_assert(std::is_same_v<days::rep, IntRep>);
48static_assert(std::is_same_v<weeks::rep, IntRep>);
49static_assert(std::is_same_v<years::rep, IntRep>);
50static_assert(std::is_same_v<months::rep, IntRep>);
51#else // __cpp_lib_chrono >= 201907L
52using days = std::chrono::duration<IntRep, std::ratio<86400>>;
53using weeks = std::chrono::duration<IntRep, std::ratio_multiply<std::ratio<7>, days::period>>;
54using years = std::chrono::duration<IntRep, std::ratio_multiply<std::ratio<146097, 400>, days::period>>;
55using months = std::chrono::duration<IntRep, std::ratio_divide<years::period, std::ratio<12>>>;
56#endif // __cpp_lib_chrono >= 201907L
57} // namespace chrono
58} // namespace q20
59
60QT_END_NAMESPACE
61
62#endif /* Q20CHRONO_H */
63

source code of qtbase/src/corelib/global/q20chrono.h