MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlSchemaCompareDates

Function xmlSchemaCompareDates

ThirdParty/libxml2/vtklibxml2/xmlschemastypes.c:4152–4433  ·  view source on GitHub ↗

* xmlSchemaCompareDates: * @x: a first date/time value * @y: a second date/time value * * Compare 2 date/times * * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in * case of error */

Source from the content-addressed store, hash-verified

4150 * case of error
4151 */
4152static int
4153xmlSchemaCompareDates (xmlSchemaValPtr x, xmlSchemaValPtr y)
4154{
4155 unsigned char xmask, ymask, xor_mask, and_mask;
4156 xmlSchemaValPtr p1, p2, q1, q2;
4157 long p1d, p2d, q1d, q2d;
4158
4159 if ((x == NULL) || (y == NULL))
4160 return -2;
4161
4162 if ((x->value.date.year > LONG_MAX / 366) ||
4163 (x->value.date.year < LONG_MIN / 366) ||
4164 (y->value.date.year > LONG_MAX / 366) ||
4165 (y->value.date.year < LONG_MIN / 366)) {
4166 /* Possible overflow when converting to days. */
4167 return -2;
4168 }
4169
4170 if (x->value.date.tz_flag) {
4171
4172 if (!y->value.date.tz_flag) {
4173 p1 = xmlSchemaDateNormalize(x, 0);
4174 if (p1 == NULL)
4175 return -2;
4176 p1d = _xmlSchemaDateCastYMToDays(p1) + p1->value.date.day;
4177 /* normalize y + 14:00 */
4178 q1 = xmlSchemaDateNormalize(y, (14 * SECS_PER_HOUR));
4179 if (q1 == NULL) {
4180 xmlSchemaFreeValue(p1);
4181 return -2;
4182 }
4183
4184 q1d = _xmlSchemaDateCastYMToDays(q1) + q1->value.date.day;
4185 if (p1d < q1d) {
4186 xmlSchemaFreeValue(p1);
4187 xmlSchemaFreeValue(q1);
4188 return -1;
4189 } else if (p1d == q1d) {
4190 double sec;
4191
4192 sec = TIME_TO_NUMBER(p1) - TIME_TO_NUMBER(q1);
4193 if (sec < 0.0) {
4194 xmlSchemaFreeValue(p1);
4195 xmlSchemaFreeValue(q1);
4196 return -1;
4197 } else {
4198 int ret = 0;
4199 /* normalize y - 14:00 */
4200 q2 = xmlSchemaDateNormalize(y, -(14 * SECS_PER_HOUR));
4201 if (q2 == NULL) {
4202 xmlSchemaFreeValue(p1);
4203 xmlSchemaFreeValue(q1);
4204 return -2;
4205 }
4206 q2d = _xmlSchemaDateCastYMToDays(q2) + q2->value.date.day;
4207 if (p1d > q2d)
4208 ret = 1;
4209 else if (p1d == q2d) {

Callers 1

Calls 3

xmlSchemaDateNormalizeFunction · 0.85
xmlSchemaFreeValueFunction · 0.85

Tested by

no test coverage detected