30 #include <nsAutoPtr.h>
31 #include <nsComponentManagerUtils.h>
32 #include <nsServiceManagerUtils.h>
46 NS_INTERFACE_TABLE_BEGIN
49 NS_INTERFACE_TABLE_END
52 sbDatetimePropertyInfo::sbDatetimePropertyInfo()
53 : mTimeTypeLock(nsnull)
55 , mMinMaxDateTimeLock(nsnull)
57 , mMaxDateTime(LL_MAXINT)
58 , mAppLocaleLock(nsnull)
59 , mDateTimeFormatLock(nsnull)
61 mType = NS_LITERAL_STRING(
"datetime");
63 mTimeTypeLock = PR_NewLock();
64 NS_ASSERTION(mTimeTypeLock,
65 "sbDatetimePropertyInfo::mTimeTypeLock failed to create lock!");
67 mMinMaxDateTimeLock = PR_NewLock();
68 NS_ASSERTION(mMinMaxDateTimeLock,
69 "sbDatetimePropertyInfo::mMinMaxDateTimeLock failed to create lock!");
71 mAppLocaleLock = PR_NewLock();
72 NS_ASSERTION(mAppLocaleLock,
73 "sbDatetimePropertyInfo::mAppLocaleLock failed to create lock!");
75 mDateTimeFormatLock = PR_NewLock();
76 NS_ASSERTION(mDateTimeFormatLock,
77 "sbDatetimePropertyInfo::mDateTimeFormatLock failed to create lock!");
101 NS_ENSURE_SUCCESS(rv, rv);
104 NS_ENSURE_SUCCESS(rv, rv);
114 nsRefPtr<sbPropertyOperator> propOp;
116 rv = sbPropertyInfo::GetOPERATOR_EQUALS(op);
117 NS_ENSURE_SUCCESS(rv, rv);
119 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
121 NS_ENSURE_SUCCESS(rv, rv);
123 rv = GetOPERATOR_ONDATE(op);
124 NS_ENSURE_SUCCESS(rv, rv);
126 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
128 NS_ENSURE_SUCCESS(rv, rv);
130 rv = sbPropertyInfo::GetOPERATOR_NOTEQUALS(op);
131 NS_ENSURE_SUCCESS(rv, rv);
133 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
135 NS_ENSURE_SUCCESS(rv, rv);
137 rv = GetOPERATOR_NOTONDATE(op);
138 NS_ENSURE_SUCCESS(rv, rv);
140 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
142 NS_ENSURE_SUCCESS(rv, rv);
144 rv = sbPropertyInfo::GetOPERATOR_GREATER(op);
145 NS_ENSURE_SUCCESS(rv, rv);
147 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
149 NS_ENSURE_SUCCESS(rv, rv);
151 rv = GetOPERATOR_AFTERDATE(op);
152 NS_ENSURE_SUCCESS(rv, rv);
154 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
156 NS_ENSURE_SUCCESS(rv, rv);
158 rv = sbPropertyInfo::GetOPERATOR_GREATEREQUAL(op);
159 NS_ENSURE_SUCCESS(rv, rv);
161 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
163 NS_ENSURE_SUCCESS(rv, rv);
165 rv = GetOPERATOR_AFTERORONDATE(op);
166 NS_ENSURE_SUCCESS(rv, rv);
168 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
170 NS_ENSURE_SUCCESS(rv, rv);
172 rv = sbPropertyInfo::GetOPERATOR_LESS(op);
173 NS_ENSURE_SUCCESS(rv, rv);
175 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
177 NS_ENSURE_SUCCESS(rv, rv);
179 rv = GetOPERATOR_BEFOREDATE(op);
180 NS_ENSURE_SUCCESS(rv, rv);
182 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
184 NS_ENSURE_SUCCESS(rv, rv);
186 rv = sbPropertyInfo::GetOPERATOR_LESSEQUAL(op);
187 NS_ENSURE_SUCCESS(rv, rv);
189 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
191 NS_ENSURE_SUCCESS(rv, rv);
193 rv = GetOPERATOR_BEFOREORONDATE(op);
194 NS_ENSURE_SUCCESS(rv, rv);
196 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
198 NS_ENSURE_SUCCESS(rv, rv);
200 rv = GetOPERATOR_INTHELAST(op);
201 NS_ENSURE_SUCCESS(rv, rv);
203 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
205 NS_ENSURE_SUCCESS(rv, rv);
207 rv = GetOPERATOR_NOTINTHELAST(op);
208 NS_ENSURE_SUCCESS(rv, rv);
210 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
212 NS_ENSURE_SUCCESS(rv, rv);
214 rv = sbPropertyInfo::GetOPERATOR_BETWEEN(op);
215 NS_ENSURE_SUCCESS(rv, rv);
217 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
219 NS_ENSURE_SUCCESS(rv, rv);
221 rv = GetOPERATOR_BETWEENDATES(op);
222 NS_ENSURE_SUCCESS(rv, rv);
224 NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
226 NS_ENSURE_SUCCESS(rv, rv);
233 NS_ENSURE_ARG_POINTER(_retval);
236 NS_ConvertUTF16toUTF8 narrow(aValue);
255 return NS_ERROR_NOT_IMPLEMENTED;
262 NS_ConvertUTF16toUTF8 narrow(aValue);
264 nsresult rv = GetTimeType(&timeType);
265 NS_ENSURE_SUCCESS(rv, rv);
268 return NS_ERROR_INVALID_ARG;
275 return NS_ERROR_INVALID_ARG;
284 nsCOMPtr<nsILocaleService> localeService =
285 do_GetService(
"@mozilla.org/intl/nslocaleservice;1", &rv);
286 NS_ENSURE_SUCCESS(rv, rv);
288 rv = localeService->GetApplicationLocale(getter_AddRefs(
mAppLocale));
289 NS_ENSURE_SUCCESS(rv, rv);
294 mDateTimeFormat = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
295 NS_ENSURE_SUCCESS(rv, rv);
301 PRExplodedTime explodedTime = {0};
302 PR_ExplodeTime((PRTime) (value * PR_USEC_PER_MSEC), PR_LocalTimeParameters, &explodedTime);
314 PRExplodedTime explodedTime = {0};
315 PR_ExplodeTime((PRTime) (value * PR_USEC_PER_MSEC), PR_LocalTimeParameters, &explodedTime);
327 PRExplodedTime explodedTime = {0};
328 PR_ExplodeTime((PRTime) (value * PR_USEC_PER_MSEC), PR_LocalTimeParameters, &explodedTime);
331 kTimeFormatNoSeconds,
338 NS_ENSURE_SUCCESS(rv, rv);
343 CompressWhitespace(_retval);
353 NS_ConvertUTF16toUTF8 narrow(aValue);
356 _retval.StripWhitespace();
361 _retval = EmptyString();
362 return NS_ERROR_INVALID_ARG;
367 rv = NS_ERROR_FAILURE;
368 _retval = EmptyString();
371 NS_ConvertUTF8toUTF16 wide(out);
379 NS_IMETHODIMP sbDatetimePropertyInfo::GetTimeType(PRInt32 *aTimeType)
381 NS_ENSURE_ARG_POINTER(aTimeType);
389 return NS_ERROR_NOT_INITIALIZED;
391 NS_IMETHODIMP sbDatetimePropertyInfo::SetTimeType(PRInt32 aTimeType)
402 return NS_ERROR_ALREADY_INITIALIZED;
405 NS_IMETHODIMP sbDatetimePropertyInfo::GetMinDateTime(PRInt64 *aMinDateTime)
407 NS_ENSURE_ARG_POINTER(aMinDateTime);
414 NS_IMETHODIMP sbDatetimePropertyInfo::SetMinDateTime(PRInt64 aMinDateTime)
416 NS_ENSURE_ARG(aMinDateTime > -1);
424 NS_IMETHODIMP sbDatetimePropertyInfo::GetMaxDateTime(PRInt64 *aMaxDateTime)
426 NS_ENSURE_ARG_POINTER(aMaxDateTime);
433 NS_IMETHODIMP sbDatetimePropertyInfo::SetMaxDateTime(PRInt64 aMaxDateTime)
435 NS_ENSURE_ARG(aMaxDateTime > -1);
443 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_INTHELAST(nsAString & aOPERATOR_INTHELAST)
449 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_NOTINTHELAST(nsAString & aOPERATOR_NOTINTHELAST)
455 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_ONDATE(nsAString & aOPERATOR_ONDATE)
461 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_NOTONDATE(nsAString & aOPERATOR_NOTONDATE)
467 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_BEFOREDATE(nsAString & aOPERATOR_BEFOREDATE)
473 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_BEFOREORONDATE(nsAString & aOPERATOR_BEFOREORONDATE)
479 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_AFTERDATE(nsAString & aOPERATOR_AFTERDATE)
485 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_AFTERORONDATE(nsAString & aOPERATOR_AFTERORONDATE)
491 NS_IMETHODIMP sbDatetimePropertyInfo::GetOPERATOR_BETWEENDATES(nsAString & aOPERATOR_BETWEENDATES)
#define SB_OPERATOR_AFTERDATE
PRLock * mDateTimeFormatLock
#define SB_OPERATOR_ONDATE
#define SB_OPERATOR_AFTERORONDATE
NS_IMETHOD Format(const nsAString &aValue, nsAString &_retval)
The property information specific to date/time fields.
#define SB_OPERATOR_NOTINTHELAST
#define SB_OPERATOR_BEFOREDATE
#define SB_OPERATOR_BEFOREORONDATE
NS_IMETHOD Sanitize(const nsAString &aValue, nsAString &_retval)
NS_IMPL_RELEASE_INHERITED(sbDatetimePropertyInfo, sbPropertyInfo)
const long TIMETYPE_TIME
HH:mm:ss.ms, in localized format. Limited to 24 hour days.
const long TIMETYPE_DATETIME
Long date format, 2007-03-28 12:33:01 , no milliseconds.
nsCOMPtr< nsIDateTimeFormat > mDateTimeFormat
const long TIMETYPE_DATE
2007-03-28 , in localized format
virtual ~sbDatetimePropertyInfo()
#define SB_OPERATOR_NOTONDATE
static const char * gsFmtRadix10
NS_IMETHOD Validate(const nsAString &aValue, PRBool *_retval)
attribute long timeType
You must initialize this attribute before using this object. If you do not, all methods on this objec...
nsCOMPtr< nsILocale > mAppLocale
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)
const long TIMETYPE_UNINITIALIZED
nsresult InitializeOperators()
static const char * gsSortFmtRadix10
#define SB_OPERATOR_BETWEENDATES
#define SB_OPERATOR_INTHELAST
PRLock * mMinMaxDateTimeLock
nsCOMArray< sbIPropertyOperator > mOperators
NS_IMPL_ADDREF_INHERITED(sbDatetimePropertyInfo, sbPropertyInfo)
const long TIMETYPE_TIMESTAMP
Timestamp format, respects unix time, microsecond format.