Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
q20chrono.h
Go to the documentation of this file.
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
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
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
61
62#endif /* Q20CHRONO_H */
Combined button and popup list for selecting options.
std::chrono::duration< IntRep, std::ratio_multiply< std::ratio< 7 >, days::period > > weeks
Definition q20chrono.h:53
std::chrono::duration< IntRep, std::ratio< 86400 > > days
Definition q20chrono.h:52
std::chrono::duration< IntRep, std::ratio_divide< years::period, std::ratio< 12 > > > months
Definition q20chrono.h:55
std::chrono::duration< IntRep, std::ratio_multiply< std::ratio< 146097, 400 >, days::period > > years
Definition q20chrono.h:54