/[LeafOK_CVS]/innwebd/DateTimeConvert.cpp
ViewVC logotype

Annotation of /innwebd/DateTimeConvert.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Fri Apr 11 17:14:49 2008 UTC (17 years, 11 months ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -6 lines
Content type: text/x-c++src
Update copyright
Add extra log for exception

1 sysadm 1.1 /*******************************************************/
2     /* */
3 sysadm 1.2 /* LeafOK Innbbsd */
4 sysadm 1.1 /* */
5 sysadm 1.4 /* Copyright (C) LeafOK.com, 2003-2008 */
6 sysadm 1.1 /* */
7 sysadm 1.4 /* http://www.leafok.com */
8 sysadm 1.1 /* */
9     /*******************************************************/
10    
11     #include "StdAfx.h"
12     #include ".\datetimeconvert.h"
13    
14     DateTimeConvert::DateTimeConvert(const char* str_time)
15     {
16     if (str_time)
17     this->strtotime(str_time);
18     }
19    
20     DateTimeConvert::~DateTimeConvert(void)
21     {
22     }
23    
24     int DateTimeConvert::strtotime(const char* str_time)
25     {
26     char month[4],temp[80];
27     // Wed, 30 Jul 2003 14:39:31 GMT
28    
29     sscanf(str_time,"%s",temp);
30     if (temp[strlen(temp)-1] == ',')
31     {
32     sscanf(str_time,"%*s %d %s %d %d:%d:%d",
33     &(this->time.tm_mday),month,&(this->time.tm_year),
34     &(this->time.tm_hour),&(this->time.tm_min),&(this->time.tm_sec));
35     }
36     else
37     {
38     sscanf(str_time,"%d %s %d %d:%d:%d",
39     &(this->time.tm_mday),month,&(this->time.tm_year),
40     &(this->time.tm_hour),&(this->time.tm_min),&(this->time.tm_sec));
41     }
42    
43     if (strcmp(month,"Jan") == 0)
44     this->time.tm_mon = 1;
45     if (strcmp(month,"Feb") == 0)
46     this->time.tm_mon = 2;
47     if (strcmp(month,"Mar") == 0)
48     this->time.tm_mon = 3;
49     if (strcmp(month,"Apr") == 0)
50     this->time.tm_mon = 4;
51     if (strcmp(month,"May") == 0)
52     this->time.tm_mon = 5;
53     if (strcmp(month,"Jun") == 0)
54     this->time.tm_mon = 6;
55     if (strcmp(month,"Jul") == 0)
56     this->time.tm_mon = 7;
57     if (strcmp(month,"Aug") == 0)
58     this->time.tm_mon = 8;
59     if (strcmp(month,"Sep") == 0)
60     this->time.tm_mon = 9;
61     if (strcmp(month,"Oct") == 0)
62     this->time.tm_mon = 10;
63     if (strcmp(month,"Nov") == 0)
64     this->time.tm_mon = 11;
65     if (strcmp(month,"Dec") == 0)
66     this->time.tm_mon = 12;
67    
68     return 0;
69     }
70    
71     CString DateTimeConvert::strftime(void) const
72     {
73     //%y-%m-%d %H:%M:%S
74     CString str;
75    
76     str.Format("%d-%d-%d %.2d:%.2d:%.2d",
77     this->time.tm_year,this->time.tm_mon,this->time.tm_mday,
78     this->time.tm_hour,this->time.tm_min,this->time.tm_sec);
79    
80     return str;
81     }
82    
83     time_t DateTimeConvert::mktime(void)
84     {
85     return ::mktime(&(this->time));
86     }
87    
88     __time64_t DateTimeConvert::_mktime64(void)
89     {
90     return ::_mktime64(&(this->time));
91     }
92    
93     COleDateTime DateTimeConvert::ToOleDataTime(void) const
94     {
95     return COleDateTime(this->time.tm_year,this->time.tm_mon,this->time.tm_mday,
96     this->time.tm_hour,this->time.tm_min,this->time.tm_sec);
97     }
98    
99     DateTimeConvert::DateTimeConvert(TIMESTAMP_STRUCT* timestamp)
100     {
101     this->time.tm_year = timestamp->year;
102     this->time.tm_mon = timestamp->month;
103     this->time.tm_mday = timestamp->day;
104     this->time.tm_hour = timestamp->hour;
105     this->time.tm_min = timestamp->minute;
106     this->time.tm_sec = timestamp->day;
107     }
108    
109     CString DateTimeConvert::gmstrftime(void) const
110     {
111     //"%d %b %Y %H:%M:%S GMT"
112     CString str,month;
113    
114     switch(this->time.tm_mon)
115     {
116     case 1:
117     month="Jan";
118     break;
119     case 2:
120     month="Feb";
121     break;
122     case 3:
123     month="Mar";
124     break;
125     case 4:
126     month="Apr";
127     break;
128     case 5:
129     month="May";
130     break;
131     case 6:
132     month="Jun";
133     break;
134     case 7:
135     month="Jul";
136     break;
137     case 8:
138     month="Aug";
139     break;
140     case 9:
141     month="Sep";
142     break;
143     case 10:
144     month="Oct";
145     break;
146     case 11:
147     month="Nov";
148     break;
149     case 12:
150     month="Dec";
151     break;
152     default:
153     month="Jan";
154     }
155    
156     str.Format("%d %s %d %.2d:%.2d:%.2d GMT",
157     this->time.tm_mday,month,this->time.tm_year,
158     this->time.tm_hour,this->time.tm_min,this->time.tm_sec);
159    
160     return str;
161     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1