You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sh...@apache.org on 2012/09/04 11:25:12 UTC
svn commit: r1380501 [2/4] - in /xalan/c/branches/GSoC-2012:
Projects/Win32/VC10/ Projects/Win32/VC10/AllInOne/
Projects/Win32/VC10/TestDatesAndTimes/ samples/TestDatesAndTimes/
src/xalanc/XalanDateTime/
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTime.hpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTime.hpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTime.hpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTime.hpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _XALAN_DATETIME_H
+#define _XALAN_DATETIME_H
+
+#include "XalanDateTimeDefinitons.hpp"
+
+#include "XalanCalendar.hpp"
+#include "XalanDuration.hpp"
+
+#include "XalanDateTimeMath.hpp"
+
+XALAN_CPP_NAMESPACE_BEGIN
+
+enum XalanDateTimeFormat
+ {
+ TIME, DATE, G_DAY,
+ G_YEAR, G_MONTH, DATE_TIME,
+ G_MONTH_DAY, G_YEAR_MONTH, NUM_FORMATS
+ };
+
+class XalanDateTime : public XalanCalendar<XalanDateTime>
+{
+
+public:
+
+ XalanDateTime(
+ long int year,
+ long int month,
+ long int day,
+ long int hours,
+ long int minutes,
+ double seconds,
+ const char * timeZone,
+ XalanDateTimeFormat formatType)
+ : XalanCalendar(
+ year,
+ month,
+ day,
+ hours,
+ minutes,
+ seconds),
+ timeZone(timeZone),
+ formatType(formatType)
+ {
+ }
+
+ inline int getDayInWeek()
+ {
+ // Jan 1, 2000 was Saturday
+
+ const int baseDay = 1;
+ const int baseMonth = 1;
+ const int baseYear = 2000;
+ const int baseDayOfWeek = 6;
+
+ int nDays = 0;
+
+ bool isAfterOrIsBase = year > baseYear || (year == baseYear && month > baseMonth) ||
+ (year == baseYear && month == baseMonth && day > baseDay) ||
+ (year == baseYear && month == baseMonth && day == baseDay);
+
+ int cYear = isAfterOrIsBase ? baseYear : baseYear - 1;
+ while (cYear != year)
+ {
+ nDays += cYear ? (XalanDateTimeMath::isLeapYear(cYear) ? 366 : 365) : 0;
+ cYear += isAfterOrIsBase ? 1 : -1;
+ }
+
+ nDays += isAfterOrIsBase ? getDayInYear()
+ : (XalanDateTimeMath::isLeapYear(year) ? 366 : 365) - getDayInYear() + 1;
+
+ int dayInWeek = isAfterOrIsBase ? (baseDayOfWeek + nDays - 1) % 7 : (((baseDayOfWeek - nDays) % 7) + 7) % 7;
+
+ return dayInWeek + 1;
+ }
+
+ inline int getDayOfWeekInMonth()
+ {
+ return (day / 7) + ((day % 7) ? 1 : 0);
+ }
+
+ inline int getDayInYear()
+ {
+ int dayInYear = 0;
+
+ for (int cMonth = 1; cMonth < month; cMonth++)
+ {
+ dayInYear += XalanDateTimeMath::maximumDayInMonthFor(year, cMonth);
+ }
+
+ return dayInYear + day;
+ }
+
+ inline int getWeekInYear()
+ {
+ return ((getDayInYear() - getDayInWeek() + 5) / 7) + 1;
+ }
+
+ inline int getWeekInMonth()
+ {
+ int monday = day - getDayInWeek() + 2;
+
+ return (monday / 7) + (monday > 0 && monday % 7) ? 2 : 1;
+ }
+
+ inline const char * getDayName()
+ {
+ const char * DAY_NAMES[7] =
+ {
+ "Sunday", "Monday", "Tuesday",
+ "Wednesday", "Thursday", "Friday",
+ "Saturday"
+ };
+
+ return DAY_NAMES[getDayInWeek() - 1];
+ }
+
+ inline const char * getDayAbbreviation()
+ {
+ const char * DAY_NAMES_ABBREVIATIONS[7] =
+ {
+ "Sun", "Mon", "Tue",
+ "Wed", "Thu", "Fri",
+ "Sat"
+ };
+
+ return DAY_NAMES_ABBREVIATIONS[getDayInWeek() - 1];
+ }
+
+ inline const char * getMonthName()
+ {
+ const char * MONTH_NAMES[12] =
+ {
+ "January", "February", "March",
+ "April", "May", "June",
+ "July", "August", "September",
+ "October", "November", "December"
+ };
+
+ return MONTH_NAMES[month - 1];
+ }
+
+ inline const char * getMonthAbbreviation()
+ {
+ const char * MONTH_NAMES_ABBREVIATIONS[12] =
+ {
+ "Jan", "Feb", "Mar",
+ "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep",
+ "Oct", "Nov", "Dec"
+ };
+
+ return MONTH_NAMES_ABBREVIATIONS[month - 1];
+ }
+
+ inline const char * getTimeZone() const
+ {
+ return timeZone;
+ }
+
+ inline XalanDateTimeFormat getFormatType() const
+ {
+ return formatType;
+ }
+
+ inline void setFormatType(XalanDateTimeFormat newFormatType)
+ {
+ this->formatType = newFormatType;
+ }
+
+ void addDuration(XalanDuration * duration);
+
+ XalanDuration * difference(XalanDateTime * other);
+
+ XalanCalendarIFormatter<XalanDateTime> * getFormatter();
+
+ static XalanDateTime * fromSystem(XalanDateTimeFormat format);
+
+ static XalanDateTime * fromString(const char * dateTime, XalanDateTimeFormat first, ...);
+
+private:
+
+ const char * timeZone;
+
+ XalanDateTimeFormat formatType;
+
+};
+
+XALAN_CPP_NAMESPACE_END
+
+#endif
\ No newline at end of file
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeDefinitons.hpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeDefinitons.hpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeDefinitons.hpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeDefinitons.hpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(DATETIMEDEFINITIONS_HEADER_GUARD_82838485)
+#define DATETIMEDEFINITIONS_HEADER_GUARD_82838485
+
+#include <xalanc/Include/PlatformDefinitions.hpp>
+
+#if defined(XALAN_BUILD_DLL)
+# define XALAN_DATETIME_EXPORT XALAN_PLATFORM_EXPORT
+# define XALAN_DATETIME_EXPORT_FUNCTION(T) XALAN_PLATFORM_EXPORT_FUNCTION(T)
+#else
+# define XALAN_DATETIME_EXPORT XALAN_PLATFORM_IMPORT
+# define XALAN_DATETIME_EXPORT_FUNCTION(T) XALAN_PLATFORM_IMPORT_FUNCTION(T)
+#endif
+
+#endif
\ No newline at end of file
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeExceptions.hpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeExceptions.hpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeExceptions.hpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeExceptions.hpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * This header file defines the C++ classes whose objects represent exceptions
+ * that are thrown when any XalanCalendar object is invalid, more specificaly a
+ * XalanDateTime or a XalanDuration one.
+ * It may occur when it is not correctly represented by a string or the
+ * operation that are being applied put it in an invalid state.
+ *
+ * In accordance with the classes XalanCalendar, XalanDateTime and XalanDuration
+ * defined in the model, the classes XalanInvalidCalendar, XalanInvalidDateTime,
+ * and XalanInvalidDuration were defined, respectively.
+ */
+
+#ifndef _XALAN_DATETIME_EXCEPTIONS_H
+#define _XALAN_DATETIME_EXCEPTIONS_H
+
+#include "XalanDateTimeDefinitons.hpp"
+
+#include <stdexcept>
+
+XALAN_CPP_NAMESPACE_BEGIN
+
+/**
+ * Objects of this class are exceptions that are thrown when any XalanCalendar
+ * object is invalid.
+ */
+class XalanInvalidCalendar
+ : public std::invalid_argument
+{
+
+public:
+
+ XalanInvalidCalendar()
+ : invalid_argument("No information about the cause of this exception.")
+ {
+ }
+
+ XalanInvalidCalendar(const char * message)
+ : invalid_argument(message)
+ {
+ }
+
+};
+
+/**
+ * Objects of this class are exceptions that are thrown when any XalanDateTime
+ * object is invalid.
+ */
+class XalanInvalidDateTime
+ : public XalanInvalidCalendar
+{
+
+public:
+
+ XalanInvalidDateTime()
+ : XalanInvalidCalendar()
+ {
+ }
+
+ XalanInvalidDateTime(const char * message)
+ : XalanInvalidCalendar(message)
+ {
+ }
+
+};
+
+/**
+ * Objects of this class are exceptions that are thrown when any XalanDuration
+ * object is invalid.
+ */
+class XalanInvalidDuration
+ : public XalanInvalidCalendar
+{
+
+public:
+
+ XalanInvalidDuration()
+ : XalanInvalidCalendar()
+ {
+ }
+
+ XalanInvalidDuration(const char * message)
+ : XalanInvalidCalendar(message)
+ {
+ }
+
+};
+
+XALAN_CPP_NAMESPACE_END
+
+#endif
\ No newline at end of file
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.cpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.cpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.cpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.cpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdarg.h>
+
+#include "XalanDateTime.hpp"
+#include "XalanDateTimeFormatter.hpp"
+
+XALAN_CPP_NAMESPACE_USE
+
+XalanCalendarIFormatter<XalanDateTime> * DateTimeFormatterDelegator::getFormatter(XalanDateTimeFormat format)
+{
+ switch (format)
+ {
+ case TIME:
+ return TimeFormatter::getInstance();
+ case DATE:
+ return DateFormatter::getInstance();
+ case G_DAY:
+ return GDayFormatter::getInstance();
+ case G_YEAR:
+ return GYearFormatter::getInstance();
+ case G_MONTH:
+ return GMonthFormatter::getInstance();
+ case DATE_TIME:
+ return DateTimeFormatter::getInstance();
+ case G_MONTH_DAY:
+ return GMonthDayFormatter::getInstance();
+ case G_YEAR_MONTH:
+ return GYearMonthFormatter::getInstance();
+ default:
+ return 0;
+ }
+}
+
+char * DateTimeFormatterDelegator::createString(XalanDateTime * time)
+{
+ return getFormatter(time->getFormatType())->createString(time);
+}
+
+XalanDateTime * DateTimeFormatterDelegator::createInstance(const char * dateTime)
+{
+ return createInstance(dateTime,
+ TIME, DATE,
+ G_DAY, G_YEAR,
+ G_MONTH, DATE_TIME,
+ G_MONTH_DAY, G_YEAR_MONTH);
+}
+
+XalanDateTime * DateTimeFormatterDelegator::createInstance(const char * dateTime, XalanDateTimeFormat first, ...)
+{
+ va_list ap;
+ va_start(ap, first);
+
+ XalanDateTimeFormat format = first;
+ do
+ {
+ try
+ {
+ return getFormatter(format)->createInstance(dateTime);
+ }
+ catch (XalanInvalidCalendar & invalidCalendar)
+ {
+ continue;
+ }
+ } while ((format = va_arg(ap, XalanDateTimeFormat)) < NUM_FORMATS && format >= 0);
+
+ va_end(ap);
+
+ throw XalanInvalidDateTime("");
+}
+
+char * TimeFormatter::createString(XalanDateTime * time)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(gYyMn, "%02ld:%02ld:%s", time->getHours(),
+ time->getMinutes(), getFormattedSeconds(time->getSeconds()));
+
+ return strcat(gYyMn, time->getTimeZone());
+}
+
+XalanDateTime * TimeFormatter::createInstance(const char * time)
+{
+ long int hours = getHours(& time); // HH
+ checkSeparator(& time, TMS_SYM); // :
+ long int minutes = getMinutes(& time); // MM
+ checkSeparator(& time, TMS_SYM); // :
+ double seconds = getSeconds(& time); // SS
+ checkTime(hours, minutes, seconds);
+
+ return new XalanDateTime(1, 1, 1, hours, minutes, seconds,
+ getTimeZone(& time), TIME);
+}
+
+char * DateFormatter::createString(XalanDateTime * date)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(date->getYear() < 0 && (*gYyMn = '-') ? gYyMn + 1 : gYyMn,
+ "%04ld-%02ld-%02ld", abs(date->getYear()), date->getMonth(),
+ date->getDay());
+
+ return strcat(gYyMn, date->getTimeZone());
+}
+
+XalanDateTime * DateFormatter::createInstance(const char * date)
+{
+ long int year = getYear(& date); // CCYY
+ checkSeparator(& date, DTS_SYM); // -
+ long int month = getMonth(& date); // MM
+ checkSeparator(& date, DTS_SYM); // -
+ long int day = getDay(& date); // DD
+ checkDay(year, month, day);
+
+ return new XalanDateTime(year, month, day, 0, 0, 0.0,
+ getTimeZone(& date), DATE);
+}
+
+char * GDayFormatter::createString(XalanDateTime * gDay)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(gYyMn, "---%02ld", gDay->getDay());
+
+ return strcat(gYyMn, gDay->getTimeZone());
+}
+
+XalanDateTime * GDayFormatter::createInstance(const char * gDay)
+{
+ checkSeparator(& gDay, DTS_SYM); // -
+ checkSeparator(& gDay, DTS_SYM); // -
+ checkSeparator(& gDay, DTS_SYM); // -
+ long int day = getDay(& gDay); // DD
+
+ return new XalanDateTime(1, 1, day, 0, 0, 0.0,
+ getTimeZone(& gDay), G_DAY);
+}
+
+char * GYearFormatter::createString(XalanDateTime * gYear)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(gYear->getYear() < 0 && (*gYyMn = '-') ? gYyMn + 1 : gYyMn,
+ "%04ld", abs(gYear->getYear()));
+
+ return strcat(gYyMn, gYear->getTimeZone());
+}
+
+XalanDateTime * GYearFormatter::createInstance(const char * gYear)
+{
+ long int year = getYear(& gYear); // CCYY
+
+ return new XalanDateTime(year, 1, 1, 0, 0, 0.0,
+ getTimeZone(& gYear), G_YEAR);
+}
+
+char * GMonthFormatter::createString(XalanDateTime * gMonth)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(gYyMn, "--%02ld", gMonth->getMonth());
+
+ return strcat(gYyMn, gMonth->getTimeZone());
+}
+
+XalanDateTime * GMonthFormatter::createInstance(const char * gMonth)
+{
+ checkSeparator(& gMonth, DTS_SYM); // -
+ checkSeparator(& gMonth, DTS_SYM); // -
+ long int month = getMonth(& gMonth); // MM
+
+ return new XalanDateTime(1, month, 1, 0, 0, 0.0,
+ getTimeZone(& gMonth), G_MONTH);
+}
+
+char * DateTimeFormatter::createString(XalanDateTime * dateTime)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(dateTime->getYear() < 0 && (*gYyMn = '-') ? gYyMn + 1 : gYyMn,
+ "%04ld-%02ld-%02ldT%02ld:%02ld:%s", abs(dateTime->getYear()), dateTime->getMonth(),
+ dateTime->getDay(), dateTime->getHours(),
+ dateTime->getMinutes(), getFormattedSeconds(dateTime->getSeconds()));
+
+ return strcat(gYyMn, dateTime->getTimeZone());
+}
+
+XalanDateTime * DateTimeFormatter::createInstance(const char * dateTime)
+{
+ long int year = getYear(& dateTime); // CCYY
+ checkSeparator(& dateTime, DTS_SYM); // -
+ long int month = getMonth(& dateTime); // MM
+ checkSeparator(& dateTime, DTS_SYM); // -
+ long int day = getDay(& dateTime); // DD
+ checkDay(year, month, day);
+ checkSeparator(& dateTime, DTTMS_SYM); // T
+ long int hours = getHours(& dateTime); // HH
+ checkSeparator(& dateTime, TMS_SYM); // :
+ long int minutes = getMinutes(& dateTime); // MM
+ checkSeparator(& dateTime, TMS_SYM); // :
+ double seconds = getSeconds(& dateTime); // SS
+ checkTime(hours, minutes, seconds);
+
+ return new XalanDateTime(year, month, day, hours, minutes, seconds,
+ getTimeZone(& dateTime), DATE_TIME);
+}
+
+char * GMonthDayFormatter::createString(XalanDateTime * gMonthDay)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(gYyMn, "--%02ld-%02ld", gMonthDay->getMonth(), gMonthDay->getDay());
+
+ return strcat(gYyMn, gMonthDay->getTimeZone());
+}
+
+XalanDateTime * GMonthDayFormatter::createInstance(const char * gMonthDay)
+{
+ checkSeparator(& gMonthDay, DTS_SYM); // -
+ checkSeparator(& gMonthDay, DTS_SYM); // -
+ long int month = getMonth(& gMonthDay); // MM
+ checkSeparator(& gMonthDay, DTS_SYM); // -
+ long int day = getDay(& gMonthDay); // DD
+ checkDay(-0001, month, day);
+
+ return new XalanDateTime(1, month, day, 0, 0, 0.0,
+ getTimeZone(& gMonthDay), G_MONTH_DAY);
+}
+
+char * GYearMonthFormatter::createString(XalanDateTime * gYearMonth)
+{
+ char * gYyMn = new char[30];
+
+ sprintf(gYearMonth->getYear() < 0 && (*gYyMn = '-') ? gYyMn + 1 : gYyMn,
+ "%04ld-%02ld", abs(gYearMonth->getYear()), gYearMonth->getMonth());
+
+ return strcat(gYyMn, gYearMonth->getTimeZone());
+}
+
+XalanDateTime * GYearMonthFormatter::createInstance(const char * gYearMonth)
+{
+ long int year = getYear(& gYearMonth); // CCYY
+ checkSeparator(& gYearMonth, DTS_SYM); // -
+ long int month = getMonth(& gYearMonth); // MM
+
+ return new XalanDateTime(year, month, 1, 0, 0, 0.0,
+ getTimeZone(& gYearMonth), G_YEAR_MONTH);
+}
\ No newline at end of file
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.hpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.hpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.hpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFormatter.hpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _XALAN_DATETIME_FORMATTER_H
+#define _XALAN_DATETIME_FORMATTER_H
+
+#include "XalanDateTimeDefinitons.hpp"
+
+#include "XalanDateTime.hpp"
+#include "XalanDateTimeMath.hpp"
+#include "XalanCalendarFormatter.hpp"
+
+XALAN_CPP_NAMESPACE_BEGIN
+
+template <typename T> class XalanDateTimeFormatter
+ : public XalanCalendarFormatter<T>,
+ public XalanCalendarIFormatter<XalanDateTime>
+{
+
+public:
+
+ enum DateTimeSymbols
+ {
+ DTS_SYM = '-',
+ TMS_SYM = ':',
+ UTC_TMZN_SYM = 'Z'
+ };
+
+protected:
+
+ long int getYear(const char ** dateTime)
+ {
+ bool negative = (**dateTime == '-') && ++(*dateTime);
+
+ int nLength;
+ long double ten = 10;
+ getNumberInfo(*dateTime, &nLength);
+ long int year = getInteger(dateTime, 4, true, 1);
+ if (nLength > 4 && (year < pow((double) 10, (double) (nLength -1))))
+ {
+ throw XalanInvalidDateTime("");
+ }
+
+ return negative
+ ? -year
+ : year;
+ }
+
+ long int getMonth(const char ** dateTime)
+ {
+ return getInteger(dateTime, 2, false, 1, 12);
+ }
+
+ long int getDay(const char ** dateTime)
+ {
+ return getInteger(dateTime, 2, false, 1, 31);
+ }
+
+ long int getHours(const char ** dateTime)
+ {
+ return getInteger(dateTime, 2, false, 0, 24);
+ }
+
+ long int getMinutes(const char ** dateTime)
+ {
+ return getInteger(dateTime, 2, false, 0, 59);
+ }
+
+ double getSeconds(const char ** dateTime)
+ {
+ return getDouble(dateTime, 2, 0.0, 59.999);
+ }
+
+ void checkDay(long int year, long int month, long int day)
+ {
+ if (day > XalanDateTimeMath::maximumDayInMonthFor(year, month))
+ {
+ throw XalanInvalidDateTime("");
+ }
+ }
+
+ void checkTime(long int hours, long int minutes, double seconds)
+ {
+ if (hours == 24 && (minutes + seconds))
+ {
+ throw XalanInvalidDateTime("");
+ }
+ }
+
+ void checkSeparator(const char ** dateTime, const char separator)
+ {
+ checkChar(dateTime, separator, true);
+ }
+
+ const char * getTimeZone(const char ** dateTime)
+ {
+ const char * timeZone = *dateTime;
+
+ long int hours = 0;
+ long int minutes = 0;
+ if (**dateTime && !checkChar(dateTime, 'Z', false))
+ {
+ if (!checkChar(dateTime, '+', false))
+ {
+ checkChar(dateTime, '-', true);
+ }
+
+ hours = getHours(dateTime);
+ checkSeparator(dateTime, ':');
+ minutes = getMinutes(dateTime);
+ }
+
+ if (**dateTime
+ || hours > 14
+ || (hours == 14 && minutes))
+ {
+ throw XalanInvalidDateTime("");
+ }
+
+ return timeZone;
+ }
+
+ char * getFormattedSeconds(double seconds)
+ {
+ char * formattedNumber = new char [12];
+ sprintf(formattedNumber, "%02g", seconds);
+
+ int nLength;
+ int pointAt = getNumberInfo(formattedNumber, &nLength);
+
+ char * format = new char[5];
+ sprintf(format, "%%0%dg", pointAt ? (pointAt != 2 ? nLength : nLength + 1) : 2);
+
+ sprintf(formattedNumber, format, seconds);
+
+ return formattedNumber;
+ }
+
+private:
+
+ long int getInteger(const char ** pInfo, int eLength, bool maybeLarger, int lowerBound, int upperBound = 2147483647)
+ {
+ long int integer = XalanCalendarFormatter::getInteger(pInfo, eLength, maybeLarger);
+
+ if (integer < lowerBound || integer > upperBound)
+ {
+ throw XalanInvalidCalendar("");
+ }
+
+ return integer;
+ }
+
+ double getDouble(const char ** pInfo, int eLength, double lowerBound, double upperBound)
+ {
+ double dbl = XalanCalendarFormatter::getDouble(pInfo, eLength);
+
+ if (dbl < lowerBound || dbl > upperBound)
+ {
+ throw XalanInvalidCalendar("");
+ }
+
+ return dbl;
+ }
+
+};
+
+class DateTimeFormatterDelegator : public XalanDateTimeFormatter<DateTimeFormatterDelegator>
+{
+
+public:
+
+ char * createString(XalanDateTime * dateTime);
+
+ XalanDateTime * createInstance(const char * dateTime);
+
+ XalanDateTime * createInstance(const char * dateTime, XalanDateTimeFormat first, ...);
+
+private:
+
+ XalanCalendarIFormatter<XalanDateTime> * getFormatter(XalanDateTimeFormat format);
+
+};
+
+class TimeFormatter : public XalanDateTimeFormatter<TimeFormatter>
+{
+public:
+ char * createString(XalanDateTime * time);
+
+ XalanDateTime * createInstance(const char * time);
+
+};
+
+class DateFormatter : public XalanDateTimeFormatter<DateFormatter>
+{
+public:
+
+ char * createString(XalanDateTime * date);
+
+ XalanDateTime * createInstance(const char * date);
+
+};
+
+class GDayFormatter : public XalanDateTimeFormatter<GDayFormatter>
+{
+public:
+
+ char * createString(XalanDateTime * gDay);
+
+ XalanDateTime * createInstance(const char * gDay);
+
+};
+
+class GYearFormatter : public XalanDateTimeFormatter<GYearFormatter>
+{
+public:
+
+ char * createString(XalanDateTime * gYear);
+
+ XalanDateTime * createInstance(const char * gYear);
+
+};
+
+class GMonthFormatter : public XalanDateTimeFormatter<GMonthFormatter>
+{
+public:
+
+ char * createString(XalanDateTime * gMonth);
+
+ XalanDateTime * createInstance(const char * gMonth);
+
+};
+
+class DateTimeFormatter : public XalanDateTimeFormatter<DateTimeFormatter>
+{
+public:
+
+ char * createString(XalanDateTime * dateTime);
+
+ XalanDateTime * createInstance(const char * dateTime);
+
+};
+
+class GMonthDayFormatter : public XalanDateTimeFormatter<GMonthDayFormatter>
+{
+public:
+
+ char * createString(XalanDateTime * gMonthDay);
+
+ XalanDateTime * createInstance(const char * gMonthDay);
+
+};
+
+class GYearMonthFormatter : public XalanDateTimeFormatter<GYearMonthFormatter>
+{
+public:
+
+ char * createString(XalanDateTime * gYearMonth);
+
+ XalanDateTime * createInstance(const char * gYearMonth);
+
+};
+
+XALAN_CPP_NAMESPACE_END
+
+#endif _XALANDATETIMEFORMATTER_H
\ No newline at end of file
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.cpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.cpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.cpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.cpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "XalanDateTimeFunction.hpp"
+
+#include <xalanc/Include/XalanVector.hpp>
+#include <xalanc/XPath/XObjectFactory.hpp>
+#include <xalanc/Include/XalanVersion.hpp>
+#include <xalanc/XalanDOM/XalanDOMString.hpp>
+#include <xalanc/PlatformSupport/XalanMessageLoader.hpp>
+
+XALAN_CPP_NAMESPACE_BEGIN
+
+XalanDateTimeFunction::XalanDateTimeFunction()
+ : Function()
+{
+}
+
+XalanDateTimeFunction::~XalanDateTimeFunction()
+{
+}
+
+#if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
+ Function*
+#else
+ XalanDateTimeFunction*
+#endif
+XalanDateTimeFunction::clone(MemoryManagerType& theManager) const
+{
+ return XalanCopyConstruct(theManager, *this);
+}
+
+XObjectPtr XalanDateTimeFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectArgVectorType & args,
+ const LocatorType * locator) const
+{
+ const XObjectArgVectorType::size_type theArgCount = args.size();
+
+ if (theArgCount == 0)
+ {
+ return execute(executionContext, context, locator);
+ }
+ else if (theArgCount == 1)
+ {
+ return execute(executionContext, context, args[0], locator);
+ }
+ else if (theArgCount == 2)
+ {
+ return execute(executionContext, context, args[0], args[1], locator);
+ }
+
+ throwDefaultError(context, locator, executionContext);
+
+ return XObjectPtr(0);
+}
+
+/*
+ * Execute with No Arguments
+ */
+
+XObjectPtr
+XalanDateTimeFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const LocatorType * locator) const
+{
+ throwDefaultError(context, locator, executionContext);
+
+ return XObjectPtr(0);
+}
+
+/*
+ * Execute with One Argument
+ */
+
+XObjectPtr
+XalanDateTimeFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const LocatorType * locator) const
+{
+ throwDefaultError(context, locator, executionContext);
+
+ return XObjectPtr(0);
+}
+
+
+/*
+ * Execute with Two Arguments
+ */
+
+XObjectPtr
+XalanDateTimeFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const XObjectPtr arg2,
+ const LocatorType * locator) const
+{
+ throwDefaultError(context, locator, executionContext);
+
+ return XObjectPtr(0);
+}
+
+void XalanDateTimeFunction::throwDefaultError(
+ XalanNode * context,
+ const LocatorType * locator,
+ XPathExecutionContext & executionContext) const
+{
+ XalanDOMString theBuffer(executionContext.getMemoryManager());
+
+ #if (_XALAN_VERSION == 11000)
+ executionContext.error(getError(theBuffer), context, locator);
+ #elif (_XALAN_VERSION >= 11100)
+ executionContext.problem(
+ XPathExecutionContext::eXPath,
+ XPathExecutionContext::eError,
+ getError(theBuffer),
+ locator, context);
+ #elif (_XALAN_VERSION < 11000)
+ #error "XALAN Library Version must be 1_10 or newer"
+ #endif
+}
+
+const XalanDOMString&
+XalanDateTimeFunction::getError(XalanDOMString& theResult) const
+{
+ return XalanMessageLoader::getMessage(
+ theResult,
+ XalanMessages::FunctionTakesTwoOrThreeArguments_1Param,
+ "TheFunctionName()");
+}
+
+XALAN_CPP_NAMESPACE_END
\ No newline at end of file
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.hpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.hpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.hpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunction.hpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * This header file defines the C++ class that implement the default behavior of
+ * a EXSLT Dates and Times library function.
+ *
+ * These functions inherits the behavior from the Function class located at
+ * 'xalanc/XPath/'. The execute(..., XObjectArgVectorType & args, ...) method
+ * is overriden, calling any other execute(...) method, according the number of
+ * available arguments into the 'args' parameter received.
+ *
+ * There are Dates and Times EXSLT functions that receive one, two or no
+ * arguments. If any other function with more than two arguments have to be
+ * added, then the method receiving the XObjectArgVectorType argument have to be
+ * overriden.
+ */
+
+#ifndef _XALAN_DATETIME_FUNCTION_H
+#define _XALAN_DATETIME_FUNCTION_H
+
+#include "XalanDateTimeDefinitons.hpp"
+
+#include <xalanc/XPath/Function.hpp>
+
+#include <xalanc/XPath/XObjectFactory.hpp>
+
+XALAN_CPP_NAMESPACE_BEGIN
+
+/**
+ * This is the base class for Xalan Dates and Times EXSLT functions
+ *
+ * This base function inherits the behavior from the Function class located at
+ * 'xalanc/XPath/'. The execute(..., XObjectArgVectorType & args, ...) method
+ * is overriden, calling any other execute(...) method of the subclass,
+ * according the number of available arguments into the 'args' parameter
+ * received. Each subclass have to override the correct execute(...) method,
+ * according the number of arguments it expects to receive.
+ */
+class XalanDateTimeFunction
+ : public Function
+{
+
+public:
+
+ XalanDateTimeFunction();
+
+ virtual
+ ~XalanDateTimeFunction();
+
+ #if !defined(XALAN_NO_USING_DECLARATION)
+ using Function::execute;
+ #endif
+
+ virtual XObjectPtr
+ execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectArgVectorType & args,
+ const LocatorType * locator) const;
+
+ virtual XObjectPtr
+ execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const LocatorType * locator) const;
+
+ virtual XObjectPtr
+ execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const;
+
+ virtual XObjectPtr
+ execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const XObjectPtr arg2,
+ const LocatorType * locator) const;
+
+ #if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
+ virtual Function*
+ #else
+ virtual XalanDateTimeFunction*
+ #endif
+ clone(MemoryManagerType & theManager) const;
+
+protected:
+
+ /**
+ * This method propagate a XPath exception with a default message
+ *
+ * The default message propagated alerts that the function was called
+ * with a wrong number of parameters.
+ *
+ * @param context The XPath context.
+ *
+ * @param locator The locator type.
+ *
+ * @param executionContext The XPath execution context.
+ *
+ * @exception An exception with the default message is always thrown into
+ * the XPath execution context.
+ */
+ void throwDefaultError(
+ XalanNode * context,
+ const LocatorType * locator,
+ XPathExecutionContext & executionContext) const;
+
+ virtual const XalanDOMString & getError(
+ XalanDOMString & theResult) const;
+
+};
+
+XALAN_CPP_NAMESPACE_END
+
+#endif
\ No newline at end of file
Added: xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunctions.cpp
URL: http://svn.apache.org/viewvc/xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunctions.cpp?rev=1380501&view=auto
==============================================================================
--- xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunctions.cpp (added)
+++ xalan/c/branches/GSoC-2012/src/xalanc/XalanDateTime/XalanDateTimeFunctions.cpp Tue Sep 4 09:25:11 2012
@@ -0,0 +1,1107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "XalanDateTime.hpp"
+#include "XalanDuration.hpp"
+
+#include "XalanDateTimeMath.hpp"
+#include "XalanDateTimeFunctions.hpp"
+#include "XalanDateTimeExceptions.hpp"
+
+XALAN_CPP_NAMESPACE_USE
+
+XObjectPtr
+XalanDTOptionalParameterFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const LocatorType * locator) const
+{
+ XalanDOMString theArgument(XalanDateTime::fromSystem(DATE_TIME)->toString());
+
+ return execute(executionContext,
+ context,
+ executionContext.getXObjectFactory().createString(theArgument),
+ locator);
+}
+
+XalanDTAddFunction::XalanDTAddFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTAddFunction::~XalanDTAddFunction()
+{
+}
+
+XObjectPtr
+XalanDTAddFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const XObjectPtr arg2,
+ const LocatorType * locator) const
+{
+ XalanDateTime * dateTime;
+
+ try
+ {
+ dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg1->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR);
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ // TODO Report error
+ }
+
+ XalanDuration * duration;
+
+ try
+ {
+ duration = XalanDuration::fromString(
+ TranscodeToLocalCodePage(arg2->str()).begin());
+ }
+ catch (XalanInvalidDuration & xid)
+ {
+ // TODO Report error
+ }
+
+ dateTime->addDuration(duration);
+
+ XalanDOMString theResult(dateTime->toString());
+
+ delete dateTime;
+ delete duration;
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTAddDurationFunction::XalanDTAddDurationFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTAddDurationFunction::~XalanDTAddDurationFunction()
+{
+}
+
+XObjectPtr
+XalanDTAddDurationFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const XObjectPtr arg2,
+ const LocatorType * locator) const
+{
+ XalanDuration * fDuration;
+ XalanDuration * sDuration;
+
+ char * rDuration;
+ try
+ {
+ fDuration = XalanDuration::fromString(
+ TranscodeToLocalCodePage(arg1->str()).begin());
+
+ sDuration = XalanDuration::fromString(
+ TranscodeToLocalCodePage(arg2->str()).begin());
+
+ fDuration->add(sDuration);
+
+ rDuration = fDuration->toString();
+ }
+ catch (XalanInvalidDuration & xid)
+ {
+ rDuration = "";
+ }
+
+ XalanDOMString theResult(rDuration);
+
+ delete fDuration;
+ delete sDuration;
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTDateFunction::XalanDTDateFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTDateFunction::~XalanDTDateFunction()
+{
+}
+
+XObjectPtr
+XalanDTDateFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ char * rDate;
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ dateTime->setFormatType(DATE);
+
+ rDate = dateTime->toString();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDuration & xid)
+ {
+ rDate = "";
+ }
+
+ XalanDOMString theResult(rDate);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTDateTimeFunction::XalanDTDateTimeFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTDateTimeFunction::~XalanDTDateTimeFunction()
+{
+}
+
+XObjectPtr
+XalanDTDateTimeFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const LocatorType * locator) const
+{
+ XalanDOMString theResult(XalanDateTime::fromSystem(DATE_TIME)->toString());
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTDayAbbreviationFunction::XalanDTDayAbbreviationFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTDayAbbreviationFunction::~XalanDTDayAbbreviationFunction()
+{
+}
+
+XObjectPtr
+XalanDTDayAbbreviationFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ const char * rDayAbbreviation;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ rDayAbbreviation = dateTime->getDayAbbreviation();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ rDayAbbreviation = "";
+ }
+
+ XalanDOMString theResult(rDayAbbreviation);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTDayInMonthFunction::XalanDTDayInMonthFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTDayInMonthFunction::~XalanDTDayInMonthFunction()
+{
+}
+
+XObjectPtr
+XalanDTDayInMonthFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double dayInMonth = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE, G_MONTH_DAY, G_DAY);
+
+ dayInMonth = dateTime->getDay();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ dayInMonth = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(dayInMonth);
+}
+
+XalanDTDayInWeekFunction::XalanDTDayInWeekFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTDayInWeekFunction::~XalanDTDayInWeekFunction()
+{
+}
+
+XObjectPtr
+XalanDTDayInWeekFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double dayInWeek = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ dayInWeek = dateTime->getDayInWeek();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ dayInWeek = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(dayInWeek);
+}
+
+XalanDTDayInYearFunction::XalanDTDayInYearFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTDayInYearFunction::~XalanDTDayInYearFunction()
+{
+}
+
+XObjectPtr
+XalanDTDayInYearFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double dayInYear = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ dayInYear = dateTime->getDayInYear();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ dayInYear = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(dayInYear);
+}
+
+XalanDTDayNameFunction::XalanDTDayNameFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTDayNameFunction::~XalanDTDayNameFunction()
+{
+}
+
+XObjectPtr
+XalanDTDayNameFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ const char * dayName;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ dayName = dateTime->getDayName();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ dayName = "";
+ }
+
+ XalanDOMString theResult(dayName);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTDayOfWeekInMonthFunction::XalanDTDayOfWeekInMonthFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTDayOfWeekInMonthFunction::~XalanDTDayOfWeekInMonthFunction()
+{
+}
+
+XObjectPtr
+XalanDTDayOfWeekInMonthFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double dayOfWeekInMonth = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ dayOfWeekInMonth = dateTime->getDayOfWeekInMonth();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ dayOfWeekInMonth = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(dayOfWeekInMonth);
+}
+
+XalanDTDifferenceFunction::XalanDTDifferenceFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTDifferenceFunction::~XalanDTDifferenceFunction()
+{
+}
+
+XObjectPtr
+XalanDTDifferenceFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const XObjectPtr arg2,
+ const LocatorType * locator) const
+{
+ XalanDateTime * fDateTime;
+ XalanDateTime * sDateTime;
+
+ char * rDuration;
+ try
+ {
+ fDateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg1->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR);
+
+ sDateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg2->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR);
+
+ XalanDuration * duration = fDateTime->difference(sDateTime);
+
+ duration->setFormatType(
+ (fDateTime->getFormatType() == G_YEAR_MONTH
+ || sDateTime->getFormatType() == G_YEAR_MONTH
+ || fDateTime->getFormatType() == G_YEAR
+ || sDateTime->getFormatType() == G_YEAR)
+ ? YEAR_MONTH : DAY_AND_TIME);
+
+ duration->normalizeAttributes();
+
+ rDuration = duration->toString();
+
+ delete duration;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ rDuration = "";
+ }
+
+ delete fDateTime;
+ delete sDateTime;
+
+ XalanDOMString theResult(rDuration);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTDurationFunction::XalanDTDurationFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTDurationFunction::~XalanDTDurationFunction()
+{
+}
+
+XObjectPtr
+XalanDTDurationFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const LocatorType * locator) const
+{
+ XalanDTSecondsFunction * dtSecondsFunction = new XalanDTSecondsFunction();
+
+ XObjectPtr secondsObject = ((XalanDTOptionalParameterFunction *) dtSecondsFunction)->execute(
+ executionContext,
+ context,
+ locator);
+
+ delete dtSecondsFunction;
+
+ return XalanDTDurationFunction::execute(
+ executionContext,
+ context,
+ secondsObject,
+ locator);
+}
+
+XObjectPtr
+XalanDTDurationFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ XalanDuration * duration;
+
+ char * rDuration;
+ try
+ {
+ duration = new XalanDuration(0, 0, 0, 0, 0, arg->num());
+
+ duration->setFormatType(DAY_AND_TIME);
+
+ duration->normalizeAttributes();
+
+ rDuration = duration->toString();
+
+ delete duration;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ rDuration = "";
+ }
+
+ delete duration;
+
+ XalanDOMString theResult(rDuration);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTFormatDateFunction::XalanDTFormatDateFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTFormatDateFunction::~XalanDTFormatDateFunction()
+{
+}
+
+XObjectPtr
+XalanDTFormatDateFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const XObjectPtr arg2,
+ const LocatorType * locator) const
+{
+ return XObjectPtr(0);
+}
+
+XalanDTHourInDayFunction::XalanDTHourInDayFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTHourInDayFunction::~XalanDTHourInDayFunction()
+{
+}
+
+XObjectPtr
+XalanDTHourInDayFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double hourInDay = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, TIME);
+
+ hourInDay = dateTime->getHours();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ hourInDay = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(hourInDay);
+}
+
+XalanDTLeapYearFunction::XalanDTLeapYearFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTLeapYearFunction::~XalanDTLeapYearFunction()
+{
+}
+
+XObjectPtr
+XalanDTLeapYearFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ bool leapYear = false;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR);
+
+ leapYear = XalanDateTimeMath::isLeapYear(dateTime->getYear());
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ return executionContext.getXObjectFactory().createNumber(XalanDateTimeMath::NAN);
+ }
+
+ return executionContext.getXObjectFactory().createBoolean(leapYear);
+}
+
+XalanDTMinuteInHourFunction::XalanDTMinuteInHourFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTMinuteInHourFunction::~XalanDTMinuteInHourFunction()
+{
+}
+
+XObjectPtr
+XalanDTMinuteInHourFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double minuteInHour = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, TIME);
+
+ minuteInHour = dateTime->getMinutes();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ minuteInHour = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(minuteInHour);
+}
+
+XalanDTMonthAbbreviationFunction::XalanDTMonthAbbreviationFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTMonthAbbreviationFunction::~XalanDTMonthAbbreviationFunction()
+{
+}
+
+XObjectPtr
+XalanDTMonthAbbreviationFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ const char * monthAbbreviation;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH, G_MONTH);
+
+ monthAbbreviation = dateTime->getMonthAbbreviation();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ monthAbbreviation = "";
+ }
+
+ XalanDOMString theResult(monthAbbreviation);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTMonthInYearFunction::XalanDTMonthInYearFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTMonthInYearFunction::~XalanDTMonthInYearFunction()
+{
+}
+
+XObjectPtr
+XalanDTMonthInYearFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double monthInYear = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH,
+ G_MONTH, G_MONTH_DAY);
+
+ monthInYear = dateTime->getMonth();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ monthInYear = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(monthInYear);
+}
+
+XalanDTMonthNameFunction::XalanDTMonthNameFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTMonthNameFunction::~XalanDTMonthNameFunction()
+{
+}
+
+XObjectPtr
+XalanDTMonthNameFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ const char * monthName;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH,
+ G_MONTH);
+
+ monthName = dateTime->getMonthName();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ monthName = "";
+ }
+
+ XalanDOMString theResult(monthName);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTParseDateFunction::XalanDTParseDateFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTParseDateFunction::~XalanDTParseDateFunction()
+{
+}
+
+XObjectPtr
+XalanDTParseDateFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg1,
+ const XObjectPtr arg2,
+ const LocatorType * locator) const
+{
+ return XObjectPtr(0);
+}
+
+XalanDTSecondInMinuteFunction::XalanDTSecondInMinuteFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTSecondInMinuteFunction::~XalanDTSecondInMinuteFunction()
+{
+}
+
+XObjectPtr
+XalanDTSecondInMinuteFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double secondInMinute = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, TIME);
+
+ secondInMinute = dateTime->getSeconds();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ secondInMinute = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(secondInMinute);
+}
+
+XalanDTSecondsFunction::XalanDTSecondsFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTSecondsFunction::~XalanDTSecondsFunction()
+{
+}
+
+XObjectPtr
+XalanDTSecondsFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double seconds = 0.0;
+
+ XalanDuration * duration;
+
+ XalanDateTime * dateTime;
+ XalanDateTime * baseDateTime;
+
+ try
+ {
+ dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR);
+
+ baseDateTime = XalanDateTime::fromString(
+ "1970-01-01T00:00:00Z", DATE_TIME);
+
+ duration = dateTime->difference(baseDateTime);
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ try
+ {
+ duration = XalanDuration::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin());
+
+ if (duration->getYear() + duration->getMonth())
+ {
+ throw XalanInvalidDuration();
+ }
+ }
+ catch (XalanInvalidDuration & xid)
+ {
+ return executionContext.getXObjectFactory().
+ createNumber(XalanDateTimeMath::NAN);
+ }
+ }
+
+ seconds = duration->getTotalOfSeconds();
+
+ delete duration;
+ delete dateTime;
+ delete baseDateTime;
+
+ return executionContext.getXObjectFactory().createNumber(seconds);
+}
+
+
+XalanDTSumFunction::XalanDTSumFunction()
+ : XalanDateTimeFunction()
+{
+}
+
+XalanDTSumFunction::~XalanDTSumFunction()
+{
+}
+
+XObjectPtr
+XalanDTSumFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectArgVectorType & args,
+ const LocatorType* locator) const
+{
+ const XObjectArgVectorType::size_type theArgCount = args.size();
+
+ char * rDuration;
+ if (theArgCount != 0)
+ {
+ XalanDuration * fDuration;
+ XalanDuration * sDuration;
+
+ try
+ {
+ fDuration = XalanDuration::fromString(
+ TranscodeToLocalCodePage(args[0]->str()).begin());
+
+ for (int iArg = 1; iArg < theArgCount; iArg ++)
+ {
+ fDuration->add(sDuration = XalanDuration::fromString(
+ TranscodeToLocalCodePage(args[iArg]->str()).begin()));
+
+ delete sDuration;
+ }
+
+ rDuration = fDuration->toString();
+ }
+ catch (XalanInvalidDuration & xid)
+ {
+ rDuration = "";
+ }
+
+ delete fDuration;
+ delete sDuration;
+ }
+ else
+ {
+ rDuration = "";
+ }
+
+ XalanDOMString theResult(rDuration);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTTimeFunction::XalanDTTimeFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTTimeFunction::~XalanDTTimeFunction()
+{
+}
+
+XObjectPtr
+XalanDTTimeFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ char * rTime;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, TIME);
+
+ dateTime->setFormatType(TIME);
+
+ rTime = dateTime->toString();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDuration & xid)
+ {
+ rTime = "";
+ }
+
+ XalanDOMString theResult(rTime);
+
+ return executionContext.getXObjectFactory().createString(theResult);
+}
+
+XalanDTWeekInMonthFunction::XalanDTWeekInMonthFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTWeekInMonthFunction::~XalanDTWeekInMonthFunction()
+{
+}
+
+XObjectPtr
+XalanDTWeekInMonthFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double weekInMonth = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ weekInMonth = dateTime->getWeekInMonth();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ weekInMonth = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(weekInMonth);
+}
+
+XalanDTWeekInYearFunction::XalanDTWeekInYearFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTWeekInYearFunction::~XalanDTWeekInYearFunction()
+{
+}
+
+XObjectPtr
+XalanDTWeekInYearFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double weekInYear = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE);
+
+ weekInYear = dateTime->getWeekInYear();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ weekInYear = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(weekInYear);
+}
+
+XalanDTYearFunction::XalanDTYearFunction()
+ : XalanDTOptionalParameterFunction()
+{
+}
+
+XalanDTYearFunction::~XalanDTYearFunction()
+{
+}
+
+XObjectPtr
+XalanDTYearFunction::execute(
+ XPathExecutionContext & executionContext,
+ XalanNode * context,
+ const XObjectPtr arg,
+ const LocatorType * locator) const
+{
+ double year = 0.0;
+
+ try
+ {
+ XalanDateTime * dateTime = XalanDateTime::fromString(
+ TranscodeToLocalCodePage(arg->str()).begin(),
+ DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR);
+
+ year = dateTime->getYear();
+
+ delete dateTime;
+ }
+ catch (XalanInvalidDateTime & xidt)
+ {
+ year = XalanDateTimeMath::NAN;
+ }
+
+ return executionContext.getXObjectFactory().createNumber(year);
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org