Coverage Report

Created: 2025-09-16 21:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/util/time_lut.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with 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,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
19
#pragma once
20
21
#include <atomic>
22
#include <cstdint>
23
24
namespace doris {
25
26
constexpr uint16_t LUT_START_YEAR = 1950;
27
constexpr uint16_t LUT_END_YEAR = 2030;
28
29
constexpr uint8_t NUM_MONTHS = 12;
30
constexpr uint8_t NUM_DAYS = 31;
31
32
uint32_t year_week(uint16_t yy, uint8_t month, uint8_t day);
33
34
uint8_t calc_weekday(uint64_t day_nr, bool is_sunday_first_day);
35
36
107k
inline bool is_leap(uint32_t year) {
37
107k
    return ((year % 4) == 0) && ((year % 100 != 0) || ((year % 400) == 0 && year));
38
107k
}
39
40
uint16_t calc_days_in_year(uint32_t year);
41
42
uint8_t calc_week(uint16_t yy, uint8_t month, uint8_t day, bool monday_first, bool week_year,
43
                  bool first_weekday, uint16_t* to_year);
44
45
class TimeLUTImpl {
46
public:
47
    int8_t week_of_year_table[LUT_END_YEAR - LUT_START_YEAR][NUM_MONTHS][NUM_DAYS];
48
49
    uint32_t year_week_table[LUT_END_YEAR - LUT_START_YEAR][NUM_MONTHS][NUM_DAYS];
50
51
    int8_t week_table[LUT_END_YEAR - LUT_START_YEAR][NUM_MONTHS][NUM_DAYS];
52
53
private:
54
    friend class TimeLUT;
55
56
    TimeLUTImpl();
57
    void init_time_lut();
58
};
59
60
class TimeLUT {
61
public:
62
10
    static const TimeLUTImpl* GetImplement() {
63
10
        static TimeLUT time_lut;
64
10
        return time_lut._impl.load();
65
10
    }
66
67
protected:
68
1
    TimeLUT() { _impl.store(new TimeLUTImpl()); }
69
70
private:
71
    std::atomic<const TimeLUTImpl*> _impl;
72
};
73
74
} // namespace doris