catboost 1.25.1 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPLOYMENT.md +22 -15
- package/README.md +37 -27
- package/binding.gyp +5 -7
- package/build_scripts/bootstrap.js +2 -1
- package/build_scripts/out/build.js +46 -68
- package/build_scripts/out/build_model.js +1 -1
- package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
- package/build_scripts/out/ci.js +5 -5
- package/build_scripts/out/config.js +32 -18
- package/build_scripts/out/install.js +5 -3
- package/build_scripts/out/package_prepublish.js +1 -1
- package/build_scripts/out/packaging.js +1 -19
- package/build_scripts/out/run_tests.js +1 -1
- package/build_scripts/out/test.js +8 -3
- package/config.json +18 -11
- package/inc/catboost/libs/model_interface/c_api.h +349 -3
- package/lib/catboost.d.ts +65 -21
- package/package.json +4 -4
- package/src/api_helpers.cpp +100 -24
- package/src/api_helpers.h +8 -7
- package/src/api_module.cpp +1 -2
- package/src/model.cpp +483 -83
- package/src/model.h +24 -9
- package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
- package/inc/util/charset/recode_result.h +0 -9
- package/inc/util/charset/unicode_table.h +0 -123
- package/inc/util/charset/unidata.h +0 -421
- package/inc/util/charset/utf8.h +0 -384
- package/inc/util/charset/wide.h +0 -843
- package/inc/util/charset/wide_specific.h +0 -22
- package/inc/util/datetime/base.h +0 -669
- package/inc/util/datetime/constants.h +0 -7
- package/inc/util/datetime/cputimer.h +0 -124
- package/inc/util/datetime/parser.h +0 -292
- package/inc/util/datetime/systime.h +0 -47
- package/inc/util/datetime/uptime.h +0 -8
- package/inc/util/digest/city.h +0 -88
- package/inc/util/digest/fnv.h +0 -73
- package/inc/util/digest/multi.h +0 -14
- package/inc/util/digest/murmur.h +0 -57
- package/inc/util/digest/numeric.h +0 -86
- package/inc/util/digest/sequence.h +0 -48
- package/inc/util/draft/date.h +0 -129
- package/inc/util/draft/datetime.h +0 -184
- package/inc/util/draft/enum.h +0 -136
- package/inc/util/draft/holder_vector.h +0 -102
- package/inc/util/draft/ip.h +0 -131
- package/inc/util/draft/matrix.h +0 -108
- package/inc/util/draft/memory.h +0 -40
- package/inc/util/folder/dirent_win.h +0 -46
- package/inc/util/folder/dirut.h +0 -121
- package/inc/util/folder/filelist.h +0 -81
- package/inc/util/folder/fts.h +0 -108
- package/inc/util/folder/iterator.h +0 -109
- package/inc/util/folder/lstat_win.h +0 -20
- package/inc/util/folder/path.h +0 -225
- package/inc/util/folder/pathsplit.h +0 -113
- package/inc/util/folder/tempdir.h +0 -42
- package/inc/util/generic/adaptor.h +0 -134
- package/inc/util/generic/algorithm.h +0 -765
- package/inc/util/generic/array_ref.h +0 -282
- package/inc/util/generic/array_size.h +0 -24
- package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
- package/inc/util/generic/bitmap.h +0 -1115
- package/inc/util/generic/bitops.h +0 -459
- package/inc/util/generic/bt_exception.h +0 -24
- package/inc/util/generic/buffer.h +0 -232
- package/inc/util/generic/cast.h +0 -176
- package/inc/util/generic/deque.h +0 -24
- package/inc/util/generic/explicit_type.h +0 -42
- package/inc/util/generic/fastqueue.h +0 -55
- package/inc/util/generic/flags.h +0 -244
- package/inc/util/generic/function.h +0 -103
- package/inc/util/generic/fwd.h +0 -171
- package/inc/util/generic/guid.h +0 -61
- package/inc/util/generic/hash.h +0 -2032
- package/inc/util/generic/hash_primes.h +0 -140
- package/inc/util/generic/hash_set.h +0 -490
- package/inc/util/generic/hide_ptr.h +0 -3
- package/inc/util/generic/intrlist.h +0 -876
- package/inc/util/generic/is_in.h +0 -53
- package/inc/util/generic/iterator.h +0 -137
- package/inc/util/generic/iterator_range.h +0 -105
- package/inc/util/generic/lazy_value.h +0 -66
- package/inc/util/generic/list.h +0 -22
- package/inc/util/generic/map.h +0 -44
- package/inc/util/generic/mapfindptr.h +0 -60
- package/inc/util/generic/maybe.h +0 -713
- package/inc/util/generic/maybe_traits.h +0 -164
- package/inc/util/generic/mem_copy.h +0 -55
- package/inc/util/generic/noncopyable.h +0 -38
- package/inc/util/generic/object_counter.h +0 -53
- package/inc/util/generic/ptr.h +0 -1113
- package/inc/util/generic/queue.h +0 -57
- package/inc/util/generic/refcount.h +0 -162
- package/inc/util/generic/reserve.h +0 -11
- package/inc/util/generic/scope.h +0 -65
- package/inc/util/generic/serialized_enum.h +0 -406
- package/inc/util/generic/set.h +0 -42
- package/inc/util/generic/singleton.h +0 -136
- package/inc/util/generic/size_literals.h +0 -65
- package/inc/util/generic/stack.h +0 -18
- package/inc/util/generic/store_policy.h +0 -120
- package/inc/util/generic/strbase.h +0 -612
- package/inc/util/generic/strbuf.h +0 -552
- package/inc/util/generic/strfcpy.h +0 -17
- package/inc/util/generic/string.h +0 -1572
- package/inc/util/generic/string_hash.h +0 -21
- package/inc/util/generic/string_ut.h +0 -1175
- package/inc/util/generic/type_name.h +0 -34
- package/inc/util/generic/typelist.h +0 -114
- package/inc/util/generic/typetraits.h +0 -325
- package/inc/util/generic/utility.h +0 -132
- package/inc/util/generic/va_args.h +0 -400
- package/inc/util/generic/variant.h +0 -631
- package/inc/util/generic/variant_traits.h +0 -171
- package/inc/util/generic/vector.h +0 -119
- package/inc/util/generic/xrange.h +0 -258
- package/inc/util/generic/yexception.h +0 -212
- package/inc/util/generic/yexception_ut.h +0 -14
- package/inc/util/generic/ylimits.h +0 -92
- package/inc/util/generic/ymath.h +0 -206
- package/inc/util/memory/addstorage.h +0 -93
- package/inc/util/memory/alloc.h +0 -27
- package/inc/util/memory/blob.h +0 -296
- package/inc/util/memory/mmapalloc.h +0 -8
- package/inc/util/memory/pool.h +0 -432
- package/inc/util/memory/segmented_string_pool.h +0 -194
- package/inc/util/memory/segpool_alloc.h +0 -118
- package/inc/util/memory/smallobj.h +0 -141
- package/inc/util/memory/tempbuf.h +0 -111
- package/inc/util/network/address.h +0 -136
- package/inc/util/network/endpoint.h +0 -61
- package/inc/util/network/hostip.h +0 -16
- package/inc/util/network/init.h +0 -60
- package/inc/util/network/interface.h +0 -17
- package/inc/util/network/iovec.h +0 -65
- package/inc/util/network/ip.h +0 -116
- package/inc/util/network/nonblock.h +0 -8
- package/inc/util/network/pair.h +0 -9
- package/inc/util/network/poller.h +0 -58
- package/inc/util/network/pollerimpl.h +0 -707
- package/inc/util/network/sock.h +0 -608
- package/inc/util/network/socket.h +0 -421
- package/inc/util/random/common_ops.h +0 -130
- package/inc/util/random/easy.h +0 -47
- package/inc/util/random/entropy.h +0 -21
- package/inc/util/random/fast.h +0 -101
- package/inc/util/random/init_atfork.h +0 -3
- package/inc/util/random/lcg_engine.h +0 -66
- package/inc/util/random/mersenne.h +0 -46
- package/inc/util/random/mersenne32.h +0 -50
- package/inc/util/random/mersenne64.h +0 -50
- package/inc/util/random/normal.h +0 -38
- package/inc/util/random/random.h +0 -30
- package/inc/util/random/shuffle.h +0 -39
- package/inc/util/str_stl.h +0 -266
- package/inc/util/stream/aligned.h +0 -99
- package/inc/util/stream/buffer.h +0 -119
- package/inc/util/stream/buffered.h +0 -225
- package/inc/util/stream/debug.h +0 -53
- package/inc/util/stream/direct_io.h +0 -43
- package/inc/util/stream/file.h +0 -108
- package/inc/util/stream/format.h +0 -444
- package/inc/util/stream/fwd.h +0 -100
- package/inc/util/stream/hex.h +0 -8
- package/inc/util/stream/holder.h +0 -44
- package/inc/util/stream/input.h +0 -273
- package/inc/util/stream/labeled.h +0 -19
- package/inc/util/stream/length.h +0 -100
- package/inc/util/stream/mem.h +0 -255
- package/inc/util/stream/multi.h +0 -32
- package/inc/util/stream/null.h +0 -61
- package/inc/util/stream/output.h +0 -304
- package/inc/util/stream/pipe.h +0 -112
- package/inc/util/stream/printf.h +0 -25
- package/inc/util/stream/str.h +0 -207
- package/inc/util/stream/tee.h +0 -28
- package/inc/util/stream/tempbuf.h +0 -21
- package/inc/util/stream/tokenizer.h +0 -214
- package/inc/util/stream/trace.h +0 -60
- package/inc/util/stream/walk.h +0 -35
- package/inc/util/stream/zerocopy.h +0 -91
- package/inc/util/stream/zerocopy_output.h +0 -57
- package/inc/util/stream/zlib.h +0 -173
- package/inc/util/string/ascii.h +0 -236
- package/inc/util/string/builder.h +0 -39
- package/inc/util/string/cast.h +0 -347
- package/inc/util/string/cstriter.h +0 -14
- package/inc/util/string/escape.h +0 -70
- package/inc/util/string/hex.h +0 -59
- package/inc/util/string/join.h +0 -194
- package/inc/util/string/printf.h +0 -13
- package/inc/util/string/reverse.h +0 -16
- package/inc/util/string/split.h +0 -1080
- package/inc/util/string/strip.h +0 -257
- package/inc/util/string/strspn.h +0 -65
- package/inc/util/string/subst.h +0 -56
- package/inc/util/string/type.h +0 -50
- package/inc/util/string/util.h +0 -195
- package/inc/util/string/vector.h +0 -132
- package/inc/util/system/align.h +0 -50
- package/inc/util/system/atexit.h +0 -22
- package/inc/util/system/atomic.h +0 -51
- package/inc/util/system/atomic_gcc.h +0 -90
- package/inc/util/system/atomic_ops.h +0 -189
- package/inc/util/system/atomic_win.h +0 -114
- package/inc/util/system/backtrace.h +0 -39
- package/inc/util/system/byteorder.h +0 -186
- package/inc/util/system/compat.h +0 -84
- package/inc/util/system/compiler.h +0 -620
- package/inc/util/system/condvar.h +0 -71
- package/inc/util/system/context.h +0 -181
- package/inc/util/system/context_aarch64.h +0 -8
- package/inc/util/system/context_i686.h +0 -9
- package/inc/util/system/context_x86.h +0 -12
- package/inc/util/system/context_x86_64.h +0 -7
- package/inc/util/system/cpu_id.h +0 -159
- package/inc/util/system/daemon.h +0 -28
- package/inc/util/system/datetime.h +0 -98
- package/inc/util/system/defaults.h +0 -149
- package/inc/util/system/demangle.h +0 -5
- package/inc/util/system/demangle_impl.h +0 -23
- package/inc/util/system/direct_io.h +0 -71
- package/inc/util/system/dynlib.h +0 -119
- package/inc/util/system/env.h +0 -32
- package/inc/util/system/error.h +0 -95
- package/inc/util/system/event.h +0 -122
- package/inc/util/system/execpath.h +0 -17
- package/inc/util/system/fasttime.h +0 -6
- package/inc/util/system/fhandle.h +0 -27
- package/inc/util/system/file.h +0 -210
- package/inc/util/system/file_lock.h +0 -34
- package/inc/util/system/filemap.h +0 -383
- package/inc/util/system/flock.h +0 -35
- package/inc/util/system/fs.h +0 -156
- package/inc/util/system/fs_win.h +0 -29
- package/inc/util/system/fstat.h +0 -46
- package/inc/util/system/getpid.h +0 -12
- package/inc/util/system/guard.h +0 -179
- package/inc/util/system/hi_lo.h +0 -139
- package/inc/util/system/hostname.h +0 -10
- package/inc/util/system/hp_timer.h +0 -36
- package/inc/util/system/info.h +0 -12
- package/inc/util/system/interrupt_signals.h +0 -22
- package/inc/util/system/madvise.h +0 -30
- package/inc/util/system/maxlen.h +0 -32
- package/inc/util/system/mem_info.h +0 -18
- package/inc/util/system/mincore.h +0 -38
- package/inc/util/system/mktemp.h +0 -11
- package/inc/util/system/mlock.h +0 -43
- package/inc/util/system/mutex.h +0 -67
- package/inc/util/system/nice.h +0 -3
- package/inc/util/system/pipe.h +0 -90
- package/inc/util/system/platform.h +0 -246
- package/inc/util/system/progname.h +0 -13
- package/inc/util/system/protect.h +0 -25
- package/inc/util/system/rusage.h +0 -26
- package/inc/util/system/rwlock.h +0 -78
- package/inc/util/system/sanitizers.h +0 -122
- package/inc/util/system/sem.h +0 -41
- package/inc/util/system/shellcommand.h +0 -472
- package/inc/util/system/shmat.h +0 -32
- package/inc/util/system/sigset.h +0 -78
- package/inc/util/system/spin_wait.h +0 -10
- package/inc/util/system/spinlock.h +0 -121
- package/inc/util/system/src_location.h +0 -25
- package/inc/util/system/src_root.h +0 -68
- package/inc/util/system/sys_alloc.h +0 -43
- package/inc/util/system/sysstat.h +0 -52
- package/inc/util/system/tempfile.h +0 -34
- package/inc/util/system/thread.h +0 -167
- package/inc/util/system/tls.h +0 -307
- package/inc/util/system/types.h +0 -119
- package/inc/util/system/unaligned_mem.h +0 -67
- package/inc/util/system/user.h +0 -5
- package/inc/util/system/utime.h +0 -6
- package/inc/util/system/valgrind.h +0 -48
- package/inc/util/system/winint.h +0 -43
- package/inc/util/system/yassert.h +0 -121
- package/inc/util/system/yield.h +0 -4
- package/inc/util/thread/factory.h +0 -65
- package/inc/util/thread/fwd.h +0 -30
- package/inc/util/thread/lfqueue.h +0 -406
- package/inc/util/thread/lfstack.h +0 -188
- package/inc/util/thread/pool.h +0 -388
- package/inc/util/thread/singleton.h +0 -42
- package/inc/util/ysafeptr.h +0 -427
- package/inc/util/ysaveload.h +0 -700
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <util/system/types.h>
|
|
4
|
-
#include <util/system/yassert.h>
|
|
5
|
-
|
|
6
|
-
inline constexpr bool IsW16SurrogateLead(wchar16 c) noexcept {
|
|
7
|
-
return 0xD800 <= c && c <= 0xDBFF;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
inline constexpr bool IsW16SurrogateTail(wchar16 c) noexcept {
|
|
11
|
-
return 0xDC00 <= c && c <= 0xDFFF;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
inline size_t W16SymbolSize(const wchar16* begin, const wchar16* end) {
|
|
15
|
-
Y_ASSERT(begin < end);
|
|
16
|
-
|
|
17
|
-
if ((begin + 1 != end) && IsW16SurrogateLead(*begin) && IsW16SurrogateTail(*(begin + 1))) {
|
|
18
|
-
return 2;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return 1;
|
|
22
|
-
}
|
package/inc/util/datetime/base.h
DELETED
|
@@ -1,669 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "systime.h"
|
|
4
|
-
|
|
5
|
-
#include <util/str_stl.h>
|
|
6
|
-
#include <util/system/platform.h>
|
|
7
|
-
#include <util/system/datetime.h>
|
|
8
|
-
#include <util/generic/string.h>
|
|
9
|
-
#include <util/generic/strbuf.h>
|
|
10
|
-
#include <util/generic/ylimits.h>
|
|
11
|
-
#include <util/generic/utility.h>
|
|
12
|
-
#include <util/generic/typetraits.h>
|
|
13
|
-
#include <util/generic/yexception.h>
|
|
14
|
-
|
|
15
|
-
#include <ctime>
|
|
16
|
-
#include <cstdio>
|
|
17
|
-
|
|
18
|
-
#include <time.h>
|
|
19
|
-
|
|
20
|
-
#ifdef _MSC_VER
|
|
21
|
-
#pragma warning(push)
|
|
22
|
-
#pragma warning(disable : 4244) // conversion from 'time_t' to 'long', possible loss of data
|
|
23
|
-
#endif // _MSC_VER
|
|
24
|
-
|
|
25
|
-
// Microseconds since epoch
|
|
26
|
-
class TInstant;
|
|
27
|
-
|
|
28
|
-
// Duration is microseconds. Could be used to store timeouts, for example.
|
|
29
|
-
class TDuration;
|
|
30
|
-
|
|
31
|
-
/// Current time
|
|
32
|
-
static inline TInstant Now() noexcept;
|
|
33
|
-
|
|
34
|
-
/// Use Now() method to obtain current time instead of *Seconds() unless you understand what are you doing.
|
|
35
|
-
|
|
36
|
-
class TDateTimeParseException: public yexception {
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const int DATE_BUF_LEN = 4 + 2 + 2 + 1; // [YYYYMMDD*]
|
|
40
|
-
|
|
41
|
-
constexpr long seconds(const struct tm& theTm) {
|
|
42
|
-
return 60 * (60 * theTm.tm_hour + theTm.tm_min) + theTm.tm_sec;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
void sprint_gm_date(char* buf, time_t when, long* sec = nullptr);
|
|
46
|
-
bool sscan_date(const char* date, struct tm& theTm);
|
|
47
|
-
|
|
48
|
-
const int DATE_8601_LEN = 21; // strlen("YYYY-MM-DDThh:mm:ssZ") = 20 + '\0'
|
|
49
|
-
|
|
50
|
-
size_t FormatDate8601(char* buf, size_t len, time_t when);
|
|
51
|
-
|
|
52
|
-
inline void sprint_date8601(char* buf, time_t when) {
|
|
53
|
-
buf[FormatDate8601(buf, 64, when)] = 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
bool ParseISO8601DateTimeDeprecated(const char* date, time_t& utcTime);
|
|
57
|
-
bool ParseISO8601DateTimeDeprecated(const char* date, size_t dateLen, time_t& utcTime);
|
|
58
|
-
bool ParseRFC822DateTimeDeprecated(const char* date, time_t& utcTime);
|
|
59
|
-
bool ParseRFC822DateTimeDeprecated(const char* date, size_t dateLen, time_t& utcTime);
|
|
60
|
-
bool ParseHTTPDateTimeDeprecated(const char* date, time_t& utcTime);
|
|
61
|
-
bool ParseHTTPDateTimeDeprecated(const char* date, size_t dateLen, time_t& utcTime);
|
|
62
|
-
bool ParseX509ValidityDateTimeDeprecated(const char* date, time_t& utcTime);
|
|
63
|
-
bool ParseX509ValidityDateTimeDeprecated(const char* date, size_t dateLen, time_t& utcTime);
|
|
64
|
-
|
|
65
|
-
bool ParseISO8601DateTime(const char* date, time_t& utcTime);
|
|
66
|
-
bool ParseISO8601DateTime(const char* date, size_t dateLen, time_t& utcTime);
|
|
67
|
-
bool ParseRFC822DateTime(const char* date, time_t& utcTime);
|
|
68
|
-
bool ParseRFC822DateTime(const char* date, size_t dateLen, time_t& utcTime);
|
|
69
|
-
bool ParseHTTPDateTime(const char* date, time_t& utcTime);
|
|
70
|
-
bool ParseHTTPDateTime(const char* date, size_t dateLen, time_t& utcTime);
|
|
71
|
-
bool ParseX509ValidityDateTime(const char* date, time_t& utcTime);
|
|
72
|
-
bool ParseX509ValidityDateTime(const char* date, size_t dateLen, time_t& utcTime);
|
|
73
|
-
|
|
74
|
-
constexpr long TVdiff(timeval r1, timeval r2) {
|
|
75
|
-
return (1000000 * (r2.tv_sec - r1.tv_sec) + (r2.tv_usec - r1.tv_usec));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
TString Strftime(const char* format, const struct tm* tm);
|
|
79
|
-
|
|
80
|
-
// Use functions below instead of sprint_date (check IGNIETFERRO-892 for details)
|
|
81
|
-
void DateToString(char* buf, const struct tm& theTm);
|
|
82
|
-
void DateToString(char* buf, time_t when, long* sec = nullptr);
|
|
83
|
-
TString DateToString(const struct tm& theTm);
|
|
84
|
-
TString DateToString(time_t when, long* sec = nullptr);
|
|
85
|
-
// Year in format "YYYY", throws an exception if year not in range [0, 9999]
|
|
86
|
-
TString YearToString(const struct tm& theTm);
|
|
87
|
-
TString YearToString(time_t when);
|
|
88
|
-
|
|
89
|
-
template <class S>
|
|
90
|
-
class TTimeBase {
|
|
91
|
-
public:
|
|
92
|
-
using TValue = ui64;
|
|
93
|
-
|
|
94
|
-
protected:
|
|
95
|
-
constexpr TTimeBase(const TValue& value) noexcept
|
|
96
|
-
: Value_(value)
|
|
97
|
-
{
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public:
|
|
101
|
-
constexpr TTimeBase() noexcept
|
|
102
|
-
: Value_(0)
|
|
103
|
-
{
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
constexpr TTimeBase(const struct timeval& tv) noexcept
|
|
107
|
-
: Value_(tv.tv_sec * (ui64)1000000 + tv.tv_usec)
|
|
108
|
-
{
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
constexpr TValue GetValue() const noexcept {
|
|
112
|
-
return Value_;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
constexpr double SecondsFloat() const noexcept {
|
|
116
|
-
return Value_ * (1 / 1000000.0);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
constexpr double MillisecondsFloat() const noexcept {
|
|
120
|
-
return Value_ * (1 / 1000.0);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
constexpr TValue MicroSeconds() const noexcept {
|
|
124
|
-
return Value_;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
constexpr TValue MilliSeconds() const noexcept {
|
|
128
|
-
return MicroSeconds() / 1000;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
constexpr TValue Seconds() const noexcept {
|
|
132
|
-
return MilliSeconds() / 1000;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
constexpr TValue Minutes() const noexcept {
|
|
136
|
-
return Seconds() / 60;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
constexpr TValue Hours() const noexcept {
|
|
140
|
-
return Minutes() / 60;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
constexpr TValue Days() const noexcept {
|
|
144
|
-
return Hours() / 24;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
constexpr TValue NanoSeconds() const noexcept {
|
|
148
|
-
return MicroSeconds() >= (Max<TValue>() / (TValue)1000) ? Max<TValue>() : MicroSeconds() * (TValue)1000;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
constexpr ui32 MicroSecondsOfSecond() const noexcept {
|
|
152
|
-
return MicroSeconds() % (TValue)1000000;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
constexpr ui32 MilliSecondsOfSecond() const noexcept {
|
|
156
|
-
return MicroSecondsOfSecond() / (TValue)1000;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
constexpr ui32 NanoSecondsOfSecond() const noexcept {
|
|
160
|
-
return MicroSecondsOfSecond() * (TValue)1000;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
constexpr explicit operator bool() const noexcept {
|
|
164
|
-
return Value_;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
protected:
|
|
168
|
-
TValue Value_; // microseconds count
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
namespace NDateTimeHelpers {
|
|
172
|
-
template <typename T>
|
|
173
|
-
struct TPrecisionHelper {
|
|
174
|
-
using THighPrecision = ui64;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
template <>
|
|
178
|
-
struct TPrecisionHelper<float> {
|
|
179
|
-
using THighPrecision = double;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
template <>
|
|
183
|
-
struct TPrecisionHelper<double> {
|
|
184
|
-
using THighPrecision = double;
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
class TDuration: public TTimeBase<TDuration> {
|
|
189
|
-
using TBase = TTimeBase<TDuration>;
|
|
190
|
-
|
|
191
|
-
private:
|
|
192
|
-
/**
|
|
193
|
-
* private construct from microseconds
|
|
194
|
-
*/
|
|
195
|
-
constexpr explicit TDuration(TValue value) noexcept
|
|
196
|
-
: TBase(value)
|
|
197
|
-
{
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
public:
|
|
201
|
-
constexpr TDuration() noexcept {
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
constexpr TDuration(const struct timeval& tv) noexcept
|
|
205
|
-
: TBase(tv)
|
|
206
|
-
{
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
static constexpr TDuration FromValue(TValue value) noexcept {
|
|
210
|
-
return TDuration(value);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
static constexpr TDuration MicroSeconds(ui64 us) noexcept {
|
|
214
|
-
return TDuration(us);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/* noexcept(false) as conversion from T might throw, for example FromString("abc") */
|
|
218
|
-
template <typename T>
|
|
219
|
-
static constexpr TDuration MilliSeconds(T ms) noexcept(false) {
|
|
220
|
-
return MicroSeconds((ui64)(typename NDateTimeHelpers::TPrecisionHelper<T>::THighPrecision(ms) * 1000));
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
using TBase::Days;
|
|
224
|
-
using TBase::Hours;
|
|
225
|
-
using TBase::MicroSeconds;
|
|
226
|
-
using TBase::MilliSeconds;
|
|
227
|
-
using TBase::Minutes;
|
|
228
|
-
using TBase::Seconds;
|
|
229
|
-
|
|
230
|
-
/// DeadLineFromTimeOut
|
|
231
|
-
inline TInstant ToDeadLine() const;
|
|
232
|
-
constexpr TInstant ToDeadLine(TInstant now) const;
|
|
233
|
-
|
|
234
|
-
static constexpr TDuration Max() noexcept {
|
|
235
|
-
return TDuration(::Max<TValue>());
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
static constexpr TDuration Zero() noexcept {
|
|
239
|
-
return TDuration();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/* noexcept(false) as conversion from T might throw, for example FromString("abc") */
|
|
243
|
-
template <typename T>
|
|
244
|
-
static constexpr TDuration Seconds(T s) noexcept(false) {
|
|
245
|
-
return MilliSeconds(typename NDateTimeHelpers::TPrecisionHelper<T>::THighPrecision(s) * 1000);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
static constexpr TDuration Minutes(ui64 m) noexcept {
|
|
249
|
-
return Seconds(m * 60);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
static constexpr TDuration Hours(ui64 h) noexcept {
|
|
253
|
-
return Minutes(h * 60);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
static constexpr TDuration Days(ui64 d) noexcept {
|
|
257
|
-
return Hours(d * 24);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/// parses strings like 10s, 15ms, 15.05s, 20us, or just 25 (s). See parser_ut.cpp for details
|
|
261
|
-
static TDuration Parse(const TStringBuf input);
|
|
262
|
-
|
|
263
|
-
static bool TryParse(const TStringBuf input, TDuration& result);
|
|
264
|
-
|
|
265
|
-
// note global Out method is defined for TDuration, so it could be written to IOutputStream as text
|
|
266
|
-
|
|
267
|
-
template <class T>
|
|
268
|
-
inline TDuration& operator+=(const T& t) noexcept {
|
|
269
|
-
return (*this = (*this + t));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
template <class T>
|
|
273
|
-
inline TDuration& operator-=(const T& t) noexcept {
|
|
274
|
-
return (*this = (*this - t));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
template <class T>
|
|
278
|
-
inline TDuration& operator*=(const T& t) noexcept {
|
|
279
|
-
return (*this = (*this * t));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
template <class T>
|
|
283
|
-
inline TDuration& operator/=(const T& t) noexcept {
|
|
284
|
-
return (*this = (*this / t));
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
TString ToString() const;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
Y_DECLARE_PODTYPE(TDuration);
|
|
291
|
-
|
|
292
|
-
template <>
|
|
293
|
-
struct THash<TDuration> {
|
|
294
|
-
size_t operator()(const TDuration& key) const {
|
|
295
|
-
return THash<TDuration::TValue>()(key.GetValue());
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
/// TInstant and TDuration are guaranteed to have same precision
|
|
300
|
-
class TInstant: public TTimeBase<TInstant> {
|
|
301
|
-
using TBase = TTimeBase<TInstant>;
|
|
302
|
-
|
|
303
|
-
private:
|
|
304
|
-
/**
|
|
305
|
-
* private construct from microseconds since epoch
|
|
306
|
-
*/
|
|
307
|
-
constexpr explicit TInstant(TValue value) noexcept
|
|
308
|
-
: TBase(value)
|
|
309
|
-
{
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
public:
|
|
313
|
-
constexpr TInstant() noexcept {
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
constexpr TInstant(const struct timeval& tv) noexcept
|
|
317
|
-
: TBase(tv)
|
|
318
|
-
{
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
static constexpr TInstant FromValue(TValue value) noexcept {
|
|
322
|
-
return TInstant(value);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
static inline TInstant Now() {
|
|
326
|
-
return TInstant::MicroSeconds(::MicroSeconds());
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
using TBase::Days;
|
|
330
|
-
using TBase::Hours;
|
|
331
|
-
using TBase::MicroSeconds;
|
|
332
|
-
using TBase::MilliSeconds;
|
|
333
|
-
using TBase::Minutes;
|
|
334
|
-
using TBase::Seconds;
|
|
335
|
-
|
|
336
|
-
static constexpr TInstant Max() noexcept {
|
|
337
|
-
return TInstant(::Max<TValue>());
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
static constexpr TInstant Zero() noexcept {
|
|
341
|
-
return TInstant();
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/// us since epoch
|
|
345
|
-
static constexpr TInstant MicroSeconds(ui64 us) noexcept {
|
|
346
|
-
return TInstant(us);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/// ms since epoch
|
|
350
|
-
static constexpr TInstant MilliSeconds(ui64 ms) noexcept {
|
|
351
|
-
return MicroSeconds(ms * 1000);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/// seconds since epoch
|
|
355
|
-
static constexpr TInstant Seconds(ui64 s) noexcept {
|
|
356
|
-
return MilliSeconds(s * 1000);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/// minutes since epoch
|
|
360
|
-
static constexpr TInstant Minutes(ui64 m) noexcept {
|
|
361
|
-
return Seconds(m * 60);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/// hours since epoch
|
|
365
|
-
static constexpr TInstant Hours(ui64 h) noexcept {
|
|
366
|
-
return Minutes(h * 60);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/// days since epoch
|
|
370
|
-
static constexpr TInstant Days(ui64 d) noexcept {
|
|
371
|
-
return Hours(d * 24);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
constexpr time_t TimeT() const noexcept {
|
|
375
|
-
return (time_t)Seconds();
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
inline struct timeval TimeVal() const noexcept {
|
|
379
|
-
struct timeval tv;
|
|
380
|
-
::Zero(tv);
|
|
381
|
-
tv.tv_sec = TimeT();
|
|
382
|
-
tv.tv_usec = MicroSecondsOfSecond();
|
|
383
|
-
return tv;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
inline struct tm* LocalTime(struct tm* tm) const noexcept {
|
|
387
|
-
time_t clock = Seconds();
|
|
388
|
-
return localtime_r(&clock, tm);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
inline struct tm* GmTime(struct tm* tm) const noexcept {
|
|
392
|
-
time_t clock = Seconds();
|
|
393
|
-
return GmTimeR(&clock, tm);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Formats the instant using the UTC time zone, with microsecond precision.
|
|
398
|
-
*
|
|
399
|
-
* @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27.991669Z'.
|
|
400
|
-
* @note Global Out method is defined to TInstant, so it can be written as text to IOutputStream.
|
|
401
|
-
*/
|
|
402
|
-
TString ToString() const;
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Formats the instant using the UTC time zone.
|
|
406
|
-
*
|
|
407
|
-
* @returns An RFC822 formatted string, e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'.
|
|
408
|
-
*/
|
|
409
|
-
TString ToRfc822String() const;
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Formats the instant using the UTC time zone, with second precision.
|
|
413
|
-
*
|
|
414
|
-
* @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27Z'.
|
|
415
|
-
*/
|
|
416
|
-
TString ToStringUpToSeconds() const;
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Formats the instant using the system time zone, with microsecond precision.
|
|
420
|
-
*
|
|
421
|
-
* @returns An ISO 8601 / RFC 3339 formatted string,
|
|
422
|
-
* e.g. '2015-11-22T04:30:27.991669+05:00'.
|
|
423
|
-
*/
|
|
424
|
-
TString ToIsoStringLocal() const;
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Formats the instant using the system time zone, with microsecond precision.
|
|
428
|
-
*
|
|
429
|
-
* @returns A semi-ISO 8601 formatted string with timezone without colon,
|
|
430
|
-
* e.g. '2015-11-22T04:30:27.991669+0500'.
|
|
431
|
-
*/
|
|
432
|
-
TString ToStringLocal() const;
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Formats the instant using the system time zone.
|
|
436
|
-
*
|
|
437
|
-
* @returns An RFC822 formatted string, e.g. 'Sun, 06 Nov 1994 08:49:37 MSK'.
|
|
438
|
-
*/
|
|
439
|
-
TString ToRfc822StringLocal() const;
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Formats the instant using the system time zone, with second precision.
|
|
443
|
-
*
|
|
444
|
-
* @returns An ISO 8601 / RFC 3339 formatted string,
|
|
445
|
-
* e.g. '2015-11-22T04:30:27+05:00'.
|
|
446
|
-
*/
|
|
447
|
-
TString ToIsoStringLocalUpToSeconds() const;
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Formats the instant using the system time zone, with second precision.
|
|
451
|
-
*
|
|
452
|
-
* @returns A semi-ISO 8601 formatted string with timezone without colon,
|
|
453
|
-
* e.g. '2015-11-22T04:30:27+0500'.
|
|
454
|
-
*/
|
|
455
|
-
TString ToStringLocalUpToSeconds() const;
|
|
456
|
-
|
|
457
|
-
TString FormatLocalTime(const char* format) const noexcept;
|
|
458
|
-
TString FormatGmTime(const char* format) const noexcept;
|
|
459
|
-
|
|
460
|
-
/// See #TryParseIso8601.
|
|
461
|
-
static TInstant ParseIso8601(TStringBuf);
|
|
462
|
-
/// See #TryParseRfc822.
|
|
463
|
-
static TInstant ParseRfc822( TStringBuf);
|
|
464
|
-
/// See #TryParseHttp.
|
|
465
|
-
static TInstant ParseHttp(TStringBuf);
|
|
466
|
-
/// See #TryParseX509.
|
|
467
|
-
static TInstant ParseX509Validity(TStringBuf);
|
|
468
|
-
|
|
469
|
-
/// ISO 8601 Representation of Dates and Times
|
|
470
|
-
///
|
|
471
|
-
/// @link https://www.iso.org/standard/40874.html Description of format.
|
|
472
|
-
static bool TryParseIso8601(TStringBuf input, TInstant& instant);
|
|
473
|
-
|
|
474
|
-
/// RFC 822 Date and Time specification
|
|
475
|
-
///
|
|
476
|
-
/// @link https://tools.ietf.org/html/rfc822#section-5 Description of format.
|
|
477
|
-
static bool TryParseRfc822(TStringBuf input, TInstant& instant);
|
|
478
|
-
|
|
479
|
-
/// RFC 2616 3.3.1 Full Date
|
|
480
|
-
///
|
|
481
|
-
/// @link https://tools.ietf.org/html/rfc2616#section-3.3.1 Description of format.
|
|
482
|
-
static bool TryParseHttp(TStringBuf input, TInstant& instant);
|
|
483
|
-
|
|
484
|
-
/// X.509 certificate validity time (see rfc5280 4.1.2.5.*)
|
|
485
|
-
///
|
|
486
|
-
/// @link https://tools.ietf.org/html/rfc5280#section-4.1.2.5 Description of format.
|
|
487
|
-
static bool TryParseX509(TStringBuf input, TInstant& instant);
|
|
488
|
-
|
|
489
|
-
static TInstant ParseIso8601Deprecated(TStringBuf);
|
|
490
|
-
static TInstant ParseRfc822Deprecated(TStringBuf);
|
|
491
|
-
static TInstant ParseHttpDeprecated(TStringBuf);
|
|
492
|
-
static TInstant ParseX509ValidityDeprecated(TStringBuf);
|
|
493
|
-
|
|
494
|
-
static bool TryParseIso8601Deprecated(TStringBuf input, TInstant& instant);
|
|
495
|
-
static bool TryParseRfc822Deprecated(TStringBuf input, TInstant& instant);
|
|
496
|
-
static bool TryParseHttpDeprecated(TStringBuf input, TInstant& instant);
|
|
497
|
-
static bool TryParseX509Deprecated(TStringBuf input, TInstant& instant);
|
|
498
|
-
|
|
499
|
-
template <class T>
|
|
500
|
-
inline TInstant& operator+=(const T& t) noexcept {
|
|
501
|
-
return (*this = (*this + t));
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
template <class T>
|
|
505
|
-
inline TInstant& operator-=(const T& t) noexcept {
|
|
506
|
-
return (*this = (*this - t));
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
Y_DECLARE_PODTYPE(TInstant);
|
|
511
|
-
|
|
512
|
-
template <>
|
|
513
|
-
struct THash<TInstant> {
|
|
514
|
-
size_t operator()(const TInstant& key) const {
|
|
515
|
-
return THash<TInstant::TValue>()(key.GetValue());
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
namespace NPrivate {
|
|
520
|
-
template <bool PrintUpToSeconds, bool iso>
|
|
521
|
-
struct TPrintableLocalTime {
|
|
522
|
-
TInstant MomentToPrint;
|
|
523
|
-
|
|
524
|
-
constexpr explicit TPrintableLocalTime(TInstant momentToPrint)
|
|
525
|
-
: MomentToPrint(momentToPrint)
|
|
526
|
-
{
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
/** @name Helpers for printing local times to `IOutputStream`s.
|
|
532
|
-
* The FormatLocal* functions create an opaque object that, when written to
|
|
533
|
-
* a `IOutputStream`, outputs this instant as an ISO 8601 formatted string
|
|
534
|
-
* using the system time zone.
|
|
535
|
-
*
|
|
536
|
-
* @note The only reason behind this set of functions is to avoid excessive
|
|
537
|
-
* allocations when you directly print the local time to a stream.
|
|
538
|
-
*
|
|
539
|
-
* If you need something beyond just printing the value or your code
|
|
540
|
-
* is not performance-critical, feel free to use the corresponding
|
|
541
|
-
* TInstant::ToString*() functions.
|
|
542
|
-
*/
|
|
543
|
-
///@{
|
|
544
|
-
/// @see TInstant::ToIsoStringLocal()
|
|
545
|
-
::NPrivate::TPrintableLocalTime<false, true> FormatIsoLocal(TInstant instant);
|
|
546
|
-
/// @see TInstant::ToStringLocal()
|
|
547
|
-
::NPrivate::TPrintableLocalTime<false, false> FormatLocal(TInstant instant);
|
|
548
|
-
/// @see TInstant::ToIsoStringLocalUpToSeconds()
|
|
549
|
-
::NPrivate::TPrintableLocalTime<true, true> FormatIsoLocalUpToSeconds(TInstant instant);
|
|
550
|
-
/// @see TInstant::ToStringLocalUpToSeconds()
|
|
551
|
-
::NPrivate::TPrintableLocalTime<true, false> FormatLocalUpToSeconds(TInstant instant);
|
|
552
|
-
///@}
|
|
553
|
-
|
|
554
|
-
template <class S>
|
|
555
|
-
static constexpr bool operator<(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept {
|
|
556
|
-
return l.GetValue() < r.GetValue();
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
template <class S>
|
|
560
|
-
static constexpr bool operator<=(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept {
|
|
561
|
-
return l.GetValue() <= r.GetValue();
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
template <class S>
|
|
565
|
-
static constexpr bool operator==(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept {
|
|
566
|
-
return l.GetValue() == r.GetValue();
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
template <class S>
|
|
570
|
-
static constexpr bool operator!=(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept {
|
|
571
|
-
return l.GetValue() != r.GetValue();
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
template <class S>
|
|
575
|
-
static constexpr bool operator>(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept {
|
|
576
|
-
return l.GetValue() > r.GetValue();
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
template <class S>
|
|
580
|
-
static constexpr bool operator>=(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept {
|
|
581
|
-
return l.GetValue() >= r.GetValue();
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
namespace NDateTimeHelpers {
|
|
585
|
-
template <typename T>
|
|
586
|
-
static constexpr T SumWithSaturation(T a, T b) {
|
|
587
|
-
static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed");
|
|
588
|
-
|
|
589
|
-
return Max<T>() - a < b ? Max<T>() : a + b;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
template <typename T>
|
|
593
|
-
static constexpr T DiffWithSaturation(T a, T b) {
|
|
594
|
-
static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed");
|
|
595
|
-
|
|
596
|
-
return a < b ? 0 : a - b;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
constexpr TDuration operator-(const TInstant& l, const TInstant& r) noexcept {
|
|
601
|
-
return TDuration::FromValue(::NDateTimeHelpers::DiffWithSaturation(l.GetValue(), r.GetValue()));
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
constexpr TInstant operator+(const TInstant& i, const TDuration& d) noexcept {
|
|
605
|
-
return TInstant::FromValue(::NDateTimeHelpers::SumWithSaturation(i.GetValue(), d.GetValue()));
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
constexpr TInstant operator-(const TInstant& i, const TDuration& d) noexcept {
|
|
609
|
-
return TInstant::FromValue(::NDateTimeHelpers::DiffWithSaturation(i.GetValue(), d.GetValue()));
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
constexpr TDuration operator-(const TDuration& l, const TDuration& r) noexcept {
|
|
613
|
-
return TDuration::FromValue(::NDateTimeHelpers::DiffWithSaturation(l.GetValue(), r.GetValue()));
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
constexpr TDuration operator+(const TDuration& l, const TDuration& r) noexcept {
|
|
617
|
-
return TDuration::FromValue(::NDateTimeHelpers::SumWithSaturation(l.GetValue(), r.GetValue()));
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
template <class T>
|
|
621
|
-
inline TDuration operator*(TDuration d, T t) noexcept {
|
|
622
|
-
Y_ASSERT(t >= T());
|
|
623
|
-
Y_ASSERT(t == T() || Max<TDuration::TValue>() / t >= d.GetValue());
|
|
624
|
-
return TDuration::FromValue(d.GetValue() * t);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
template <>
|
|
628
|
-
inline TDuration operator*(TDuration d, double t) noexcept {
|
|
629
|
-
Y_ASSERT(t >= 0 && MaxFloor<TDuration::TValue>() >= d.GetValue() * t);
|
|
630
|
-
return TDuration::FromValue(d.GetValue() * t);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
template <>
|
|
634
|
-
inline TDuration operator*(TDuration d, float t) noexcept {
|
|
635
|
-
return d * static_cast<double>(t);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
template <class T>
|
|
639
|
-
inline TDuration operator*(T t, TDuration d) noexcept {
|
|
640
|
-
return d * t;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
template <class T, std::enable_if_t<!std::is_same<TDuration, T>::value, int> = 0>
|
|
644
|
-
constexpr TDuration operator/(const TDuration& d, const T& t) noexcept {
|
|
645
|
-
return TDuration::FromValue(d.GetValue() / t);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
constexpr double operator/(const TDuration& x, const TDuration& y) noexcept {
|
|
649
|
-
return static_cast<double>(x.GetValue()) / static_cast<double>(y.GetValue());
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
inline TInstant TDuration::ToDeadLine() const {
|
|
653
|
-
return ToDeadLine(TInstant::Now());
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
constexpr TInstant TDuration::ToDeadLine(TInstant now) const {
|
|
657
|
-
return now + *this;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
void Sleep(TDuration duration);
|
|
661
|
-
void SleepUntil(TInstant instant);
|
|
662
|
-
|
|
663
|
-
static inline TInstant Now() noexcept {
|
|
664
|
-
return TInstant::Now();
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
#ifdef _MSC_VER
|
|
668
|
-
#pragma warning(pop)
|
|
669
|
-
#endif // _MSC_VER
|