Aggiunta la possibilita' di trattare le date in formato ANSI (YYYYMMDD).
git-svn-id: svn://10.65.10.50/trunk@45 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
22611ac7b5
commit
441344d49c
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
TDate nodate, botime, eotime(31,12,2050);
|
TDate nodate, botime, eotime(31,12,2050);
|
||||||
HIDDEN TDate __tmp_date;
|
HIDDEN TDate __tmp_date;
|
||||||
|
HIDDEN char __date_tmp_string[20];
|
||||||
|
|
||||||
TDate::TDate(const TDate &d) : _val(d._val) {}
|
TDate::TDate(const TDate &d) : _val(d._val) {}
|
||||||
|
|
||||||
@ -37,9 +38,26 @@ TDate::TDate(const char* s)
|
|||||||
|
|
||||||
if (strlen(s) == 10)
|
if (strlen(s) == 10)
|
||||||
{
|
{
|
||||||
int day = atoi(s),
|
int day = atoi(s), month = atoi(&s[3]), year = atoi(&s[6]);
|
||||||
month = atoi(&s[3]),
|
long off = 0L;
|
||||||
year = atoi(&s[6]);
|
|
||||||
|
if (year > 1000)
|
||||||
|
{
|
||||||
|
if (year < 1951) off -= DAYBIAS;
|
||||||
|
if (year < 1851) off -= DAYBIAS;
|
||||||
|
if (year < 1751) off -= DAYBIAS;
|
||||||
|
year %= 100; // modify
|
||||||
|
}
|
||||||
|
_val = makedata(day, month, year) + off;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (strchr(s, '-') == NULL)
|
||||||
|
{
|
||||||
|
strcpy(__date_tmp_string, s);
|
||||||
|
|
||||||
|
int day = atoi(__date_tmp_string + 6); __date_tmp_string[6] = '\0';
|
||||||
|
int month = atoi(__date_tmp_string + 4); __date_tmp_string[4] = '\0';
|
||||||
|
int year = atoi(__date_tmp_string);
|
||||||
long off = 0L;
|
long off = 0L;
|
||||||
|
|
||||||
if (year > 1000)
|
if (year > 1000)
|
||||||
@ -95,13 +113,17 @@ TDate& TDate::operator =(const char* s)
|
|||||||
|
|
||||||
|
|
||||||
void TDate::print_on(ostream& out) const
|
void TDate::print_on(ostream& out) const
|
||||||
{ out << string(); }
|
{
|
||||||
|
out << string();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TDate::read_from(istream& in)
|
void TDate::read_from(istream& in)
|
||||||
{
|
{
|
||||||
in >> __tmp_string;
|
char s[256];
|
||||||
if (isdate(__tmp_string)) _val = cpackdata(__tmp_string);
|
|
||||||
|
in >> s;
|
||||||
|
if (isdate(s)) _val = cpackdata(s);
|
||||||
else _val = NULLDATE;
|
else _val = NULLDATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,35 +133,39 @@ char* TDate::string(int yeardgts, char sep) const
|
|||||||
{
|
{
|
||||||
if (!ok()) return "";
|
if (!ok()) return "";
|
||||||
long wv = _val;
|
long wv = _val;
|
||||||
// int cnt = int(wv / DAYBIAS - (wv < 0 ? 1 : 0));
|
|
||||||
int cnt = wv >= DAYBIAS ? 2000 : 1900;
|
int cnt = wv >= DAYBIAS ? 2000 : 1900;
|
||||||
// int cnt = 0;
|
|
||||||
// bool over2000 = wv >= DAYBIAS;
|
|
||||||
|
|
||||||
while (wv < 0)
|
while (wv < 0)
|
||||||
{
|
{
|
||||||
cnt -= 100;
|
cnt -= 100;
|
||||||
wv += DAYBIAS;
|
wv += DAYBIAS;
|
||||||
}
|
}
|
||||||
ceditdata(wv, __tmp_string);
|
ceditdata(wv, __date_tmp_string);
|
||||||
if (strcmp(__tmp_string, " - - ") == 0) return "";
|
if (strcmp(__date_tmp_string, " - - ") == 0) return "";
|
||||||
if (sep != '-')
|
if (sep != '-')
|
||||||
for (char* s = __tmp_string; *s; s++)
|
for (char* s = __date_tmp_string; *s; s++)
|
||||||
if (*s == '-') *s = sep;
|
if (*s == '-') *s = sep;
|
||||||
if (yeardgts > 2)
|
if (yeardgts > 2)
|
||||||
{
|
{
|
||||||
char s[8];
|
char s[8];
|
||||||
// int year = ::year(wv) - cnt * 100;
|
int year = cnt + atoi(__date_tmp_string + 6);
|
||||||
// if (year > 2000 && !over2000) year -= 100;
|
|
||||||
// int year = 1900 + cnt * 100 + atoi(__tmp_string + 6);
|
|
||||||
int year = cnt + atoi(__tmp_string + 6);
|
|
||||||
|
|
||||||
if (yeardgts == 3) sprintf(s, "%03d", year % 1000);
|
if (yeardgts == 3) sprintf(s, "%03d", year % 1000);
|
||||||
else sprintf(s, "%04d", year);
|
else sprintf(s, "%04d", year);
|
||||||
__tmp_string[6] = '\0';
|
__date_tmp_string[6] = '\0';
|
||||||
strcat(__tmp_string, s);
|
strcat(__date_tmp_string, s);
|
||||||
}
|
}
|
||||||
return __tmp_string;
|
else
|
||||||
|
if (yeardgts == ANSI)
|
||||||
|
{
|
||||||
|
char* s = __date_tmp_string; s[2] = '\0'; s[5] = '\0';
|
||||||
|
const int day = atoi(s);
|
||||||
|
const int month = atoi(s + 3);
|
||||||
|
const int year = atoi(s + 6);
|
||||||
|
|
||||||
|
sprintf(__date_tmp_string, "%04d%02d%02d", year, month, day);
|
||||||
|
}
|
||||||
|
return __date_tmp_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user