| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 #define IN_LIBEXSLT | 22 #define IN_LIBEXSLT |
| 23 #include "libexslt/libexslt.h" | 23 #include "libexslt/libexslt.h" |
| 24 | 24 |
| 25 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) | 25 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) |
| 26 #include <win32config.h> | 26 #include <win32config.h> |
| 27 #else | 27 #else |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 #if HAVE_LOCALTIME_R» /* _POSIX_SOURCE required by gnu libc */ | 31 #if defined(HAVE_LOCALTIME_R) && defined(__GLIBC__)» /* _POSIX_SOURCE require
d by gnu libc */ |
| 32 #ifndef _AIX51 /* but on AIX we're not using gnu libc */ | 32 #ifndef _AIX51 /* but on AIX we're not using gnu libc */ |
| 33 #define _POSIX_SOURCE | 33 #define _POSIX_SOURCE |
| 34 #endif | 34 #endif |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 #include <libxml/tree.h> | 37 #include <libxml/tree.h> |
| 38 #include <libxml/xpath.h> | 38 #include <libxml/xpath.h> |
| 39 #include <libxml/xpathInternals.h> | 39 #include <libxml/xpathInternals.h> |
| 40 | 40 |
| 41 #include <libxslt/xsltconfig.h> | 41 #include <libxslt/xsltconfig.h> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 double sec; | 92 double sec; |
| 93 unsigned int tz_flag :1; /* is tzo explicitely set? */ | 93 unsigned int tz_flag :1; /* is tzo explicitely set? */ |
| 94 signed int tzo :12; /* -1440 <= tzo <= 1440 currently only -
840 to +840 are needed */ | 94 signed int tzo :12; /* -1440 <= tzo <= 1440 currently only -
840 to +840 are needed */ |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 /* Duration value */ | 97 /* Duration value */ |
| 98 typedef struct _exsltDateValDuration exsltDateValDuration; | 98 typedef struct _exsltDateValDuration exsltDateValDuration; |
| 99 typedef exsltDateValDuration *exsltDateValDurationPtr; | 99 typedef exsltDateValDuration *exsltDateValDurationPtr; |
| 100 struct _exsltDateValDuration { | 100 struct _exsltDateValDuration { |
| 101 long mon; /* mon stores years also */ | 101 long mon; /* mon stores years also */ |
| 102 long » day; | 102 long» day; |
| 103 double sec; /* sec stores min and hour also */ | 103 double sec; /* sec stores min and hour also */ |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 typedef struct _exsltDateVal exsltDateVal; | 106 typedef struct _exsltDateVal exsltDateVal; |
| 107 typedef exsltDateVal *exsltDateValPtr; | 107 typedef exsltDateVal *exsltDateValPtr; |
| 108 struct _exsltDateVal { | 108 struct _exsltDateVal { |
| 109 exsltDateType type; | 109 exsltDateType type; |
| 110 union { | 110 union { |
| 111 exsltDateValDate date; | 111 exsltDateValDate date; |
| 112 exsltDateValDuration dur; | 112 exsltDateValDuration dur; |
| 113 } value; | 113 } value; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 /**************************************************************** | 116 /**************************************************************** |
| 117 * * | 117 * * |
| 118 * Compat./Port. macros * | 118 * Compat./Port. macros * |
| 119 * * | 119 * * |
| 120 ****************************************************************/ | 120 ****************************************************************/ |
| 121 | 121 |
| 122 #if defined(HAVE_TIME_H) » » » » » \ | 122 #if defined(HAVE_TIME_H)» » » » » \ |
| 123 && (defined(HAVE_LOCALTIME) || defined(HAVE_LOCALTIME_R)) \ | 123 && (defined(HAVE_LOCALTIME) || defined(HAVE_LOCALTIME_R)) \ |
| 124 && (defined(HAVE_GMTIME) || defined(HAVE_GMTIME_R)) \ | 124 && (defined(HAVE_GMTIME) || defined(HAVE_GMTIME_R)) \ |
| 125 && defined(HAVE_TIME) | 125 && defined(HAVE_TIME) |
| 126 #define WITH_TIME | 126 #define WITH_TIME |
| 127 #endif | 127 #endif |
| 128 | 128 |
| 129 /**************************************************************** | 129 /**************************************************************** |
| 130 * * | 130 * * |
| 131 * Convenience macros and functions * | 131 * Convenience macros and functions * |
| 132 * * | 132 * * |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 #if 0 | 784 #if 0 |
| 785 ret->value.date.tzo = (((ret->value.date.day * 1440) + | 785 ret->value.date.tzo = (((ret->value.date.day * 1440) + |
| 786 (ret->value.date.hour * 60) + | 786 (ret->value.date.hour * 60) + |
| 787 ret->value.date.min) - | 787 ret->value.date.min) - |
| 788 ((gmTm.tm_mday * 1440) + (gmTm.tm_hour * 60) + | 788 ((gmTm.tm_mday * 1440) + (gmTm.tm_hour * 60) + |
| 789 gmTm.tm_min)); | 789 gmTm.tm_min)); |
| 790 #endif | 790 #endif |
| 791 local_s = localTm.tm_hour * SECS_PER_HOUR + | 791 local_s = localTm.tm_hour * SECS_PER_HOUR + |
| 792 localTm.tm_min * SECS_PER_MIN + | 792 localTm.tm_min * SECS_PER_MIN + |
| 793 localTm.tm_sec; | 793 localTm.tm_sec; |
| 794 | 794 |
| 795 gm_s = gmTm.tm_hour * SECS_PER_HOUR + | 795 gm_s = gmTm.tm_hour * SECS_PER_HOUR + |
| 796 gmTm.tm_min * SECS_PER_MIN + | 796 gmTm.tm_min * SECS_PER_MIN + |
| 797 gmTm.tm_sec; | 797 gmTm.tm_sec; |
| 798 | 798 |
| 799 if (localTm.tm_year < gmTm.tm_year) { | 799 if (localTm.tm_year < gmTm.tm_year) { |
| 800 » ret->value.date.tzo = -((SECS_PER_DAY - local_s) + gm_s)/60; | 800 » ret->value.date.tzo = -((SECS_PER_DAY - local_s) + gm_s)/60; |
| 801 } else if (localTm.tm_year > gmTm.tm_year) { | 801 } else if (localTm.tm_year > gmTm.tm_year) { |
| 802 » ret->value.date.tzo = ((SECS_PER_DAY - gm_s) + local_s)/60; | 802 » ret->value.date.tzo = ((SECS_PER_DAY - gm_s) + local_s)/60; |
| 803 } else if (localTm.tm_mon < gmTm.tm_mon) { | 803 } else if (localTm.tm_mon < gmTm.tm_mon) { |
| 804 » ret->value.date.tzo = -((SECS_PER_DAY - local_s) + gm_s)/60; | 804 » ret->value.date.tzo = -((SECS_PER_DAY - local_s) + gm_s)/60; |
| 805 } else if (localTm.tm_mon > gmTm.tm_mon) { | 805 } else if (localTm.tm_mon > gmTm.tm_mon) { |
| 806 » ret->value.date.tzo = ((SECS_PER_DAY - gm_s) + local_s)/60; | 806 » ret->value.date.tzo = ((SECS_PER_DAY - gm_s) + local_s)/60; |
| 807 } else if (localTm.tm_mday < gmTm.tm_mday) { | 807 } else if (localTm.tm_mday < gmTm.tm_mday) { |
| 808 » ret->value.date.tzo = -((SECS_PER_DAY - local_s) + gm_s)/60; | 808 » ret->value.date.tzo = -((SECS_PER_DAY - local_s) + gm_s)/60; |
| 809 } else if (localTm.tm_mday > gmTm.tm_mday) { | 809 } else if (localTm.tm_mday > gmTm.tm_mday) { |
| 810 » ret->value.date.tzo = ((SECS_PER_DAY - gm_s) + local_s)/60; | 810 » ret->value.date.tzo = ((SECS_PER_DAY - gm_s) + local_s)/60; |
| 811 } else { | 811 } else { |
| 812 » ret->value.date.tzo = (local_s - gm_s)/60; | 812 » ret->value.date.tzo = (local_s - gm_s)/60; |
| 813 } | 813 } |
| 814 | 814 |
| 815 return ret; | 815 return ret; |
| 816 } | 816 } |
| 817 #endif | 817 #endif |
| 818 | 818 |
| 819 /** | 819 /** |
| 820 * exsltDateParse: | 820 * exsltDateParse: |
| 821 * @dateTime: string to analyze | 821 * @dateTime: string to analyze |
| 822 * | 822 * |
| 823 * Parses a date/time string | 823 * Parses a date/time string |
| 824 * | 824 * |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 exsltDateFormatDuration (const exsltDateValDurationPtr dt) | 1104 exsltDateFormatDuration (const exsltDateValDurationPtr dt) |
| 1105 { | 1105 { |
| 1106 xmlChar buf[100], *cur = buf; | 1106 xmlChar buf[100], *cur = buf; |
| 1107 double secs, days; | 1107 double secs, days; |
| 1108 double years, months; | 1108 double years, months; |
| 1109 | 1109 |
| 1110 if (dt == NULL) | 1110 if (dt == NULL) |
| 1111 return NULL; | 1111 return NULL; |
| 1112 | 1112 |
| 1113 /* quick and dirty check */ | 1113 /* quick and dirty check */ |
| 1114 if ((dt->sec == 0.0) && (dt->day == 0) && (dt->mon == 0)) | 1114 if ((dt->sec == 0.0) && (dt->day == 0) && (dt->mon == 0)) |
| 1115 return xmlStrdup((xmlChar*)"P0D"); | 1115 return xmlStrdup((xmlChar*)"P0D"); |
| 1116 | 1116 |
| 1117 secs = dt->sec; | 1117 secs = dt->sec; |
| 1118 days = (double)dt->day; | 1118 days = (double)dt->day; |
| 1119 years = (double)(dt->mon / 12); | 1119 years = (double)(dt->mon / 12); |
| 1120 months = (double)(dt->mon % 12); | 1120 months = (double)(dt->mon % 12); |
| 1121 | 1121 |
| 1122 *cur = '\0'; | 1122 *cur = '\0'; |
| 1123 if (secs < 0.0) { | 1123 if (secs < 0.0) { |
| 1124 secs = -secs; | 1124 secs = -secs; |
| 1125 *cur = '-'; | 1125 *cur = '-'; |
| 1126 } | 1126 } |
| 1127 if (days < 0) { | 1127 if (days < 0) { |
| 1128 days = -days; | 1128 days = -days; |
| 1129 *cur = '-'; | 1129 *cur = '-'; |
| 1130 } | 1130 } |
| 1131 if (years < 0) { | 1131 if (years < 0) { |
| 1132 years = -years; | 1132 years = -years; |
| 1133 *cur = '-'; | 1133 *cur = '-'; |
| 1134 } | 1134 } |
| 1135 if (months < 0) { | 1135 if (months < 0) { |
| 1136 months = -months; | 1136 months = -months; |
| 1137 *cur = '-'; | 1137 *cur = '-'; |
| 1138 } | 1138 } |
| 1139 if (*cur == '-') | 1139 if (*cur == '-') |
| 1140 cur++; | 1140 cur++; |
| 1141 | 1141 |
| 1142 *cur++ = 'P'; | 1142 *cur++ = 'P'; |
| 1143 | 1143 |
| 1144 if (years != 0.0) { | 1144 if (years != 0.0) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 return xmlStrdup(buf); | 1294 return xmlStrdup(buf); |
| 1295 } | 1295 } |
| 1296 | 1296 |
| 1297 return NULL; | 1297 return NULL; |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 /** | 1300 /** |
| 1301 * _exsltDateCastYMToDays: | 1301 * _exsltDateCastYMToDays: |
| 1302 * @dt: an #exsltDateValPtr | 1302 * @dt: an #exsltDateValPtr |
| 1303 * | 1303 * |
| 1304 * Convert mon and year of @dt to total number of days. Take the | 1304 * Convert mon and year of @dt to total number of days. Take the |
| 1305 * number of years since (or before) 1 AD and add the number of leap | 1305 * number of years since (or before) 1 AD and add the number of leap |
| 1306 * years. This is a function because negative | 1306 * years. This is a function because negative |
| 1307 * years must be handled a little differently and there is no zero year. | 1307 * years must be handled a little differently and there is no zero year. |
| 1308 * | 1308 * |
| 1309 * Returns number of days. | 1309 * Returns number of days. |
| 1310 */ | 1310 */ |
| 1311 static long | 1311 static long |
| 1312 _exsltDateCastYMToDays (const exsltDateValPtr dt) | 1312 _exsltDateCastYMToDays (const exsltDateValPtr dt) |
| 1313 { | 1313 { |
| 1314 long ret; | 1314 long ret; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 | 1407 |
| 1408 return 0; | 1408 return 0; |
| 1409 } | 1409 } |
| 1410 | 1410 |
| 1411 /** | 1411 /** |
| 1412 * _exsltDayInWeek: | 1412 * _exsltDayInWeek: |
| 1413 * @yday: year day (1-366) | 1413 * @yday: year day (1-366) |
| 1414 * @yr: year | 1414 * @yr: year |
| 1415 * | 1415 * |
| 1416 * Determine the day-in-week from @yday and @yr. 0001-01-01 was | 1416 * Determine the day-in-week from @yday and @yr. 0001-01-01 was |
| 1417 * a Monday so all other days are calculated from there. Take the | 1417 * a Monday so all other days are calculated from there. Take the |
| 1418 * number of years since (or before) add the number of leap years and | 1418 * number of years since (or before) add the number of leap years and |
| 1419 * the day-in-year and mod by 7. This is a function because negative | 1419 * the day-in-year and mod by 7. This is a function because negative |
| 1420 * years must be handled a little differently and there is no zero year. | 1420 * years must be handled a little differently and there is no zero year. |
| 1421 * | 1421 * |
| 1422 * Returns day in week (Sunday = 0). | 1422 * Returns day in week (Sunday = 0). |
| 1423 */ | 1423 */ |
| 1424 static long | 1424 static long |
| 1425 _exsltDateDayInWeek(long yday, long yr) | 1425 _exsltDateDayInWeek(long yday, long yr) |
| 1426 { | 1426 { |
| 1427 long ret; | 1427 long ret; |
| 1428 | 1428 |
| 1429 if (yr < 0) { | 1429 if (yr < 0) { |
| 1430 ret = ((yr + (((yr+1)/4)-((yr+1)/100)+((yr+1)/400)) + yday) % 7); | 1430 ret = ((yr + (((yr+1)/4)-((yr+1)/100)+((yr+1)/400)) + yday) % 7); |
| 1431 if (ret < 0) | 1431 if (ret < 0) |
| 1432 ret += 7; | 1432 ret += 7; |
| 1433 } else | 1433 } else |
| 1434 ret = (((yr-1) + (((yr-1)/4)-((yr-1)/100)+((yr-1)/400)) + yday) % 7); | 1434 ret = (((yr-1) + (((yr-1)/4)-((yr-1)/100)+((yr-1)/400)) + yday) % 7); |
| 1435 | 1435 |
| 1436 return ret; | 1436 return ret; |
| 1437 } | 1437 } |
| 1438 | 1438 |
| 1439 /* | 1439 /* |
| 1440 * macros for adding date/times and durations | 1440 * macros for adding date/times and durations |
| 1441 */ | 1441 */ |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 | 1535 |
| 1536 tempdays += u->day + carry; | 1536 tempdays += u->day + carry; |
| 1537 | 1537 |
| 1538 while (1) { | 1538 while (1) { |
| 1539 if (tempdays < 1) { | 1539 if (tempdays < 1) { |
| 1540 long tmon = (long)MODULO_RANGE((int)r->mon-1, 1, 13); | 1540 long tmon = (long)MODULO_RANGE((int)r->mon-1, 1, 13); |
| 1541 long tyr = r->year + (long)FQUOTIENT_RANGE((int)r->mon-1, 1, 13); | 1541 long tyr = r->year + (long)FQUOTIENT_RANGE((int)r->mon-1, 1, 13); |
| 1542 if (tyr == 0) | 1542 if (tyr == 0) |
| 1543 tyr--; | 1543 tyr--; |
| 1544 /* | 1544 /* |
| 1545 » * Coverity detected an overrun in daysInMonth | 1545 » * Coverity detected an overrun in daysInMonth |
| 1546 * of size 12 at position 12 with index variable "((r)->mon - 1)" | 1546 * of size 12 at position 12 with index variable "((r)->mon - 1)" |
| 1547 */ | 1547 */ |
| 1548 if (tmon < 0) | 1548 if (tmon < 0) |
| 1549 tmon = 0; | 1549 tmon = 0; |
| 1550 if (tmon > 12) | 1550 if (tmon > 12) |
| 1551 tmon = 12; | 1551 tmon = 12; |
| 1552 tempdays += MAX_DAYINMONTH(tyr, tmon); | 1552 tempdays += MAX_DAYINMONTH(tyr, tmon); |
| 1553 carry = -1; | 1553 carry = -1; |
| 1554 } else if (tempdays > (long)MAX_DAYINMONTH(r->year, r->mon)) { | 1554 } else if (tempdays > (long)MAX_DAYINMONTH(r->year, r->mon)) { |
| 1555 tempdays = tempdays - MAX_DAYINMONTH(r->year, r->mon); | 1555 tempdays = tempdays - MAX_DAYINMONTH(r->year, r->mon); |
| 1556 carry = 1; | 1556 carry = 1; |
| 1557 } else | 1557 } else |
| 1558 break; | 1558 break; |
| 1559 | 1559 |
| 1560 temp = r->mon + carry; | 1560 temp = r->mon + carry; |
| 1561 r->mon = (unsigned int)MODULO_RANGE(temp, 1, 13); | 1561 r->mon = (unsigned int)MODULO_RANGE(temp, 1, 13); |
| 1562 r->year = r->year + (long)FQUOTIENT_RANGE(temp, 1, 13); | 1562 r->year = r->year + (long)FQUOTIENT_RANGE(temp, 1, 13); |
| 1563 if (r->year == 0) { | 1563 if (r->year == 0) { |
| 1564 if (temp < 1) | 1564 if (temp < 1) |
| 1565 r->year--; | 1565 r->year--; |
| 1566 else | 1566 else |
| 1567 r->year++; | 1567 r->year++; |
| 1568 } | 1568 } |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 r->day = tempdays; | 1571 r->day = tempdays; |
| 1572 | 1572 |
| 1573 /* | 1573 /* |
| 1574 * adjust the date/time type to the date values | 1574 * adjust the date/time type to the date values |
| 1575 */ | 1575 */ |
| 1576 if (ret->type != XS_DATETIME) { | 1576 if (ret->type != XS_DATETIME) { |
| 1577 if ((r->hour) || (r->min) || (r->sec)) | 1577 if ((r->hour) || (r->min) || (r->sec)) |
| 1578 ret->type = XS_DATETIME; | 1578 ret->type = XS_DATETIME; |
| 1579 else if (ret->type != XS_DATE) { | 1579 else if (ret->type != XS_DATE) { |
| 1580 if ((r->mon != 1) && (r->day != 1)) | 1580 if (r->day != 1) |
| 1581 ret->type = XS_DATE; | 1581 ret->type = XS_DATE; |
| 1582 else if ((ret->type != XS_GYEARMONTH) && (r->mon != 1)) | 1582 else if ((ret->type != XS_GYEARMONTH) && (r->mon != 1)) |
| 1583 ret->type = XS_GYEARMONTH; | 1583 ret->type = XS_GYEARMONTH; |
| 1584 } | 1584 } |
| 1585 } | 1585 } |
| 1586 | 1586 |
| 1587 return ret; | 1587 return ret; |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 /** | 1590 /** |
| 1591 * exsltDateNormalize: | 1591 * exsltDateNormalize: |
| 1592 * @dt: an #exsltDateValPtr | 1592 * @dt: an #exsltDateValPtr |
| 1593 * | 1593 * |
| 1594 * Normalize @dt to GMT time. | 1594 * Normalize @dt to GMT time. |
| 1595 * | 1595 * |
| 1596 */ | 1596 */ |
| 1597 static void | 1597 static void |
| 1598 exsltDateNormalize (exsltDateValPtr dt) | 1598 exsltDateNormalize (exsltDateValPtr dt) |
| 1599 { | 1599 { |
| 1600 exsltDateValPtr dur, tmp; | 1600 exsltDateValPtr dur, tmp; |
| 1601 | 1601 |
| 1602 if (dt == NULL) | 1602 if (dt == NULL) |
| 1603 return; | 1603 return; |
| 1604 | 1604 |
| 1605 if (((dt->type & XS_TIME) != XS_TIME) || (dt->value.date.tzo == 0)) | 1605 if (((dt->type & XS_TIME) != XS_TIME) && (dt->value.date.tzo == 0)) |
| 1606 return; | 1606 return; |
| 1607 | 1607 |
| 1608 dur = exsltDateCreateDate(XS_DURATION); | 1608 dur = exsltDateCreateDate(XS_DURATION); |
| 1609 if (dur == NULL) | 1609 if (dur == NULL) |
| 1610 return; | 1610 return; |
| 1611 | 1611 |
| 1612 tmp = _exsltDateAdd(dt, dur); | 1612 tmp = _exsltDateAdd(dt, dur); |
| 1613 if (tmp == NULL) | 1613 if (tmp == NULL) |
| 1614 return; | 1614 return; |
| 1615 | 1615 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1635 */ | 1635 */ |
| 1636 static exsltDateValPtr | 1636 static exsltDateValPtr |
| 1637 _exsltDateDifference (exsltDateValPtr x, exsltDateValPtr y, int flag) | 1637 _exsltDateDifference (exsltDateValPtr x, exsltDateValPtr y, int flag) |
| 1638 { | 1638 { |
| 1639 exsltDateValPtr ret; | 1639 exsltDateValPtr ret; |
| 1640 | 1640 |
| 1641 if ((x == NULL) || (y == NULL)) | 1641 if ((x == NULL) || (y == NULL)) |
| 1642 return NULL; | 1642 return NULL; |
| 1643 | 1643 |
| 1644 if (((x->type < XS_GYEAR) || (x->type > XS_DATETIME)) || | 1644 if (((x->type < XS_GYEAR) || (x->type > XS_DATETIME)) || |
| 1645 ((y->type < XS_GYEAR) || (y->type > XS_DATETIME))) | 1645 ((y->type < XS_GYEAR) || (y->type > XS_DATETIME))) |
| 1646 return NULL; | 1646 return NULL; |
| 1647 | 1647 |
| 1648 exsltDateNormalize(x); | 1648 exsltDateNormalize(x); |
| 1649 exsltDateNormalize(y); | 1649 exsltDateNormalize(y); |
| 1650 | 1650 |
| 1651 /* | 1651 /* |
| 1652 * the operand with the most specific format must be converted to | 1652 * the operand with the most specific format must be converted to |
| 1653 * the same type as the operand with the least specific format. | 1653 * the same type as the operand with the least specific format. |
| 1654 */ | 1654 */ |
| 1655 if (x->type != y->type) { | 1655 if (x->type != y->type) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 * * | 1772 * * |
| 1773 * EXSLT - Dates and Times functions * | 1773 * EXSLT - Dates and Times functions * |
| 1774 * * | 1774 * * |
| 1775 ****************************************************************/ | 1775 ****************************************************************/ |
| 1776 | 1776 |
| 1777 /** | 1777 /** |
| 1778 * exsltDateDateTime: | 1778 * exsltDateDateTime: |
| 1779 * | 1779 * |
| 1780 * Implements the EXSLT - Dates and Times date-time() function: | 1780 * Implements the EXSLT - Dates and Times date-time() function: |
| 1781 * string date:date-time() | 1781 * string date:date-time() |
| 1782 * | 1782 * |
| 1783 * Returns the current date and time as a date/time string. | 1783 * Returns the current date and time as a date/time string. |
| 1784 */ | 1784 */ |
| 1785 static xmlChar * | 1785 static xmlChar * |
| 1786 exsltDateDateTime (void) | 1786 exsltDateDateTime (void) |
| 1787 { | 1787 { |
| 1788 xmlChar *ret = NULL; | 1788 xmlChar *ret = NULL; |
| 1789 #ifdef WITH_TIME | 1789 #ifdef WITH_TIME |
| 1790 exsltDateValPtr cur; | 1790 exsltDateValPtr cur; |
| 1791 | 1791 |
| 1792 cur = exsltDateCurrent(); | 1792 cur = exsltDateCurrent(); |
| 1793 if (cur != NULL) { | 1793 if (cur != NULL) { |
| 1794 ret = exsltDateFormatDateTime(&(cur->value.date)); | 1794 ret = exsltDateFormatDateTime(&(cur->value.date)); |
| 1795 exsltDateFreeDate(cur); | 1795 exsltDateFreeDate(cur); |
| 1796 } | 1796 } |
| 1797 #endif | 1797 #endif |
| 1798 | 1798 |
| 1799 return ret; | 1799 return ret; |
| 1800 } | 1800 } |
| 1801 | 1801 |
| 1802 /** | 1802 /** |
| 1803 * exsltDateDate: | 1803 * exsltDateDate: |
| 1804 * @dateTime: a date/time string | 1804 * @dateTime: a date/time string |
| 1805 * | 1805 * |
| 1806 * Implements the EXSLT - Dates and Times date() function: | 1806 * Implements the EXSLT - Dates and Times date() function: |
| 1807 * string date:date (string?) | 1807 * string date:date (string?) |
| 1808 * | 1808 * |
| 1809 * Returns the date specified in the date/time string given as the | 1809 * Returns the date specified in the date/time string given as the |
| 1810 * argument. If no argument is given, then the current local | 1810 * argument. If no argument is given, then the current local |
| 1811 * date/time, as returned by date:date-time is used as a default | 1811 * date/time, as returned by date:date-time is used as a default |
| 1812 * argument. | 1812 * argument. |
| 1813 * The date/time string specified as an argument must be a string in | 1813 * The date/time string specified as an argument must be a string in |
| 1814 * the format defined as the lexical representation of either | 1814 * the format defined as the lexical representation of either |
| 1815 * xs:dateTime or xs:date. If the argument is not in either of these | 1815 * xs:dateTime or xs:date. If the argument is not in either of these |
| 1816 * formats, returns NULL. | 1816 * formats, returns NULL. |
| 1817 */ | 1817 */ |
| 1818 static xmlChar * | 1818 static xmlChar * |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1842 | 1842 |
| 1843 return ret; | 1843 return ret; |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 /** | 1846 /** |
| 1847 * exsltDateTime: | 1847 * exsltDateTime: |
| 1848 * @dateTime: a date/time string | 1848 * @dateTime: a date/time string |
| 1849 * | 1849 * |
| 1850 * Implements the EXSLT - Dates and Times time() function: | 1850 * Implements the EXSLT - Dates and Times time() function: |
| 1851 * string date:time (string?) | 1851 * string date:time (string?) |
| 1852 * | 1852 * |
| 1853 * Returns the time specified in the date/time string given as the | 1853 * Returns the time specified in the date/time string given as the |
| 1854 * argument. If no argument is given, then the current local | 1854 * argument. If no argument is given, then the current local |
| 1855 * date/time, as returned by date:date-time is used as a default | 1855 * date/time, as returned by date:date-time is used as a default |
| 1856 * argument. | 1856 * argument. |
| 1857 * The date/time string specified as an argument must be a string in | 1857 * The date/time string specified as an argument must be a string in |
| 1858 * the format defined as the lexical representation of either | 1858 * the format defined as the lexical representation of either |
| 1859 * xs:dateTime or xs:time. If the argument is not in either of these | 1859 * xs:dateTime or xs:time. If the argument is not in either of these |
| 1860 * formats, returns NULL. | 1860 * formats, returns NULL. |
| 1861 */ | 1861 */ |
| 1862 static xmlChar * | 1862 static xmlChar * |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2623 * given, then the current local date/time, as returned by | 2623 * given, then the current local date/time, as returned by |
| 2624 * date:date-time is used the default argument. | 2624 * date:date-time is used the default argument. |
| 2625 * The date/time string specified as the argument is a left or | 2625 * The date/time string specified as the argument is a left or |
| 2626 * right-truncated string in the format defined as the lexical | 2626 * right-truncated string in the format defined as the lexical |
| 2627 * representation of xs:dateTime in one of the formats defined in [XML | 2627 * representation of xs:dateTime in one of the formats defined in [XML |
| 2628 * Schema Part 2: Datatypes]. The permitted formats are as follows: | 2628 * Schema Part 2: Datatypes]. The permitted formats are as follows: |
| 2629 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) | 2629 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) |
| 2630 * - xs:time (hh:mm:ss) | 2630 * - xs:time (hh:mm:ss) |
| 2631 * If the date/time string is not in one of these formats, then NaN is | 2631 * If the date/time string is not in one of these formats, then NaN is |
| 2632 * returned. | 2632 * returned. |
| 2633 * | 2633 * |
| 2634 * Returns the second or NaN. | 2634 * Returns the second or NaN. |
| 2635 */ | 2635 */ |
| 2636 static double | 2636 static double |
| 2637 exsltDateSecondInMinute (const xmlChar *dateTime) | 2637 exsltDateSecondInMinute (const xmlChar *dateTime) |
| 2638 { | 2638 { |
| 2639 exsltDateValPtr dt; | 2639 exsltDateValPtr dt; |
| 2640 double ret; | 2640 double ret; |
| 2641 | 2641 |
| 2642 if (dateTime == NULL) { | 2642 if (dateTime == NULL) { |
| 2643 #ifdef WITH_TIME | 2643 #ifdef WITH_TIME |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2660 | 2660 |
| 2661 return ret; | 2661 return ret; |
| 2662 } | 2662 } |
| 2663 | 2663 |
| 2664 /** | 2664 /** |
| 2665 * exsltDateAdd: | 2665 * exsltDateAdd: |
| 2666 * @xstr: date/time string | 2666 * @xstr: date/time string |
| 2667 * @ystr: date/time string | 2667 * @ystr: date/time string |
| 2668 * | 2668 * |
| 2669 * Implements the date:add (string,string) function which returns the | 2669 * Implements the date:add (string,string) function which returns the |
| 2670 * date/time * resulting from adding a duration to a date/time. | 2670 * date/time * resulting from adding a duration to a date/time. |
| 2671 * The first argument (@xstr) must be right-truncated date/time | 2671 * The first argument (@xstr) must be right-truncated date/time |
| 2672 * strings in one of the formats defined in [XML Schema Part 2: | 2672 * strings in one of the formats defined in [XML Schema Part 2: |
| 2673 * Datatypes]. The permitted formats are as follows: | 2673 * Datatypes]. The permitted formats are as follows: |
| 2674 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) | 2674 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) |
| 2675 * - xs:date (CCYY-MM-DD) | 2675 * - xs:date (CCYY-MM-DD) |
| 2676 * - xs:gYearMonth (CCYY-MM) | 2676 * - xs:gYearMonth (CCYY-MM) |
| 2677 * - xs:gYear (CCYY) | 2677 * - xs:gYear (CCYY) |
| 2678 * The second argument (@ystr) is a string in the format defined for | 2678 * The second argument (@ystr) is a string in the format defined for |
| 2679 * xs:duration in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. | 2679 * xs:duration in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. |
| 2680 * The return value is a right-truncated date/time strings in one of | 2680 * The return value is a right-truncated date/time strings in one of |
| 2681 * the formats defined in [XML Schema Part 2: Datatypes] and listed | 2681 * the formats defined in [XML Schema Part 2: Datatypes] and listed |
| 2682 * above. This value is calculated using the algorithm described in | 2682 * above. This value is calculated using the algorithm described in |
| 2683 * [Appendix E Adding durations to dateTimes] of [XML Schema Part 2: | 2683 * [Appendix E Adding durations to dateTimes] of [XML Schema Part 2: |
| 2684 * Datatypes]. | 2684 * Datatypes]. |
| 2685 | 2685 |
| 2686 * Returns date/time string or NULL. | 2686 * Returns date/time string or NULL. |
| 2687 */ | 2687 */ |
| 2688 static xmlChar * | 2688 static xmlChar * |
| 2689 exsltDateAdd (const xmlChar *xstr, const xmlChar *ystr) | 2689 exsltDateAdd (const xmlChar *xstr, const xmlChar *ystr) |
| 2690 { | 2690 { |
| 2691 exsltDateValPtr dt, dur, res; | 2691 exsltDateValPtr dt, dur, res; |
| 2692 xmlChar *ret; | 2692 xmlChar *ret; |
| 2693 | 2693 |
| 2694 if ((xstr == NULL) || (ystr == NULL)) | 2694 if ((xstr == NULL) || (ystr == NULL)) |
| 2695 return NULL; | 2695 return NULL; |
| 2696 | 2696 |
| 2697 dt = exsltDateParse(xstr); | 2697 dt = exsltDateParse(xstr); |
| 2698 if (dt == NULL) | 2698 if (dt == NULL) |
| 2699 return NULL; | 2699 return NULL; |
| 2700 else if ((dt->type < XS_GYEAR) || (dt->type > XS_DATETIME)) { | 2700 else if ((dt->type < XS_GYEAR) || (dt->type > XS_DATETIME)) { |
| 2701 exsltDateFreeDate(dt); | 2701 exsltDateFreeDate(dt); |
| 2702 return NULL; | 2702 return NULL; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2721 | 2721 |
| 2722 return ret; | 2722 return ret; |
| 2723 } | 2723 } |
| 2724 | 2724 |
| 2725 /** | 2725 /** |
| 2726 * exsltDateAddDuration: | 2726 * exsltDateAddDuration: |
| 2727 * @xstr: first duration string | 2727 * @xstr: first duration string |
| 2728 * @ystr: second duration string | 2728 * @ystr: second duration string |
| 2729 * | 2729 * |
| 2730 * Implements the date:add-duration (string,string) function which returns | 2730 * Implements the date:add-duration (string,string) function which returns |
| 2731 * the duration resulting from adding two durations together. | 2731 * the duration resulting from adding two durations together. |
| 2732 * Both arguments are strings in the format defined for xs:duration | 2732 * Both arguments are strings in the format defined for xs:duration |
| 2733 * in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. If either | 2733 * in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. If either |
| 2734 * argument is not in this format, the function returns an empty string | 2734 * argument is not in this format, the function returns an empty string |
| 2735 * (''). | 2735 * (''). |
| 2736 * The return value is a string in the format defined for xs:duration | 2736 * The return value is a string in the format defined for xs:duration |
| 2737 * in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. | 2737 * in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. |
| 2738 * The durations can usually be added by summing the numbers given for | 2738 * The durations can usually be added by summing the numbers given for |
| 2739 * each of the components in the durations. However, if the durations | 2739 * each of the components in the durations. However, if the durations |
| 2740 * are differently signed, then this sometimes results in durations | 2740 * are differently signed, then this sometimes results in durations |
| 2741 * that are impossible to express in this syntax (e.g. 'P1M' + '-P1D'). | 2741 * that are impossible to express in this syntax (e.g. 'P1M' + '-P1D'). |
| 2742 * In these cases, the function returns an empty string (''). | 2742 * In these cases, the function returns an empty string (''). |
| 2743 * | 2743 * |
| 2744 * Returns duration string or NULL. | 2744 * Returns duration string or NULL. |
| 2745 */ | 2745 */ |
| 2746 static xmlChar * | 2746 static xmlChar * |
| 2747 exsltDateAddDuration (const xmlChar *xstr, const xmlChar *ystr) | 2747 exsltDateAddDuration (const xmlChar *xstr, const xmlChar *ystr) |
| 2748 { | 2748 { |
| 2749 exsltDateValPtr x, y, res; | 2749 exsltDateValPtr x, y, res; |
| 2750 xmlChar *ret; | 2750 xmlChar *ret; |
| 2751 | 2751 |
| 2752 if ((xstr == NULL) || (ystr == NULL)) | 2752 if ((xstr == NULL) || (ystr == NULL)) |
| 2753 return NULL; | 2753 return NULL; |
| 2754 | 2754 |
| 2755 x = exsltDateParseDuration(xstr); | 2755 x = exsltDateParseDuration(xstr); |
| 2756 if (x == NULL) | 2756 if (x == NULL) |
| 2757 return NULL; | 2757 return NULL; |
| 2758 | 2758 |
| 2759 y = exsltDateParseDuration(ystr); | 2759 y = exsltDateParseDuration(ystr); |
| 2760 if (y == NULL) { | 2760 if (y == NULL) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2773 ret = exsltDateFormatDuration(&(res->value.dur)); | 2773 ret = exsltDateFormatDuration(&(res->value.dur)); |
| 2774 exsltDateFreeDate(res); | 2774 exsltDateFreeDate(res); |
| 2775 | 2775 |
| 2776 return ret; | 2776 return ret; |
| 2777 } | 2777 } |
| 2778 | 2778 |
| 2779 /** | 2779 /** |
| 2780 * exsltDateSumFunction: | 2780 * exsltDateSumFunction: |
| 2781 * @ns: a node set of duration strings | 2781 * @ns: a node set of duration strings |
| 2782 * | 2782 * |
| 2783 * The date:sum function adds a set of durations together. | 2783 * The date:sum function adds a set of durations together. |
| 2784 * The string values of the nodes in the node set passed as an argument | 2784 * The string values of the nodes in the node set passed as an argument |
| 2785 * are interpreted as durations and added together as if using the | 2785 * are interpreted as durations and added together as if using the |
| 2786 * date:add-duration function. (from exslt.org) | 2786 * date:add-duration function. (from exslt.org) |
| 2787 * | 2787 * |
| 2788 * The return value is a string in the format defined for xs:duration | 2788 * The return value is a string in the format defined for xs:duration |
| 2789 * in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. | 2789 * in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. |
| 2790 * The durations can usually be added by summing the numbers given for | 2790 * The durations can usually be added by summing the numbers given for |
| 2791 * each of the components in the durations. However, if the durations | 2791 * each of the components in the durations. However, if the durations |
| 2792 * are differently signed, then this sometimes results in durations | 2792 * are differently signed, then this sometimes results in durations |
| 2793 * that are impossible to express in this syntax (e.g. 'P1M' + '-P1D'). | 2793 * that are impossible to express in this syntax (e.g. 'P1M' + '-P1D'). |
| 2794 * In these cases, the function returns an empty string (''). | 2794 * In these cases, the function returns an empty string (''). |
| 2795 * | 2795 * |
| 2796 * Returns duration string or NULL. | 2796 * Returns duration string or NULL. |
| 2797 */ | 2797 */ |
| 2798 static void | 2798 static void |
| 2799 exsltDateSumFunction (xmlXPathParserContextPtr ctxt, int nargs) | 2799 exsltDateSumFunction (xmlXPathParserContextPtr ctxt, int nargs) |
| 2800 { | 2800 { |
| 2801 xmlNodeSetPtr ns; | 2801 xmlNodeSetPtr ns; |
| 2802 void *user = NULL; | 2802 void *user = NULL; |
| 2803 xmlChar *tmp; | 2803 xmlChar *tmp; |
| 2804 exsltDateValPtr x, total; | 2804 exsltDateValPtr x, total; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2828 return; | 2828 return; |
| 2829 } | 2829 } |
| 2830 | 2830 |
| 2831 total = exsltDateCreateDate (XS_DURATION); | 2831 total = exsltDateCreateDate (XS_DURATION); |
| 2832 if (total == NULL) { | 2832 if (total == NULL) { |
| 2833 xmlXPathFreeNodeSet (ns); | 2833 xmlXPathFreeNodeSet (ns); |
| 2834 return; | 2834 return; |
| 2835 } | 2835 } |
| 2836 | 2836 |
| 2837 for (i = 0; i < ns->nodeNr; i++) { | 2837 for (i = 0; i < ns->nodeNr; i++) { |
| 2838 » int result; | 2838 » int result; |
| 2839 tmp = xmlXPathCastNodeToString (ns->nodeTab[i]); | 2839 tmp = xmlXPathCastNodeToString (ns->nodeTab[i]); |
| 2840 if (tmp == NULL) { | 2840 if (tmp == NULL) { |
| 2841 xmlXPathFreeNodeSet (ns); | 2841 xmlXPathFreeNodeSet (ns); |
| 2842 exsltDateFreeDate (total); | 2842 exsltDateFreeDate (total); |
| 2843 return; | 2843 return; |
| 2844 } | 2844 } |
| 2845 | 2845 |
| 2846 x = exsltDateParseDuration (tmp); | 2846 x = exsltDateParseDuration (tmp); |
| 2847 if (x == NULL) { | 2847 if (x == NULL) { |
| 2848 xmlFree (tmp); | 2848 xmlFree (tmp); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2881 * exsltDateSeconds: | 2881 * exsltDateSeconds: |
| 2882 * @dateTime: a date/time string | 2882 * @dateTime: a date/time string |
| 2883 * | 2883 * |
| 2884 * Implements the EXSLT - Dates and Times seconds() function: | 2884 * Implements the EXSLT - Dates and Times seconds() function: |
| 2885 * number date:seconds(string?) | 2885 * number date:seconds(string?) |
| 2886 * The date:seconds function returns the number of seconds specified | 2886 * The date:seconds function returns the number of seconds specified |
| 2887 * by the argument string. If no argument is given, then the current | 2887 * by the argument string. If no argument is given, then the current |
| 2888 * local date/time, as returned by exsltDateCurrent() is used as the | 2888 * local date/time, as returned by exsltDateCurrent() is used as the |
| 2889 * default argument. If the date/time string is a xs:duration, then the | 2889 * default argument. If the date/time string is a xs:duration, then the |
| 2890 * years and months must be zero (or not present). Parsing a duration | 2890 * years and months must be zero (or not present). Parsing a duration |
| 2891 * converts the fields to seconds. If the date/time string is not a | 2891 * converts the fields to seconds. If the date/time string is not a |
| 2892 * duration (and not null), then the legal formats are: | 2892 * duration (and not null), then the legal formats are: |
| 2893 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) | 2893 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) |
| 2894 * - xs:date (CCYY-MM-DD) | 2894 * - xs:date (CCYY-MM-DD) |
| 2895 * - xs:gYearMonth (CCYY-MM) | 2895 * - xs:gYearMonth (CCYY-MM) |
| 2896 * - xs:gYear (CCYY) | 2896 * - xs:gYear (CCYY) |
| 2897 * In these cases the difference between the @dateTime and | 2897 * In these cases the difference between the @dateTime and |
| 2898 * 1970-01-01T00:00:00Z is calculated and converted to seconds. | 2898 * 1970-01-01T00:00:00Z is calculated and converted to seconds. |
| 2899 * | 2899 * |
| 2900 * Note that there was some confusion over whether "difference" meant | 2900 * Note that there was some confusion over whether "difference" meant |
| 2901 * that a dateTime of 1970-01-01T00:00:01Z should be a positive one or | 2901 * that a dateTime of 1970-01-01T00:00:01Z should be a positive one or |
| 2902 * a negative one. After correspondence with exslt.org, it was determined | 2902 * a negative one. After correspondence with exslt.org, it was determined |
| 2903 * that the intent of the specification was to have it positive. The | 2903 * that the intent of the specification was to have it positive. The |
| 2904 * coding was modified in July 2003 to reflect this. | 2904 * coding was modified in July 2003 to reflect this. |
| 2905 * | 2905 * |
| 2906 * Returns seconds or Nan. | 2906 * Returns seconds or Nan. |
| 2907 */ | 2907 */ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2935 */ | 2935 */ |
| 2936 y = exsltDateCreateDate(XS_DATETIME); | 2936 y = exsltDateCreateDate(XS_DATETIME); |
| 2937 if (y != NULL) { | 2937 if (y != NULL) { |
| 2938 y->value.date.year = 1970; | 2938 y->value.date.year = 1970; |
| 2939 y->value.date.mon = 1; | 2939 y->value.date.mon = 1; |
| 2940 y->value.date.day = 1; | 2940 y->value.date.day = 1; |
| 2941 y->value.date.tz_flag = 1; | 2941 y->value.date.tz_flag = 1; |
| 2942 | 2942 |
| 2943 dur = _exsltDateDifference(y, dt, 1); | 2943 dur = _exsltDateDifference(y, dt, 1); |
| 2944 if (dur != NULL) { | 2944 if (dur != NULL) { |
| 2945 ret = exsltDateCastDateToNumber(dur); | 2945 ret = exsltDateCastDateToNumber(dur); |
| 2946 exsltDateFreeDate(dur); | 2946 exsltDateFreeDate(dur); |
| 2947 } | 2947 } |
| 2948 exsltDateFreeDate(y); | 2948 exsltDateFreeDate(y); |
| 2949 } | 2949 } |
| 2950 | 2950 |
| 2951 } else if ((dt->type == XS_DURATION) && (dt->value.dur.mon == 0)) | 2951 } else if ((dt->type == XS_DURATION) && (dt->value.dur.mon == 0)) |
| 2952 ret = exsltDateCastDateToNumber(dt); | 2952 ret = exsltDateCastDateToNumber(dt); |
| 2953 | 2953 |
| 2954 exsltDateFreeDate(dt); | 2954 exsltDateFreeDate(dt); |
| 2955 | 2955 |
| 2956 return ret; | 2956 return ret; |
| 2957 } | 2957 } |
| 2958 | 2958 |
| 2959 /** | 2959 /** |
| 2960 * exsltDateDifference: | 2960 * exsltDateDifference: |
| 2961 * @xstr: date/time string | 2961 * @xstr: date/time string |
| 2962 * @ystr: date/time string | 2962 * @ystr: date/time string |
| 2963 * | 2963 * |
| 2964 * Implements the date:difference (string,string) function which returns | 2964 * Implements the date:difference (string,string) function which returns |
| 2965 * the duration between the first date and the second date. If the first | 2965 * the duration between the first date and the second date. If the first |
| 2966 * date occurs before the second date, then the result is a positive | 2966 * date occurs before the second date, then the result is a positive |
| 2967 * duration; if it occurs after the second date, the result is a | 2967 * duration; if it occurs after the second date, the result is a |
| 2968 * negative duration. The two dates must both be right-truncated | 2968 * negative duration. The two dates must both be right-truncated |
| 2969 * date/time strings in one of the formats defined in [XML Schema Part | 2969 * date/time strings in one of the formats defined in [XML Schema Part |
| 2970 * 2: Datatypes]. The date/time with the most specific format (i.e. the | 2970 * 2: Datatypes]. The date/time with the most specific format (i.e. the |
| 2971 * least truncation) is converted into the same format as the date with | 2971 * least truncation) is converted into the same format as the date with |
| 2972 * the least specific format (i.e. the most truncation). The permitted | 2972 * the least specific format (i.e. the most truncation). The permitted |
| 2973 * formats are as follows, from most specific to least specific: | 2973 * formats are as follows, from most specific to least specific: |
| 2974 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) | 2974 * - xs:dateTime (CCYY-MM-DDThh:mm:ss) |
| 2975 * - xs:date (CCYY-MM-DD) | 2975 * - xs:date (CCYY-MM-DD) |
| 2976 * - xs:gYearMonth (CCYY-MM) | 2976 * - xs:gYearMonth (CCYY-MM) |
| 2977 * - xs:gYear (CCYY) | 2977 * - xs:gYear (CCYY) |
| 2978 * If either of the arguments is not in one of these formats, | 2978 * If either of the arguments is not in one of these formats, |
| 2979 * date:difference returns the empty string (''). | 2979 * date:difference returns the empty string (''). |
| 2980 * The difference between the date/times is returned as a string in the | 2980 * The difference between the date/times is returned as a string in the |
| 2981 * format defined for xs:duration in [3.2.6 duration] of [XML Schema | 2981 * format defined for xs:duration in [3.2.6 duration] of [XML Schema |
| 2982 * Part 2: Datatypes]. | 2982 * Part 2: Datatypes]. |
| 2983 * If the date/time string with the least specific format is in either | 2983 * If the date/time string with the least specific format is in either |
| 2984 * xs:gYearMonth or xs:gYear format, then the number of days, hours, | 2984 * xs:gYearMonth or xs:gYear format, then the number of days, hours, |
| 2985 * minutes and seconds in the duration string must be equal to zero. | 2985 * minutes and seconds in the duration string must be equal to zero. |
| 2986 * (The format of the string will be PnYnM.) The number of months | 2986 * (The format of the string will be PnYnM.) The number of months |
| 2987 * specified in the duration must be less than 12. | 2987 * specified in the duration must be less than 12. |
| 2988 * Otherwise, the number of years and months in the duration string | 2988 * Otherwise, the number of years and months in the duration string |
| 2989 * must be equal to zero. (The format of the string will be | 2989 * must be equal to zero. (The format of the string will be |
| 2990 * PnDTnHnMnS.) The number of seconds specified in the duration string | 2990 * PnDTnHnMnS.) The number of seconds specified in the duration string |
| 2991 * must be less than 60; the number of minutes must be less than 60; | 2991 * must be less than 60; the number of minutes must be less than 60; |
| 2992 * the number of hours must be less than 24. | 2992 * the number of hours must be less than 24. |
| 2993 * | 2993 * |
| 2994 * Returns duration string or NULL. | 2994 * Returns duration string or NULL. |
| 2995 */ | 2995 */ |
| 2996 static xmlChar * | 2996 static xmlChar * |
| 2997 exsltDateDifference (const xmlChar *xstr, const xmlChar *ystr) | 2997 exsltDateDifference (const xmlChar *xstr, const xmlChar *ystr) |
| 2998 { | 2998 { |
| 2999 exsltDateValPtr x, y, dur; | 2999 exsltDateValPtr x, y, dur; |
| 3000 xmlChar *ret = NULL; | 3000 xmlChar *ret = NULL; |
| 3001 | 3001 |
| 3002 if ((xstr == NULL) || (ystr == NULL)) | 3002 if ((xstr == NULL) || (ystr == NULL)) |
| 3003 return NULL; | 3003 return NULL; |
| 3004 | 3004 |
| 3005 x = exsltDateParse(xstr); | 3005 x = exsltDateParse(xstr); |
| 3006 if (x == NULL) | 3006 if (x == NULL) |
| 3007 return NULL; | 3007 return NULL; |
| 3008 | 3008 |
| 3009 y = exsltDateParse(ystr); | 3009 y = exsltDateParse(ystr); |
| 3010 if (y == NULL) { | 3010 if (y == NULL) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3033 return ret; | 3033 return ret; |
| 3034 } | 3034 } |
| 3035 | 3035 |
| 3036 /** | 3036 /** |
| 3037 * exsltDateDuration: | 3037 * exsltDateDuration: |
| 3038 * @number: a xmlChar string | 3038 * @number: a xmlChar string |
| 3039 * | 3039 * |
| 3040 * Implements the The date:duration function returns a duration string | 3040 * Implements the The date:duration function returns a duration string |
| 3041 * representing the number of seconds specified by the argument string. | 3041 * representing the number of seconds specified by the argument string. |
| 3042 * If no argument is given, then the result of calling date:seconds | 3042 * If no argument is given, then the result of calling date:seconds |
| 3043 * without any arguments is used as a default argument. | 3043 * without any arguments is used as a default argument. |
| 3044 * The duration is returned as a string in the format defined for | 3044 * The duration is returned as a string in the format defined for |
| 3045 * xs:duration in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. | 3045 * xs:duration in [3.2.6 duration] of [XML Schema Part 2: Datatypes]. |
| 3046 * The number of years and months in the duration string must be equal | 3046 * The number of years and months in the duration string must be equal |
| 3047 * to zero. (The format of the string will be PnDTnHnMnS.) The number | 3047 * to zero. (The format of the string will be PnDTnHnMnS.) The number |
| 3048 * of seconds specified in the duration string must be less than 60; | 3048 * of seconds specified in the duration string must be less than 60; |
| 3049 * the number of minutes must be less than 60; the number of hours must | 3049 * the number of minutes must be less than 60; the number of hours must |
| 3050 * be less than 24. | 3050 * be less than 24. |
| 3051 * If the argument is Infinity, -Infinity or NaN, then date:duration | 3051 * If the argument is Infinity, -Infinity or NaN, then date:duration |
| 3052 * returns an empty string (''). | 3052 * returns an empty string (''). |
| 3053 * | 3053 * |
| 3054 * Returns duration string or NULL. | 3054 * Returns duration string or NULL. |
| 3055 */ | 3055 */ |
| 3056 static xmlChar * | 3056 static xmlChar * |
| 3057 exsltDateDuration (const xmlChar *number) | 3057 exsltDateDuration (const xmlChar *number) |
| 3058 { | 3058 { |
| 3059 exsltDateValPtr dur; | 3059 exsltDateValPtr dur; |
| 3060 double secs; | 3060 double secs; |
| 3061 xmlChar *ret; | 3061 xmlChar *ret; |
| 3062 | 3062 |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3905 (const xmlChar *) EXSLT_DATE_NAMESPACE, | 3905 (const xmlChar *) EXSLT_DATE_NAMESPACE, |
| 3906 exsltDateWeekInYearFunction) | 3906 exsltDateWeekInYearFunction) |
| 3907 && !xmlXPathRegisterFuncNS(ctxt, | 3907 && !xmlXPathRegisterFuncNS(ctxt, |
| 3908 (const xmlChar *) "year", | 3908 (const xmlChar *) "year", |
| 3909 (const xmlChar *) EXSLT_DATE_NAMESPACE, | 3909 (const xmlChar *) EXSLT_DATE_NAMESPACE, |
| 3910 exsltDateYearFunction)) { | 3910 exsltDateYearFunction)) { |
| 3911 return 0; | 3911 return 0; |
| 3912 } | 3912 } |
| 3913 return -1; | 3913 return -1; |
| 3914 } | 3914 } |
| OLD | NEW |