• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

b1f6c1c4 / ProfessionalAccounting / 307

25 Sep 2023 04:48AM UTC coverage: 56.975% (-1.3%) from 58.254%
307

push

appveyor

b1f6c1c4
raw subtotal more controllable

5947 of 10438 relevant lines covered (56.97%)

125.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.61
/AccountingServer.BLL/Parsing/QueryParser.Proxy.Range.cs
1
/* Copyright (C) 2020-2023 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System;
20
using AccountingServer.Entities;
21

22
namespace AccountingServer.BLL.Parsing;
23

24
internal partial class QueryParser
25
{
26
    public partial class RangeDayContext : IClientDependable, IDateRange
27
    {
28
        public Client Client { private get; set; }
29

30
        /// <inheritdoc />
31
        public DateFilter Range
32
        {
33
            get
34
            {
56✔
35
                var dt = AsDate();
56✔
36
                return new(dt, dt);
56✔
37
            }
56✔
38
        }
39

40
        public DateTime? AsDate() =>
41
            RangeDeltaDay() != null
96✔
42
                ? Client.Today.AddDays(1 - RangeDeltaDay().GetText().Length)
43
                : DateTimeParser.ParseExact(RangeADay().GetText(), "yyyyMMdd");
44
    }
45

46
    public partial class RangeWeekContext : IClientDependable, IDateRange
47
    {
48
        public Client Client { private get; set; }
49

50
        /// <inheritdoc />
51
        public DateFilter Range
52
        {
53
            get
54
            {
5✔
55
                var delta = 1 - RangeDeltaWeek().GetText().Length;
5✔
56
                var dt = Client.Today;
5✔
57
                dt = dt.AddDays(dt.DayOfWeek == DayOfWeek.Sunday ? -6 : 1 - (int)dt.DayOfWeek);
5✔
58
                dt = dt.AddDays(delta * 7);
5✔
59
                return new(dt, dt.AddDays(6));
5✔
60
            }
5✔
61
        }
62
    }
63

64
    public partial class RangeMonthContext : IClientDependable, IDateRange
65
    {
66
        public Client Client { private get; set; }
67

68
        /// <inheritdoc />
69
        public DateFilter Range
70
        {
71
            get
72
            {
25✔
73
                DateTime dt;
74
                if (RangeDeltaMonth() != null)
25✔
75
                {
1✔
76
                    var delta = int.Parse(RangeDeltaMonth().GetText().TrimStart('-'));
1✔
77
                    dt = new(
1✔
78
                        Client.Today.Year,
79
                        Client.Today.Month,
80
                        1,
81
                        0,
82
                        0,
83
                        0,
84
                        DateTimeKind.Utc);
85
                    dt = dt.AddMonths(-delta);
1✔
86
                }
1✔
87
                else
88
                    dt = DateTimeParser.ParseExact($"{RangeAMonth().GetText()}01", "yyyyMMdd");
24✔
89

90
                return new(dt, dt.AddMonths(1).AddDays(-1));
25✔
91
            }
25✔
92
        }
93
    }
94

95
    public partial class RangeQuarterContext : IClientDependable, IDateRange
96
    {
97
        public Client Client { private get; set; }
98

99
        /// <inheritdoc />
100
        public DateFilter Range
101
        {
102
            get
103
            {
12✔
104
                DateTime dt;
105
                if (RangeDeltaQuarter() != null)
12✔
106
                {
×
107
                    var delta = int.Parse(RangeDeltaQuarter().GetText().TrimStart('Q'));
×
108
                    var q = (Client.Today.Month + 2) / 3 + 1;
×
109
                    if (delta > 0)
×
110
                        q = delta;
×
111
                    else
112
                        q -= delta;
×
113
                    dt = new(Client.Today.Year, 3 * q - 2, 1, 0, 0, 0, DateTimeKind.Utc);
×
114
                }
×
115
                else
116
                {
12✔
117
                    var year = int.Parse(RangeAQuarter().GetText()[0..4]);
12✔
118
                    var q = int.Parse(RangeAQuarter().GetText()[5..]);
12✔
119
                    dt = new(year, 3 * q - 2, 1, 0, 0, 0, DateTimeKind.Utc);
12✔
120
                }
12✔
121

122
                return new(dt, dt.AddMonths(3).AddDays(-1));
12✔
123
            }
12✔
124
        }
125
    }
126

127
    public partial class RangeYearContext : IDateRange
128
    {
129
        /// <inheritdoc />
130
        public DateFilter Range
131
        {
132
            get
133
            {
41✔
134
                var year = int.Parse(RangeAYear().GetText());
41✔
135
                return new(
41✔
136
                    new(year, 1, 1, 0, 0, 0, DateTimeKind.Utc),
137
                    new(year, 12, 31, 0, 0, 0, DateTimeKind.Utc));
138
            }
41✔
139
        }
140
    }
141

142
    public partial class RangeCertainPointContext : IClientDependable, IDateRange
143
    {
144
        public Client Client { private get; set; }
145

146
        /// <inheritdoc />
147
        public DateFilter Range
148
        {
149
            get
150
            {
139✔
151
                if (rangeDay() != null)
139✔
152
                    return rangeDay().Assign(Client).Range;
56✔
153
                if (rangeWeek() != null)
83✔
154
                    return rangeWeek().Assign(Client).Range;
5✔
155
                if (rangeMonth() != null)
78✔
156
                    return rangeMonth().Assign(Client).Range;
25✔
157
                if (rangeQuarter() != null)
53✔
158
                    return rangeQuarter().Assign(Client).Range;
12✔
159
                if (rangeYear() != null)
41✔
160
                    return rangeYear().Range;
41✔
161

162
                throw new MemberAccessException("表达式错误");
×
163
            }
139✔
164
        }
165
    }
166

167
    public partial class RangePointContext : IDateRange
168
    {
169
        /// <inheritdoc />
170
        public DateFilter Range
171
        {
172
            get
173
            {
×
174
                if (AllDate() != null)
×
175
                    return DateFilter.Unconstrained;
×
176
                if (RangeNull() != null)
×
177
                    return DateFilter.TheNullOnly;
×
178

179
                return rangeCertainPoint().Range;
×
180
            }
×
181
        }
182
    }
183

184
    public partial class UniqueTimeCoreContext : IClientDependable
185
    {
186
        public Client Client { private get; set; }
187

188
        public DateTime? AsDate()
189
        {
56✔
190
            if (RangeNull() != null)
56✔
191
                return null;
16✔
192

193
            return rangeDay().Assign(Client).AsDate();
40✔
194
        }
56✔
195
    }
196

197
    public partial class RangeCoreContext : IClientDependable, IDateRange
198
    {
199
        public Client Client { private get; set; }
200

201
        /// <inheritdoc />
202
        public DateFilter Range
203
        {
204
            get
205
            {
141✔
206
                if (RangeNull() != null)
141✔
207
                    return DateFilter.TheNullOnly;
25✔
208
                if (RangeAllNotNull() != null)
116✔
209
                    return DateFilter.TheNotNull;
9✔
210
                if (Certain != null)
107✔
211
                    return Certain.Assign(Client).Range;
25✔
212

213
                DateTime? s = null, e = null;
82✔
214
                if (Begin != null)
82✔
215
                    s = Begin.Assign(Client).Range.StartDate;
52✔
216
                if (End != null)
82✔
217
                    e = End.Assign(Client).Range.EndDate;
62✔
218

219
                var f = new DateFilter(s, e);
82✔
220
                if (Tilde().GetText() == "~~")
82✔
221
                    f.Nullable ^= true;
39✔
222
                return f;
82✔
223
            }
141✔
224
        }
225
    }
226

227
    public partial class UniqueTimeContext : IClientDependable
228
    {
229
        public Client Client { private get; set; }
230

231
        public DateTime? AsDate()
232
            => Core.Assign(Client).AsDate();
56✔
233
    }
234

235
    public partial class RangeContext : IClientDependable, IDateRange
236
    {
237
        public Client Client { private get; set; }
238

239
        /// <inheritdoc />
240
        public DateFilter Range
241
            => rangeCore().Assign(Client)?.Range ?? DateFilter.Unconstrained;
140✔
242
    }
243
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc