1
/*------------------------------------------------------------------------------
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
4
* Distributable under the terms of either the Apache License (Version 2.0) or
5
* the GNU Lesser General Public License, as specified in the COPYING file.
6
------------------------------------------------------------------------------*/
7
#include "CLucene/StdHeader.h"
10
#include "CLucene/util/Misc.h"
14
DateField::~DateField(){
17
TCHAR* DateField::timeToString(const int64_t time) {
18
TCHAR* buf = _CL_NEWARRAY(TCHAR,DATEFIELD_DATE_LEN + 1);
19
timeToString(time,buf);
22
void DateField::timeToString(const int64_t time, TCHAR* buf) {
23
CND_PRECONDITION (buf, "buf == NULL");
26
_CLTHROWA (CL_ERR_IllegalArgument,"time too early"); //todo: make richer error
28
if (time > DATEFIELD_DATE_MAX)
29
_CLTHROWA (CL_ERR_IllegalArgument, "time too late (past DATEFIELD_DATE_MAX"); //todo: make richer error
31
_i64tot(time, buf, 36);
32
int32_t bufLen = _tcslen(buf);
34
CND_PRECONDITION (bufLen <= DATEFIELD_DATE_LEN, "timeToString length is greater than 9");
36
/* Supply leading zeroes if necessary. */
37
if (bufLen < DATEFIELD_DATE_LEN) {
38
const int32_t nMissingZeroes = DATEFIELD_DATE_LEN - bufLen;
39
/* Move buffer contents forward to make room for leading zeroes. */
40
for (int32_t i = DATEFIELD_DATE_LEN - 1; i >= nMissingZeroes; i--)
41
buf[i] = buf[i - nMissingZeroes];
43
/* Insert leading zeroes. */
45
for (int32_t i = 0; i < nMissingZeroes; i++)
49
buf[DATEFIELD_DATE_LEN] = 0;
52
CND_PRECONDITION (_tcslen(buf) == DATEFIELD_DATE_LEN, "timeToString return is not equal to DATEFIELD_DATE_LEN");
55
int64_t DateField::stringToTime(const TCHAR* time) {
57
return _tcstoi64(time, &end, 36);