21 #include <com/sun/star/util/DateTime.hpp>
28 bool DateTimeHelper::ISO8601_To_DateTime (
const OUString& s,
31 OString aDT (s.getStr(), s.getLength(), RTL_TEXTENCODING_ASCII_US);
33 int year,
month,
day, hours, minutes, off_hours, off_minutes, fix;
37 int n = sscanf( aDT.getStr(),
"%04d-%02d-%02dT%02d:%02d:%lfZ",
38 &year, &month, &day, &hours, &minutes, &seconds );
46 n = sscanf( aDT.getStr(),
"%04d-%02d-%02dT%02d:%02d:%lf+%02d:%02d",
47 &year, &month, &day, &hours, &minutes, &seconds,
48 &off_hours, &off_minutes );
51 fix = - off_hours * 3600 - off_minutes * 60;
56 n = sscanf( aDT.getStr(),
"%04d-%02d-%02dT%02d:%02d:%lf-%02d:%02d",
57 &year, &month, &day, &hours, &minutes, &seconds,
58 &off_hours, &off_minutes );
61 fix = off_hours * 3600 + off_minutes * 60;
72 oslDateTime aDateTime;
73 aDateTime.NanoSeconds = 0;
74 aDateTime.Seconds = sal::static_int_cast< sal_uInt16 >(seconds);
75 aDateTime.Minutes = sal::static_int_cast< sal_uInt16 >(minutes);
76 aDateTime.Hours = sal::static_int_cast< sal_uInt16 >(hours);
77 aDateTime.Day = sal::static_int_cast< sal_uInt16 >(day);
78 aDateTime.DayOfWeek = 0;
79 aDateTime.Month = sal::static_int_cast< sal_uInt16 >(month);
80 aDateTime.Year = sal::static_int_cast< sal_Int16 >(year);
83 if ( osl_getTimeValueFromDateTime( &aDateTime, &aTimeValue ) )
85 aTimeValue.Seconds += fix;
87 if ( osl_getLocalTimeFromSystemTime( &aTimeValue, &aTimeValue ) )
89 if ( osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime ) )
91 dateTime.Year = aDateTime.Year;
92 dateTime.Month = aDateTime.Month;
93 dateTime.Day = aDateTime.Day;
94 dateTime.Hours = aDateTime.Hours;
95 dateTime.Minutes = aDateTime.Minutes;
96 dateTime.Seconds = aDateTime.Seconds;
128 sal_Int32 DateTimeHelper::convertMonthToInt (
const OUString& month)
132 else if (month ==
"Feb")
134 else if (month ==
"Mar")
136 else if (month ==
"Apr")
138 else if (month ==
"May")
140 else if (month ==
"Jun")
142 else if (month ==
"Jul")
144 else if (month ==
"Aug")
146 else if (month ==
"Sep")
148 else if (month ==
"Oct")
150 else if (month ==
"Nov")
152 else if (month ==
"Dec")
158 bool DateTimeHelper::RFC2068_To_DateTime (
const OUString& s,
166 char string_month[3 + 1];
167 char string_day[3 + 1];
169 sal_Int32 found = s.indexOf (
',');
172 OString aDT (s.getStr(), s.getLength(), RTL_TEXTENCODING_ASCII_US);
175 found = sscanf (aDT.getStr(),
"%3s, %2d %3s %4d %2d:%2d:%2d GMT",
176 string_day, &day, string_month, &year, &hours, &minutes, &seconds);
180 found = sscanf (aDT.getStr(),
"%3s, %2d-%3s-%2d %2d:%2d:%2d GMT",
181 string_day, &day, string_month, &year, &hours, &minutes, &seconds);
183 found = (found == 7) ? 1 : 0;
187 OString aDT (s.getStr(), s.getLength(), RTL_TEXTENCODING_ASCII_US);
190 found = sscanf (aDT.getStr(),
"%3s %3s %d %2d:%2d:%2d %4d",
191 string_day, string_month,
192 &day, &hours, &minutes, &seconds, &year);
193 found = (found == 7) ? 1 : 0;
200 int month = DateTimeHelper::convertMonthToInt (
201 OUString::createFromAscii (string_month));
206 oslDateTime aDateTime;
207 aDateTime.NanoSeconds = 0;
208 aDateTime.Seconds = sal::static_int_cast< sal_uInt16 >(seconds);
210 aDateTime.Minutes = sal::static_int_cast< sal_uInt16 >(minutes);
212 aDateTime.Hours = sal::static_int_cast< sal_uInt16 >(hours);
214 aDateTime.Day = sal::static_int_cast< sal_uInt16 >(day);
216 aDateTime.DayOfWeek = 0;
217 aDateTime.Month = sal::static_int_cast< sal_uInt16 >(month);
219 aDateTime.Year = sal::static_int_cast< sal_Int16 >(year);
221 TimeValue aTimeValue;
222 if ( osl_getTimeValueFromDateTime( &aDateTime,
225 if ( osl_getLocalTimeFromSystemTime( &aTimeValue,
228 if ( osl_getDateTimeFromTimeValue( &aTimeValue,
231 dateTime.Year = aDateTime.Year;
232 dateTime.Month = aDateTime.Month;
233 dateTime.Day = aDateTime.Day;
234 dateTime.Hours = aDateTime.Hours;
235 dateTime.Minutes = aDateTime.Minutes;
236 dateTime.Seconds = aDateTime.Seconds;
250 if (ISO8601_To_DateTime (s, dateTime))
252 else if (RFC2068_To_DateTime (s, dateTime))
static bool convert(TaskManager const *pShell, uno::Reference< script::XTypeConverter > &xConverter, uno::Any &rValue, _type_ &aReturn)