-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateEdit.cpp
86 lines (79 loc) · 1.74 KB
/
DateEdit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <string>
#include "DateEdit.h"
using namespace std;
void CDateEdit::ValidateData() {
SetWindowText( VerifyFormat().c_str() );
CStringEdit::ValidateData();
}
void CDateEdit::SetDate( CDate date ) {
SetString( date );
}
CDate CDateEdit::GetDate() {
return (CDate)VerifyFormat();
/*if ( GetString() == VerifyFormat() ) {
string text = GetString();
if ( text == "" ) {
return CDate();
} else {
return CDate(
((text[0]-'0')*10)+(text[1]-'0'),
((text[3]-'0')*10)+(text[4]-'0'),
((text[6]-'0')*1000)+((text[7]-'0')*100)+((text[8]-'0')*10)+(text[9]-'0')
);
}
} else {
return CDate();
}*/
}
string CDateEdit::VerifyFormat() {
string text = GetString();
if ( IsAllDigits( text ) ) {
if ( text.length() == 6 ) {
text = text.substr(0,2) + "-" + text.substr(2,2) + "-" + text.substr(4,2);
//if ( text[4] < '6' ) {
// text = text.substr(0,2) + "-" + text.substr(2,2) + "-20" + text.substr(4,2);
//} else {
// text = text.substr(0,2) + "-" + text.substr(2,2) + "-19" + text.substr(4,2);
//}
} else {
if ( text.length() == 8 ) {
text = text.substr(0,2) + "-" + text.substr(2,2) + "-" + text.substr(4,4);
}
}
}
return (string)CDate(text);
/*
if ( text.length() ) {
if ( text.length() != 10 ) {
return "";
// SetWindowText( text.c_str() );
} else {
for ( int i=0; i<text.size(); i++ ) {
switch ( i ) {
case 0 :
case 1 :
case 3 :
case 4 :
case 6 :
case 7 :
case 8 :
case 9 :
if ( !isdigit( text[i] ) ) {
return "";
//SetWindowText("");
}
break;
case 2 :
case 5 :
if ( text[i] != '-' ) {
return "";
//SetWindowText("");
}
break;
}
}
}
}
return GetString();
*/
}