2009-05-07 19 views
0

と私は2回の間の時間を取得する方法を見つける必要がありますが、それは勤務時間内にある場合にのみ計算時間は、ツイスト

これは私が得たものです今、それは完全に間違っています。合計は正しいとは限りません。

int __fastcall Organisasjon::CalculateResponsetimeInOpeninghours(std::auto_ptr<DBCommand> cmd, long orgid, TDateTime starttimeIn, TDateTime endtimeIn) 
{ 
int totalTimeInQueue = 0; 
String sIsWorkDay = ""; 

String s = "SELECT o.isworkday, o.workdate, o.workstarttime, o.workendtime " \ 
       "FROM orgwdexcep o " \ 
       "WHERE o.workdate = :date " \ 
       "AND o.orgid = :orgid "; 
String s2 = "SELECT o.isworkday, o.workdate, o.workstarttime, o.workendtime " \ 
       "FROM globalwodexcep o " \ 
       "WHERE o.workdate = :date "; 
String s3 = "SELECT o.workstarttime, o.workendtime " \ 
       "FROM organizationworkday o " \ 
       "WHERE o.weekdayindex = :weekdayindex " \ 
       "AND o.orgid = :orgid "; 
double MailThisDayStart = starttimeIn; 
double MailThisDayEnd = endtimeIn; 

while ((int)MailThisDayStart <= (int)endtimeIn) 
{//for each day i period. 
    if((int)MailThisDayStart != (int)endtimeIn) 
    { 
     MailThisDayEnd = (double)((long)MailThisDayEnd) + 1; 
} 
    cmd->setCommandText(s); 
    cmd->Param("date").setAsDateTime() = DBDatabase::ConvertToSADateTime(MailThisDayStart); 
    cmd->Param("orgid").setAsLong() = orgid; 
    cmd->Execute(); 
    if (!(cmd->isResultSet() && cmd->FetchNext())) 
    { 
     cmd->setCommandText(s2); 
     cmd->Param("date").setAsDateTime() = DBDatabase::ConvertToSADateTime(MailThisDayStart); 
     cmd->Execute(); 
    } 
    if(cmd->isResultSet() && cmd->FetchNext()) 
    { 
     sIsWorkDay = String(cmd->Field("isworkday").asString()); 
    } 
    else 
    { 
     int dayOfTheWeek = DayOfTheWeek(MailThisDayStart); 
     cmd->setCommandText(s3); 
     cmd->Param("weekdayindex").setAsLong() = dayOfTheWeek; 
     cmd->Param("orgid").setAsLong() = orgid; 
     cmd->Execute(); 
     if(cmd->isResultSet() && cmd->FetchNext()) 
     { 
      sIsWorkDay = "T"; 
    } 
    } 
    if(sIsWorkDay == "T") 
    { 
     TDateTime tmpOpeningStart = TDateTime(cmd->Field("workstarttime").asDateTime()); 
     TDateTime tmpOpeningEnd = TDateTime(cmd->Field("workendtime").asDateTime()); 
     double dtmpOpeningStart = tmpOpeningStart- (int)tmpOpeningStart; 
     double dtmpOpeningEnd = tmpOpeningEnd- (int)tmpOpeningEnd; 

     totalTimeInQueue += Organisasjon::CountHours(MailThisDayStart, MailThisDayEnd, dtmpOpeningStart, dtmpOpeningEnd,(int)MailThisDayStart); 
    } 
    MailThisDayStart++;//increase date by one 
    MailThisDayStart = (double)((long)MailThisDayStart); 
} 
return totalTimeInQueue; 
} 

int __fastcall Organisasjon::CountHours(double MailTimeStart, double MailTimeEnd, double openingTimeStart, double openingTimeEnd, int DayToCompute) 
{ 
    if(MailTimeEnd<openingTimeStart) 
    { 
     return 0; 
     } 
    if(MailTimeStart<(DayToCompute+openingTimeStart)) 
    { 
     MailTimeStart=openingTimeStart; 
    } 
    else 
    { 
     MailTimeStart=MailTimeStart-(int)MailTimeStart; 
    } 
    if(MailTimeEnd>(DayToCompute+openingTimeEnd)) 
    { 
    MailTimeEnd=openingTimeEnd; 
    } 
    else 
    { 
    MailTimeEnd=MailTimeEnd-(int)MailTimeEnd; 
    } 
    TDateTime dt = TDateTime((MailTimeEnd - MailTimeStart)); 
    unsigned short milli; 
    unsigned short sec; 
    unsigned short min; 
    unsigned short hour; 
    dt.DecodeTime(&hour,&min,&sec,&milli); 
    int total = hour*3600; 
    total += min*60; 
    total += sec; 
    return total; 
} 
+0

workstarttimeフィールドとworkendtimeフィールドには、電子メールの作業時間または期間が格納されますか? – stukelly

+0

workstarttimeとworkendtimeは、指定された日付に組織の営業時間を格納します。組織作業日はid、orgId、weekDay、workStartTime、workEndTimeのようになります。 メソッドへのパラメータTDateTime starttimeIn、TDateTime endtimeInは、電子メールが最初にシステムに登録された時刻で、endtimeは誰かが応答した時刻です。 – Qwark

答えて

1

totalで何を表示しますか?

TDateTime MailTimeEnd = TDateTime::CurrentTime();; 
MailTimeEnd += 1.0/24; 
TDateTime MailTimeStart = TDateTime::CurrentTime(); 
TDateTime dt = TDateTime((MailTimeEnd - MailTimeStart)); 
unsigned short milli; 
unsigned short sec; 
unsigned short min; 
unsigned short hour; 
dt.DecodeTime(&hour,&min,&sec,&milli); 
int total = hour*3600; 
total += min*60; 
total += sec; 

total == 3600

は、この例を試してみてください。それはそうです。

+0

合計は電子メールが待ち行列で待機した合計秒数ですが、作業時間内の秒数が含まれていなければなりません。電子メールはキュー内で数日間待つことができたので、アルゴリズムは毎日営業時間をチェックする必要があります。 – Qwark