31 #include <com/sun/star/util/DateTime.hpp>
39 bool DateTimeHelper::ISO8601_To_DateTime (
const OUString& s,
42 OString aDT (s.getStr(), s.getLength(), RTL_TEXTENCODING_ASCII_US);
44 int year,
month,
day, hours, minutes, off_hours, off_minutes, fix;
48 int n = sscanf( aDT.getStr(),
"%04d-%02d-%02dT%02d:%02d:%lfZ",
49 &year, &month, &day, &hours, &minutes, &seconds );
57 n = sscanf( aDT.getStr(),
"%04d-%02d-%02dT%02d:%02d:%lf+%02d:%02d",
58 &year, &month, &day, &hours, &minutes, &seconds,
59 &off_hours, &off_minutes );
62 fix = - off_hours * 3600 - off_minutes * 60;
67 n = sscanf( aDT.getStr(),
"%04d-%02d-%02dT%02d:%02d:%lf-%02d:%02d",
68 &year, &month, &day, &hours, &minutes, &seconds,
69 &off_hours, &off_minutes );
72 fix = off_hours * 3600 + off_minutes * 60;
83 oslDateTime aDateTime;
84 aDateTime.NanoSeconds = 0;
85 aDateTime.Seconds = sal::static_int_cast< sal_uInt16 >(seconds);
86 aDateTime.Minutes = sal::static_int_cast< sal_uInt16 >(minutes);
87 aDateTime.Hours = sal::static_int_cast< sal_uInt16 >(hours);
88 aDateTime.Day = sal::static_int_cast< sal_uInt16 >(day);
89 aDateTime.DayOfWeek = 0;
90 aDateTime.Month = sal::static_int_cast< sal_uInt16 >(month);
91 aDateTime.Year = sal::static_int_cast< sal_Int16 >(year);
94 if ( osl_getTimeValueFromDateTime( &aDateTime, &aTimeValue ) )
96 aTimeValue.Seconds += fix;
98 if ( osl_getLocalTimeFromSystemTime( &aTimeValue, &aTimeValue ) )
100 if ( osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime ) )
102 dateTime.Year = aDateTime.Year;
103 dateTime.Month = aDateTime.Month;
104 dateTime.Day = aDateTime.Day;
105 dateTime.Hours = aDateTime.Hours;
106 dateTime.Minutes = aDateTime.Minutes;
107 dateTime.Seconds = aDateTime.Seconds;
117 sal_Int32 DateTimeHelper::convertMonthToInt (std::u16string_view month)
121 else if (month ==
u"Feb")
123 else if (month ==
u"Mar")
125 else if (month ==
u"Apr")
127 else if (month ==
u"May")
129 else if (month ==
u"Jun")
131 else if (month ==
u"Jul")
133 else if (month ==
u"Aug")
135 else if (month ==
u"Sep")
137 else if (month ==
u"Oct")
139 else if (month ==
u"Nov")
141 else if (month ==
u"Dec")
147 bool DateTimeHelper::RFC2068_To_DateTime (
const OUString& s,
155 char string_month[3 + 1];
156 char string_day[3 + 1];
158 sal_Int32 found = s.indexOf (
',');
161 OString aDT (s.getStr(), s.getLength(), RTL_TEXTENCODING_ASCII_US);
164 found = sscanf (aDT.getStr(),
"%3s, %2d %3s %4d %2d:%2d:%2d GMT",
165 string_day, &day, string_month, &year, &hours, &minutes, &seconds);
169 found = sscanf (aDT.getStr(),
"%3s, %2d-%3s-%2d %2d:%2d:%2d GMT",
170 string_day, &day, string_month, &year, &hours, &minutes, &seconds);
172 found = (found == 7) ? 1 : 0;
176 OString aDT (s.getStr(), s.getLength(), RTL_TEXTENCODING_ASCII_US);
179 found = sscanf (aDT.getStr(),
"%3s %3s %d %2d:%2d:%2d %4d",
180 string_day, string_month,
181 &day, &hours, &minutes, &seconds, &year);
182 found = (found == 7) ? 1 : 0;
189 int month = DateTimeHelper::convertMonthToInt (
190 OUString::createFromAscii (string_month));
195 oslDateTime aDateTime;
196 aDateTime.NanoSeconds = 0;
197 aDateTime.Seconds = sal::static_int_cast< sal_uInt16 >(seconds);
199 aDateTime.Minutes = sal::static_int_cast< sal_uInt16 >(minutes);
201 aDateTime.Hours = sal::static_int_cast< sal_uInt16 >(hours);
203 aDateTime.Day = sal::static_int_cast< sal_uInt16 >(day);
205 aDateTime.DayOfWeek = 0;
206 aDateTime.Month = sal::static_int_cast< sal_uInt16 >(month);
208 aDateTime.Year = sal::static_int_cast< sal_Int16 >(year);
210 TimeValue aTimeValue;
211 if ( osl_getTimeValueFromDateTime( &aDateTime,
214 if ( osl_getLocalTimeFromSystemTime( &aTimeValue,
217 if ( osl_getDateTimeFromTimeValue( &aTimeValue,
220 dateTime.Year = aDateTime.Year;
221 dateTime.Month = aDateTime.Month;
222 dateTime.Day = aDateTime.Day;
223 dateTime.Hours = aDateTime.Hours;
224 dateTime.Minutes = aDateTime.Minutes;
225 dateTime.Seconds = aDateTime.Seconds;
239 if (ISO8601_To_DateTime (s, dateTime))
241 else if (RFC2068_To_DateTime (s, dateTime))
static bool convert(TaskManager const *pShell, uno::Reference< script::XTypeConverter > &xConverter, uno::Any &rValue, _type_ &aReturn)