28 #include <nsAutoPtr.h>
29 #include <nsComponentManagerUtils.h>
30 #include <nsServiceManagerUtils.h>
45 NS_INTERFACE_TABLE_BEGIN
48 NS_INTERFACE_TABLE_END
51 sbDurationPropertyInfo::sbDurationPropertyInfo()
52 : mDurationInversed(PR_FALSE)
53 , mDurationDisplayMillisec(PR_FALSE)
54 , mMinMaxDurationLock(nsnull)
56 , mMaxDuration(LL_MAXINT)
57 , mAppLocaleLock(nsnull)
58 , mDateTimeFormatLock(nsnull)
60 mType = NS_LITERAL_STRING(
"duration");
62 mMinMaxDurationLock = PR_NewLock();
63 NS_ASSERTION(mMinMaxDurationLock,
64 "sbDurationPropertyInfo::mMinMaxDurationLock failed to create lock!");
66 mAppLocaleLock = PR_NewLock();
67 NS_ASSERTION(mAppLocaleLock,
68 "sbDurationPropertyInfo::mAppLocaleLock failed to create lock!");
70 mDateTimeFormatLock = PR_NewLock();
71 NS_ASSERTION(mDateTimeFormatLock,
72 "sbDurationPropertyInfo::mDateTimeFormatLock failed to create lock!");
93 NS_ENSURE_SUCCESS(rv, rv);
96 NS_ENSURE_SUCCESS(rv, rv);
106 nsRefPtr<sbPropertyOperator> propOp;
108 rv = sbPropertyInfo::GetOPERATOR_EQUALS(op);
109 NS_ENSURE_SUCCESS(rv, rv);
111 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
113 NS_ENSURE_SUCCESS(rv, rv);
115 rv = sbPropertyInfo::GetOPERATOR_NOTEQUALS(op);
116 NS_ENSURE_SUCCESS(rv, rv);
118 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
120 NS_ENSURE_SUCCESS(rv, rv);
122 rv = sbPropertyInfo::GetOPERATOR_GREATER(op);
123 NS_ENSURE_SUCCESS(rv, rv);
125 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
127 NS_ENSURE_SUCCESS(rv, rv);
129 rv = sbPropertyInfo::GetOPERATOR_GREATEREQUAL(op);
130 NS_ENSURE_SUCCESS(rv, rv);
131 propOp =
new sbPropertyOperator(op, NS_LITERAL_STRING(
"&smart.duration.greaterequal"));
132 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
134 NS_ENSURE_SUCCESS(rv, rv);
136 rv = sbPropertyInfo::GetOPERATOR_LESS(op);
137 NS_ENSURE_SUCCESS(rv, rv);
139 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
141 NS_ENSURE_SUCCESS(rv, rv);
143 rv = sbPropertyInfo::GetOPERATOR_LESSEQUAL(op);
144 NS_ENSURE_SUCCESS(rv, rv);
146 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
148 NS_ENSURE_SUCCESS(rv, rv);
150 rv = sbPropertyInfo::GetOPERATOR_BETWEEN(op);
151 NS_ENSURE_SUCCESS(rv, rv);
153 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
155 NS_ENSURE_SUCCESS(rv, rv);
162 NS_ENSURE_ARG_POINTER(_retval);
165 NS_ConvertUTF16toUTF8 narrow(aValue);
184 return NS_ERROR_NOT_IMPLEMENTED;
190 NS_ConvertUTF16toUTF8 narrow(aValue);
193 return NS_ERROR_INVALID_ARG;
221 nsCOMPtr<nsILocaleService> localeService =
222 do_GetService(
"@mozilla.org/intl/nslocaleservice;1", &rv);
223 NS_ENSURE_SUCCESS(rv, rv);
225 rv = localeService->GetApplicationLocale(getter_AddRefs(
mAppLocale));
226 NS_ENSURE_SUCCESS(rv, rv);
231 mDateTimeFormat = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
232 NS_ENSURE_SUCCESS(rv, rv);
235 PRExplodedTime referenceTime = {0}, explodedTime = {0};
236 PR_ExplodeTime((PRTime) 0, PR_GMTParameters, &referenceTime);
237 PR_ExplodeTime((PRTime)value, PR_GMTParameters, &explodedTime);
239 PRInt32 delta = explodedTime.tm_year - referenceTime.tm_year;
241 out.AppendInt(delta);
242 out.AppendLiteral(
"Y");
245 delta = explodedTime.tm_month - referenceTime.tm_month;
247 out.AppendInt(delta);
248 out.AppendLiteral(
"M");
251 delta = explodedTime.tm_mday - referenceTime.tm_mday;
253 out.AppendInt(delta);
254 out.AppendLiteral(
"D ");
257 PRInt32 hours = explodedTime.tm_hour - referenceTime.tm_hour;
259 out.AppendInt(hours);
260 out.AppendLiteral(
":");
263 PRInt32 mins = explodedTime.tm_min - referenceTime.tm_min;
264 if(hours && mins < 10 ) {
265 out.AppendLiteral(
"0");
269 out.AppendLiteral(
":");
271 PRInt32 secs = explodedTime.tm_sec - referenceTime.tm_sec;
273 out.AppendLiteral(
"0");
279 delta = (explodedTime.tm_usec - referenceTime.tm_usec)
285 out.AppendLiteral(
".");
286 out.Append(NS_ConvertUTF8toUTF16(c));
298 NS_ConvertUTF16toUTF8 narrow(aValue);
301 _retval.StripWhitespace();
306 _retval = EmptyString();
307 return NS_ERROR_INVALID_ARG;
312 rv = NS_ERROR_FAILURE;
313 _retval = EmptyString();
316 NS_ConvertUTF8toUTF16 wide(out);
324 NS_IMETHODIMP sbDurationPropertyInfo::GetMinDuration(PRInt64 *aMinDuration)
326 NS_ENSURE_ARG_POINTER(aMinDuration);
333 NS_IMETHODIMP sbDurationPropertyInfo::SetMinDuration(PRInt64 aMinDuration)
335 NS_ENSURE_ARG(aMinDuration > -1);
343 NS_IMETHODIMP sbDurationPropertyInfo::GetMaxDuration(PRInt64 *aMaxDuration)
345 NS_ENSURE_ARG_POINTER(aMaxDuration);
352 NS_IMETHODIMP sbDurationPropertyInfo::SetMaxDuration(PRInt64 aMaxDuration)
354 NS_ENSURE_ARG(aMaxDuration > -1);
362 NS_IMETHODIMP sbDurationPropertyInfo::GetDurationInverse(PRBool *aDurationInverse)
364 NS_ENSURE_ARG_POINTER(aDurationInverse);
368 NS_IMETHODIMP sbDurationPropertyInfo::SetDurationInverse(PRBool aDurationInverse)
374 NS_IMETHODIMP sbDurationPropertyInfo::GetDurationWithMilliseconds(PRBool *aDurationWithMilliseconds)
376 NS_ENSURE_ARG_POINTER(aDurationWithMilliseconds);
380 NS_IMETHODIMP sbDurationPropertyInfo::SetDurationWithMilliseconds(PRBool aDurationWithMilliseconds)
virtual ~sbDurationPropertyInfo()
PRLock * mDateTimeFormatLock
PRBool mDurationDisplayMillisec
static const char * gsFmtMilliseconds10
nsresult InitializeOperators()
The property information specific to date/time fields.
NS_IMETHOD Validate(const nsAString &aValue, PRBool *_retval)
NS_IMPL_ADDREF_INHERITED(sbDurationPropertyInfo, sbPropertyInfo)
NS_IMPL_RELEASE_INHERITED(sbDurationPropertyInfo, sbPropertyInfo)
NS_IMETHOD Format(const nsAString &aValue, nsAString &_retval)
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
NS_IMETHOD MakeSearchable(const nsAString &aValue, nsAString &_retval)
nsCOMPtr< nsILocale > mAppLocale
static const char * gsSortFmtRadix10
nsCOMArray< sbIPropertyOperator > mOperators
static const char * gsFmtRadix10
nsCOMPtr< nsIDateTimeFormat > mDateTimeFormat
NS_IMETHOD Sanitize(const nsAString &aValue, nsAString &_retval)
PRLock * mMinMaxDurationLock