MCPcopy Create free account
hub / github.com/MailCore/mailcore2 / stringFromDate

Method stringFromDate

src/core/renderer/MCDateFormatter.cpp:109–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109String * DateFormatter::stringFromDate(time_t date)
110{
111 prepare();
112#if USE_COREFOUNDATION
113 if (mAppleDateFormatter == NULL)
114 return NULL;
115
116 CFDateRef dateRef = CFDateCreate(NULL, (CFAbsoluteTime) date - kCFAbsoluteTimeIntervalSince1970);
117 CFStringRef string = CFDateFormatterCreateStringWithDate(NULL, (CFDateFormatterRef) mAppleDateFormatter, dateRef);
118 CFIndex len = CFStringGetLength(string);
119 UniChar * buffer = (UniChar *) malloc(sizeof(* buffer) * len);
120 CFStringGetCharacters(string, CFRangeMake(0, len), buffer);
121 String * result = String::stringWithCharacters(buffer, (unsigned int) len);
122 free(buffer);
123 CFRelease(string);
124 CFRelease(dateRef);
125 return result;
126#else
127 if (mDateFormatter == NULL)
128 return NULL;
129
130 UErrorCode err = U_ZERO_ERROR;
131 int32_t len = udat_format(mDateFormatter, ((double) date) * 1000., NULL, 0, NULL, &err);
132 if(err != U_BUFFER_OVERFLOW_ERROR) {
133 return NULL;
134 }
135
136 String * result;
137
138 err = U_ZERO_ERROR;
139 UChar * unichars = (UChar *) malloc((len + 1) * sizeof(unichars));
140 udat_format(mDateFormatter, ((double) date) * 1000., unichars, len + 1, NULL, &err);
141 result = new String(unichars, len);
142 free(unichars);
143
144 result->autorelease();
145 return result;
146#endif
147}
148
149time_t DateFormatter::dateFromString(String * dateString)
150{

Callers 1

Calls 1

autoreleaseMethod · 0.45

Tested by

no test coverage detected