]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/cssmdates.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // Manage the Tower of Babel of CSSM dates and times.
25 #include <Security/utilities.h>
26 #include <Security/cssmdata.h>
27 #include <CoreFoundation/CFDate.h>
34 // A PodWrapper for CSSM_DATE
36 class CssmDate
: public PodWrapper
<CssmDate
, CSSM_DATE
> {
39 CssmDate(const char *y
, const char *m
, const char *d
);
40 CssmDate(int y
, int m
, int d
);
42 const char *years() const { return reinterpret_cast<const char *>(Year
); }
43 const char *months() const { return reinterpret_cast<const char *>(Month
); }
44 const char *days() const { return reinterpret_cast<const char *>(Day
); }
45 char *years() { return reinterpret_cast<char *>(Year
); }
46 char *months() { return reinterpret_cast<char *>(Month
); }
47 char *days() { return reinterpret_cast<char *>(Day
); }
54 static void assign(char *dest
, int width
, const char *src
);
57 inline bool operator == (const CSSM_DATE
&d1
, const CSSM_DATE
&d2
)
58 { return !memcmp(&d1
, &d2
, sizeof(d1
)); }
60 inline bool operator != (const CSSM_DATE
&d1
, const CSSM_DATE
&d2
)
61 { return !memcmp(&d1
, &d2
, sizeof(d1
)); }
65 // Yet another CSSM date/time format is CSSM_TIMESTRING. This is
66 // defined as "char *", just so you can't use the type system
67 // to keep things sane, so we can't really PodWrap it the usual way.
68 // What *were* they thinking?
69 // The format is allegedly "yyyymmddhhmmss", and the standard says
70 // nothing about trailing null characters.
75 // A unified date-and-time object.
76 // This is based on CFDate objects and converts to various CSSM
79 class CssmUniformDate
{
83 // convert to/from CFDateRef
84 CssmUniformDate(CFDateRef ref
);
85 operator CFDateRef() const;
87 // convert to/from CFAbsoluteTime
88 CssmUniformDate(CFAbsoluteTime ct
) : mTime(ct
) { }
89 operator CFAbsoluteTime() const { return mTime
; }
91 // convert to/from CSSM_DATE
92 CssmUniformDate(const CssmDate
&src
);
93 operator CssmDate () const;
95 // convert to/from DATA format (1999-06-30_15:05:39 form)
96 CssmUniformDate(const CSSM_DATA
&src
);
97 void convertTo(CssmOwnedData
&data
) const;
99 // convert to/from CSSM_TIMESTRING format (19990630150539)
100 CssmUniformDate(const char *src
);
101 void convertTo(char *dest
, size_t length
) const;
103 // native comparisons
104 bool operator < (const CssmUniformDate
&other
) const { return mTime
< other
.mTime
; }
105 bool operator == (const CssmUniformDate
&other
) const { return mTime
== other
.mTime
; }
106 bool operator > (const CssmUniformDate
&other
) const { return mTime
> other
.mTime
; }
107 bool operator <= (const CssmUniformDate
&other
) const { return mTime
<= other
.mTime
; }
108 bool operator >= (const CssmUniformDate
&other
) const { return mTime
>= other
.mTime
; }
109 bool operator != (const CssmUniformDate
&other
) const { return mTime
!= other
.mTime
; }
112 void setFromString(const char *src
, const char *format
, size_t fieldLength
);
115 CFAbsoluteTime mTime
;
119 } // end namespace Security
121 #endif //_H_CSSMDATES