Debian Codegraph @

Source/Reasoner/Kernel/Process/CDatatypeDateTimeValueSpaceMap.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CDatatypeDateTimeValueSpaceMap.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33 CDatatypeDateTimeValueSpaceMap::CDatatypeDateTimeValueSpaceMap(CProcessContext* processContext) : CDatatypeCompareValueSpaceMap(processContext) {
34 }
35
36
37 CDatatypeDateTimeValueSpaceMap* CDatatypeDateTimeValueSpaceMap::initDatatypeDateTimeValueSpaceMap(CDatatypeValueSpaceDateTimeType* valueSpaceType) {
38 CPROCESSMAP<CDatatypeCompareValueSpaceMapArranger,CDatatypeCompareValueSpaceMapData>::clear();
39 mAbsoluteMinimumExclusionValue = nullptr;
40 mAbsoluteMaximumExclusionValue = nullptr;
41
42 excludeMinimum(valueSpaceType->getMinimumDataLiteralDateTimeValue(),true,nullptr);
43 excludeMaximum(valueSpaceType->getMaximumDataLiteralDateTimeValue(),true,nullptr);
44 return this;
45 }
46
47
48 bool CDatatypeDateTimeValueSpaceMap::representsInfinitelyManyValues(CDataLiteralCompareValue* leftValueExcluded, CDataLiteralCompareValue* rightValueExcluded) {
49 CDataLiteralDateTimeValue* dateTimeLeftValue = dynamic_cast<CDataLiteralDateTimeValue*>(leftValueExcluded);
50 CDataLiteralDateTimeValue* dateTimeRightValue = dynamic_cast<CDataLiteralDateTimeValue*>(rightValueExcluded);
51 if (dateTimeLeftValue->isFirstDateTime()) {
52 return true;
53 }
54 if (dateTimeRightValue->isLastDateTime()) {
55 return true;
56 }
57 return false;
58 }
59
60 bool CDatatypeDateTimeValueSpaceMap::representsInfinitelyManyValues(CDataLiteralCompareValue* value) {
61 return false;
62 }
63
64 bool CDatatypeDateTimeValueSpaceMap::getValueCopy(CDataLiteralCompareValue* valueCopyInto, CDataLiteralCompareValue* valueCopyFrom) {
65 CDataLiteralDateTimeValue* dateTimeValueCopyInto = dynamic_cast<CDataLiteralDateTimeValue*>(valueCopyInto);
66 CDataLiteralDateTimeValue* dateTimeValueCopyFrom = dynamic_cast<CDataLiteralDateTimeValue*>(valueCopyFrom);
67 dateTimeValueCopyInto->initValue(dateTimeValueCopyFrom);
68 return true;
69 }
70
71 bool CDatatypeDateTimeValueSpaceMap::getValueNext(CDataLiteralCompareValue* valueNext, CDataLiteralCompareValue* valueLast) {
72 CDataLiteralDateTimeValue* dateTimeValueNext = dynamic_cast<CDataLiteralDateTimeValue*>(valueNext);
73 CDataLiteralDateTimeValue* dateTimeValueLast = dynamic_cast<CDataLiteralDateTimeValue*>(valueLast);
74
75 dateTimeValueNext->initValue(dateTimeValueLast);
76 dateTimeValueNext->incrementDateTimeValue();
77 return true;
78 }
79
80
81 cuint64 CDatatypeDateTimeValueSpaceMap::getIntervalValueCount(CDataLiteralCompareValue* leftValueExcluded, CDataLiteralCompareValue* rightValueExcluded) {
82 CDataLiteralDateTimeValue* dateTimeLeftValue = dynamic_cast<CDataLiteralDateTimeValue*>(leftValueExcluded);
83 CDataLiteralDateTimeValue* dateTimeRightValue = dynamic_cast<CDataLiteralDateTimeValue*>(rightValueExcluded);
84 cuint64 valueCount = 0;
85
86 QDateTime leftValueDateTime = dateTimeLeftValue->getDateTimeValue();
87 QDateTime rightValueDateTime = dateTimeRightValue->getDateTimeValue();
88 cuint64 secondsBetween = leftValueDateTime.secsTo(rightValueDateTime)-1;
89 if (secondsBetween < 0) {
90 secondsBetween = 0;
91 valueCount += dateTimeRightValue->getTimeZoneOffset()-dateTimeLeftValue->getTimeZoneOffset()-1;
92 } else if (secondsBetween >= 0) {
93 if (dateTimeLeftValue->getTimeZoneOffset() < 840) {
94 valueCount += 840-dateTimeLeftValue->getTimeZoneOffset()-1;
95 }
96 if (dateTimeRightValue->getTimeZoneOffset() > -840) {
97 valueCount += dateTimeRightValue->getTimeZoneOffset()+840-1;
98 }
99 if (secondsBetween > 0) {
100 secondsBetween--;
101 }
102 }
103 valueCount = secondsBetween*(840*2-1);
104 return valueCount;
105 }
106
107
108
109 }; // end namespace Process
110
111 }; // end namespace Kernel
112
113 }; // end namespace Reasoner
114
115 }; // end namespace Konclude