OLD | NEW |
1 /* | 1 /* |
2 * date.c: Implementation of the EXSLT -- Dates and Times module | 2 * date.c: Implementation of the EXSLT -- Dates and Times module |
3 * | 3 * |
4 * References: | 4 * References: |
5 * http://www.exslt.org/date/date.html | 5 * http://www.exslt.org/date/date.html |
6 * | 6 * |
7 * See Copyright for the status of this software. | 7 * See Copyright for the status of this software. |
8 * | 8 * |
9 * Authors: | 9 * Authors: |
10 * Charlie Bozeman <cbozeman@HiWAAY.net> | 10 * Charlie Bozeman <cbozeman@HiWAAY.net> |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 exsltDateValPtr ret; | 660 exsltDateValPtr ret; |
661 | 661 |
662 ret = (exsltDateValPtr) xmlMalloc(sizeof(exsltDateVal)); | 662 ret = (exsltDateValPtr) xmlMalloc(sizeof(exsltDateVal)); |
663 if (ret == NULL) { | 663 if (ret == NULL) { |
664 xsltGenericError(xsltGenericErrorContext, | 664 xsltGenericError(xsltGenericErrorContext, |
665 "exsltDateCreateDate: out of memory\n"); | 665 "exsltDateCreateDate: out of memory\n"); |
666 return (NULL); | 666 return (NULL); |
667 } | 667 } |
668 memset (ret, 0, sizeof(exsltDateVal)); | 668 memset (ret, 0, sizeof(exsltDateVal)); |
669 | 669 |
| 670 if (type != XS_DURATION) { |
| 671 ret->value.date.mon = 1; |
| 672 ret->value.date.day = 1; |
| 673 } |
| 674 |
670 if (type != EXSLT_UNKNOWN) | 675 if (type != EXSLT_UNKNOWN) |
671 ret->type = type; | 676 ret->type = type; |
672 | 677 |
673 return ret; | 678 return ret; |
674 } | 679 } |
675 | 680 |
676 /** | 681 /** |
677 * exsltDateFreeDate: | 682 * exsltDateFreeDate: |
678 * @date: an #exsltDateValPtr | 683 * @date: an #exsltDateValPtr |
679 * | 684 * |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 if (dt == NULL) | 1393 if (dt == NULL) |
1389 return 1; | 1394 return 1; |
1390 | 1395 |
1391 if ((type & XS_TIME) != XS_TIME) { | 1396 if ((type & XS_TIME) != XS_TIME) { |
1392 dt->value.date.hour = 0; | 1397 dt->value.date.hour = 0; |
1393 dt->value.date.min = 0; | 1398 dt->value.date.min = 0; |
1394 dt->value.date.sec = 0.0; | 1399 dt->value.date.sec = 0.0; |
1395 } | 1400 } |
1396 | 1401 |
1397 if ((type & XS_GDAY) != XS_GDAY) | 1402 if ((type & XS_GDAY) != XS_GDAY) |
1398 dt->value.date.day = 0; | 1403 dt->value.date.day = 1; |
1399 | 1404 |
1400 if ((type & XS_GMONTH) != XS_GMONTH) | 1405 if ((type & XS_GMONTH) != XS_GMONTH) |
1401 dt->value.date.mon = 0; | 1406 dt->value.date.mon = 1; |
1402 | 1407 |
1403 if ((type & XS_GYEAR) != XS_GYEAR) | 1408 if ((type & XS_GYEAR) != XS_GYEAR) |
1404 dt->value.date.year = 0; | 1409 dt->value.date.year = 0; |
1405 | 1410 |
1406 dt->type = type; | 1411 dt->type = type; |
1407 | 1412 |
1408 return 0; | 1413 return 0; |
1409 } | 1414 } |
1410 | 1415 |
1411 /** | 1416 /** |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 return NULL; | 1471 return NULL; |
1467 | 1472 |
1468 ret = exsltDateCreateDate(dt->type); | 1473 ret = exsltDateCreateDate(dt->type); |
1469 if (ret == NULL) | 1474 if (ret == NULL) |
1470 return NULL; | 1475 return NULL; |
1471 | 1476 |
1472 r = &(ret->value.date); | 1477 r = &(ret->value.date); |
1473 d = &(dt->value.date); | 1478 d = &(dt->value.date); |
1474 u = &(dur->value.dur); | 1479 u = &(dur->value.dur); |
1475 | 1480 |
1476 /* normalization */ | |
1477 if (d->mon == 0) | |
1478 d->mon = 1; | |
1479 | |
1480 /* normalize for time zone offset */ | 1481 /* normalize for time zone offset */ |
1481 u->sec -= (d->tzo * 60); /* changed from + to - (bug 153000) */ | 1482 u->sec -= (d->tzo * 60); /* changed from + to - (bug 153000) */ |
1482 d->tzo = 0; | 1483 d->tzo = 0; |
1483 | 1484 |
1484 /* normalization */ | |
1485 if (d->day == 0) | |
1486 d->day = 1; | |
1487 | |
1488 /* month */ | 1485 /* month */ |
1489 carry = d->mon + u->mon; | 1486 carry = d->mon + u->mon; |
1490 r->mon = (unsigned int)MODULO_RANGE(carry, 1, 13); | 1487 r->mon = (unsigned int)MODULO_RANGE(carry, 1, 13); |
1491 carry = (long)FQUOTIENT_RANGE(carry, 1, 13); | 1488 carry = (long)FQUOTIENT_RANGE(carry, 1, 13); |
1492 | 1489 |
1493 /* year (may be modified later) */ | 1490 /* year (may be modified later) */ |
1494 r->year = d->year + carry; | 1491 r->year = d->year + carry; |
1495 if (r->year == 0) { | 1492 if (r->year == 0) { |
1496 if (d->year > 0) | 1493 if (d->year > 0) |
1497 r->year--; | 1494 r->year--; |
(...skipping 2407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3905 (const xmlChar *) EXSLT_DATE_NAMESPACE, | 3902 (const xmlChar *) EXSLT_DATE_NAMESPACE, |
3906 exsltDateWeekInYearFunction) | 3903 exsltDateWeekInYearFunction) |
3907 && !xmlXPathRegisterFuncNS(ctxt, | 3904 && !xmlXPathRegisterFuncNS(ctxt, |
3908 (const xmlChar *) "year", | 3905 (const xmlChar *) "year", |
3909 (const xmlChar *) EXSLT_DATE_NAMESPACE, | 3906 (const xmlChar *) EXSLT_DATE_NAMESPACE, |
3910 exsltDateYearFunction)) { | 3907 exsltDateYearFunction)) { |
3911 return 0; | 3908 return 0; |
3912 } | 3909 } |
3913 return -1; | 3910 return -1; |
3914 } | 3911 } |
OLD | NEW |