std::string CDateTime::GetLocalTime(std::string filter){ std::string sOutput; std::ostringstream oss; if(filter == "MM/DD/YY"){ oss << std::setfill ('0') << std::setw(2); oss << GetMonth() << "/" ; oss << std::setfill ('0') << std::setw(2); oss << GetDay() << "/"; oss << std::setfill ('0') << std::setw(2); oss << (GetYear() - 2000); sOutput = oss.str(); return sOutput; } else if(filter == "MM-DD-YYYY"){ oss << std::setfill ('0') << std::setw(2); oss << GetMonth() << "/" ; oss << std::setfill ('0') << std::setw(2); oss<< GetDay() << "/" << GetYear(); sOutput = oss.str(); return sOutput; } else if(filter == "MM.DD.YYYY"){ oss << std::setfill ('0') << std::setw(2); oss << GetMonth() << "." ; oss << std::setfill ('0') << std::setw(2); oss<< GetDay() << "." << GetYear(); sOutput = oss.str(); return sOutput; } else if(filter == "HH:MM"){ oss << std::setfill ('0') << std::setw(2); oss << GetHour() << ":" ; oss << std::setfill ('0') << std::setw(2); oss<< GetMinute(); sOutput = oss.str(); return sOutput; } else if(filter == "HH:MM:SS"){ oss << std::setfill ('0') << std::setw(2); oss << GetHour() << ":" ; oss << std::setfill ('0') << std::setw(2); oss<< GetMinute() << ":"; oss << std::setfill ('0') << std::setw(2); oss<< GetSecond(); sOutput = oss.str(); return sOutput; } else if(filter == "MONTH D, YYYY"){ oss << GetMonthName() << " "; oss << GetDay() << ", " ; //oss << std::setfill ('0') << std::setw(2); oss<< GetYear(); sOutput = oss.str(); return sOutput; } return ""; }
// draw the month/year header (ie. January 2000) int CMiniCalendarCtrl::DrawHeader(CDC& _dc, int _iY, int _iLeftX, int _iRow, int _iMonth, int _iYear) { CString strText = GetMonthName(_iMonth); strText += " "; strText += CCalendarUtils::LongToString(_iYear); _dc.FillSolidRect(_iLeftX, _iY, m_szMonthSize.cx-1, m_iHeaderHeight, ::GetSysColor(COLOR_BTNFACE)); _dc.Draw3dRect(_iLeftX, _iY, m_szMonthSize.cx-1, m_iHeaderHeight, m_cBackColor, ::GetSysColor(COLOR_3DSHADOW)); CFont* pOldFont = _dc.SelectObject(m_pFontBold); _dc.SetBkColor(::GetSysColor(COLOR_BTNFACE)); _dc.SetTextColor(MINICAL_COLOUR_HEADERFONT); _dc.SetBkMode(TRANSPARENT); _dc.DrawText(strText, CRect(_iLeftX+1, _iY+1, _iLeftX+m_szMonthSize.cx-2, _iY+m_iHeaderHeight-2), DT_CENTER | DT_VCENTER | DT_SINGLELINE); _dc.SelectObject(pOldFont); SetCellHeaderPosition(_iRow, CRect(_iLeftX+10, _iY+1, _iLeftX+m_szMonthSize.cx - 20, _iY+m_iHeaderHeight-2)); if (_iRow == 1) { // deal with left scroll bar const int iMiddle = _iY + (m_iHeaderHeight / 2); const int iTop = iMiddle - (m_iHeaderHeight / 4); const int iBottom = iMiddle + (m_iHeaderHeight / 4); int iLineY = 0; int iX1 = _iLeftX + 6; int iX2 = iX1 + ((m_iHeaderHeight / 4)); for (iLineY = iTop; iLineY <= iBottom; iLineY++) { _dc.MoveTo(iX1, iMiddle); _dc.LineTo(iX2, iLineY); } m_rectScrollLeft.SetRect(iX1-1, iTop-1, iX2+1, iBottom+1); // deal with right scroll bar iX1 = _iLeftX + m_szMonthSize.cx - 10; iX2 = iX1 - (m_iHeaderHeight / 4); for (iLineY = iTop; iLineY <= iBottom; iLineY++) { _dc.MoveTo(iX1, iMiddle); _dc.LineTo(iX2, iLineY); } m_rectScrollRight.SetRect(iX2-1, iTop-1, iX1+1, iBottom+1); } return m_iHeaderHeight; }
//--------------------------------------------------------------------------- bool GregorianDate::SetDate(Date *newDate, Integer format) { // Check validity on date first then convert to string if (!newDate->IsValid()) { MessageInterface::ShowMessage(wxT("Warning: Can't set date to string\n")); return (isValid = false); } wxString temp; // Convert the date format in string if (format == 2) { temp += NumToString(newDate->GetYear()) + wxT("-"); temp += NumToString(newDate->GetMonth()) + wxT("-"); temp += NumToString(newDate->GetDay()) + wxT("T"); temp += NumToString(newDate->GetHour()) + wxT(":"); temp += NumToString(newDate->GetMinute()) + wxT(":"); temp += NumToString(newDate->GetSecond()); stringDate = temp; } else { temp = NumToString(newDate->GetDay()); temp += wxT(" ") + GetMonthName(newDate->GetMonth()) + wxT(" "); temp += NumToString(newDate->GetYear()) + wxT(" "); temp += NumToString(newDate->GetHour()) + wxT(":"); temp += NumToString(newDate->GetMinute()) + wxT(":"); temp += NumToString(newDate->GetSecond()); stringDate = temp; } stringYMDHMS = newDate->ToPackedCalendarString(); type = wxT("Gregorian"); return (isValid = true); }
// determine size of a given cell based on actual font settings CSize CMiniCalendarCtrl::ComputeSize() { const int iXDaysSpaceFromBorder = 15; const int iHeaderSpaceForBorder = 15; const int iHeaderYSpaceForBorder = 3; const int iDaysXSpacing = 5; const int iDaysYSpacing = 2; CSize szReturn(0, 0); int iWidthByDays = 0; int iWidthByDaysOfWeekIndividual = 0; int iWidthByHeader = 0; int iHeaderHeight = 0; int iDaysHeight = 0; int iX; // allocate a DC to use when testing sizes, etc CClientDC* pDC = NULL; if (::IsWindow(GetSafeHwnd())) pDC = new CClientDC(this); else pDC = new CClientDC(AfxGetMainWnd()); ASSERT(pDC); if (!pDC) throw (new CMemoryException()); // get current font and save for later restoration CFont* pOldFont = pDC->GetCurrentFont(); // first, use days to determine width // NOTE: typically, most fonts use the same pixel sizes for all numbers, // but this is not mandatory and many "fancy" fonts change this. To deal // with this, I am calculating the width of all possible dates the control will display pDC->SelectObject(m_pFont); for (iX = 1; iX <= 31; iX++) { CString strTemp = "00"; strTemp += CCalendarUtils::LongToString(iX); strTemp = strTemp.Right(2); CSize szTemp = pDC->GetTextExtent(strTemp); if (szTemp.cx > iWidthByDays) iWidthByDays = szTemp.cx; if (szTemp.cy > iDaysHeight) iDaysHeight = szTemp.cy; } // make sure we also try it with the special days font pDC->SelectObject(m_pFontBold); for (iX = 1; iX <= 31; iX++) { CString strTemp = "00"; strTemp += CCalendarUtils::LongToString(iX); strTemp = strTemp.Right(2); CSize szTemp = pDC->GetTextExtent(strTemp); if (szTemp.cx > iWidthByDays) iWidthByDays = szTemp.cx; if (szTemp.cy > iDaysHeight) iDaysHeight = szTemp.cy; } // finish computation m_iDaysHeight = iDaysHeight; m_iIndividualDayWidth = iWidthByDays; iWidthByDays = (iWidthByDays * 7) + (iDaysXSpacing*6) + (iXDaysSpaceFromBorder*2); iDaysHeight = (iDaysHeight * 6) + (iDaysYSpacing*6); // next use days of week to determine width and height. here again, we test each variant pDC->SelectObject(m_pFont); int iWidthByDaysOfWeek = pDC->GetTextExtent("S").cx; if (pDC->GetTextExtent("M").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("M").cx; if (pDC->GetTextExtent("T").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("T").cx; if (pDC->GetTextExtent("W").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("W").cx; if (pDC->GetTextExtent("F").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("F").cx; int iDaysOfWeekHeight = pDC->GetTextExtent("S").cy; if (pDC->GetTextExtent("M").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("M").cy; if (pDC->GetTextExtent("T").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("T").cy; if (pDC->GetTextExtent("W").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("W").cy; if (pDC->GetTextExtent("F").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("F").cy; // finish computation iWidthByDaysOfWeekIndividual = iWidthByDaysOfWeek; iWidthByDaysOfWeek = (iWidthByDaysOfWeek * 7) + (iDaysXSpacing*6) + (iXDaysSpaceFromBorder*2); if (iWidthByDaysOfWeekIndividual > m_iIndividualDayWidth) m_iIndividualDayWidth = iWidthByDaysOfWeekIndividual; m_iDaysOfWeekHeight = iDaysOfWeekHeight; // next compute width and height of header (month name and year) // again, because of font variations we will use a 20 year window and // attempt the calculation with every month name pDC->SelectObject(m_pFontBold); for (int iYear = m_iCurrentYear-10; iYear <= m_iCurrentYear+10; iYear++) { for (int iMonth = 1; iMonth <= 12; iMonth++) { CString strTest = GetMonthName(iMonth); strTest += " "; strTest += CCalendarUtils::LongToString(iYear); if (pDC->GetTextExtent(strTest).cx > iWidthByHeader) iWidthByHeader = pDC->GetTextExtent(strTest).cx; if (pDC->GetTextExtent(strTest).cy > iHeaderHeight) iHeaderHeight = pDC->GetTextExtent(strTest).cy; } } // finish computation iWidthByHeader += (iHeaderSpaceForBorder*2); iHeaderHeight += (iHeaderYSpaceForBorder*2); m_iHeaderHeight = iHeaderHeight; // cleanup DC pDC->SelectObject(pOldFont); // destroy DC delete pDC; // NOW, adjust return size if needed // start with widths (these are easy at this point) int iTotalWidth = iWidthByHeader; if (iWidthByDaysOfWeek > iTotalWidth) iTotalWidth = iWidthByDaysOfWeek; if (iWidthByDays > iTotalWidth) iTotalWidth = iWidthByDays; if (iTotalWidth > szReturn.cx) szReturn.cx = iTotalWidth; // adjust heights int iTotalHeight = iHeaderHeight + iDaysOfWeekHeight + iDaysHeight + 12; if (iTotalHeight > szReturn.cy) szReturn.cy = iTotalHeight; m_szMonthSize = szReturn; m_bSizeComputed = TRUE; return szReturn; }
static void GenArcName(wchar *ArcName,const wchar *GenerateMask,uint ArcNumber,bool &ArcNumPresent) { bool Prefix=false; if (*GenerateMask=='+') { Prefix=true; // Add the time string before the archive name. GenerateMask++; // Skip '+' in the beginning of time mask. } wchar Mask[MAX_GENERATE_MASK]; wcsncpyz(Mask,*GenerateMask!=0 ? GenerateMask:L"yyyymmddhhmmss",ASIZE(Mask)); bool QuoteMode=false,Hours=false; for (uint I=0;Mask[I]!=0;I++) { if (Mask[I]=='{' || Mask[I]=='}') { QuoteMode=(Mask[I]=='{'); continue; } if (QuoteMode) continue; int CurChar=toupperw(Mask[I]); if (CurChar=='H') Hours=true; if (Hours && CurChar=='M') { // Replace minutes with 'I'. We use 'M' both for months and minutes, // so we treat as minutes only those 'M' which are found after hours. Mask[I]='I'; } if (CurChar=='N') { uint Digits=GetDigits(ArcNumber); uint NCount=0; while (toupperw(Mask[I+NCount])=='N') NCount++; // Here we ensure that we have enough 'N' characters to fit all digits // of archive number. We'll replace them by actual number later // in this function. if (NCount<Digits) { wmemmove(Mask+I+Digits,Mask+I+NCount,wcslen(Mask+I+NCount)+1); wmemset(Mask+I,'N',Digits); } I+=Max(Digits,NCount)-1; ArcNumPresent=true; continue; } } RarTime CurTime; CurTime.SetCurrentTime(); RarLocalTime rlt; CurTime.GetLocal(&rlt); wchar Ext[NM],*Dot=GetExt(ArcName); *Ext=0; if (Dot==NULL) wcscpy(Ext,*PointToName(ArcName)==0 ? L".rar":L""); else { wcsncpyz(Ext,Dot,ASIZE(Ext)); *Dot=0; } int WeekDay=rlt.wDay==0 ? 6:rlt.wDay-1; int StartWeekDay=rlt.yDay-WeekDay; if (StartWeekDay<0) if (StartWeekDay<=-4) StartWeekDay+=IsLeapYear(rlt.Year-1) ? 366:365; else StartWeekDay=0; int CurWeek=StartWeekDay/7+1; if (StartWeekDay%7>=4) CurWeek++; char Field[10][6]; sprintf(Field[0],"%04d",rlt.Year); sprintf(Field[1],"%02d",rlt.Month); sprintf(Field[2],"%02d",rlt.Day); sprintf(Field[3],"%02d",rlt.Hour); sprintf(Field[4],"%02d",rlt.Minute); sprintf(Field[5],"%02d",rlt.Second); sprintf(Field[6],"%02d",CurWeek); sprintf(Field[7],"%d",WeekDay+1); sprintf(Field[8],"%03d",rlt.yDay+1); sprintf(Field[9],"%05d",ArcNumber); const wchar *MaskChars=L"YMDHISWAEN"; int CField[sizeof(Field)/sizeof(Field[0])]; memset(CField,0,sizeof(CField)); QuoteMode=false; for (int I=0;Mask[I]!=0;I++) { if (Mask[I]=='{' || Mask[I]=='}') { QuoteMode=(Mask[I]=='{'); continue; } if (QuoteMode) continue; const wchar *ChPtr=wcschr(MaskChars,toupperw(Mask[I])); if (ChPtr!=NULL) CField[ChPtr-MaskChars]++; } wchar DateText[MAX_GENERATE_MASK]; *DateText=0; QuoteMode=false; for (size_t I=0,J=0;Mask[I]!=0 && J<ASIZE(DateText)-1;I++) { if (Mask[I]=='{' || Mask[I]=='}') { QuoteMode=(Mask[I]=='{'); continue; } const wchar *ChPtr=wcschr(MaskChars,toupperw(Mask[I])); if (ChPtr==NULL || QuoteMode) { DateText[J]=Mask[I]; #ifdef _WIN_ALL // We do not allow ':' in Windows because of NTFS streams. // Users had problems after specifying hh:mm mask. if (DateText[J]==':') DateText[J]='_'; #endif } else { size_t FieldPos=ChPtr-MaskChars; int CharPos=(int)strlen(Field[FieldPos])-CField[FieldPos]--; if (FieldPos==1 && toupperw(Mask[I+1])=='M' && toupperw(Mask[I+2])=='M') { wcsncpyz(DateText+J,GetMonthName(rlt.Month-1),ASIZE(DateText)-J); J=wcslen(DateText); I+=2; continue; } if (CharPos<0) DateText[J]=Mask[I]; else DateText[J]=Field[FieldPos][CharPos]; } DateText[++J]=0; } if (Prefix) { wchar NewName[NM]; GetFilePath(ArcName,NewName,ASIZE(NewName)); AddEndSlash(NewName,ASIZE(NewName)); wcsncatz(NewName,DateText,ASIZE(NewName)); wcsncatz(NewName,PointToName(ArcName),ASIZE(NewName)); wcscpy(ArcName,NewName); } else wcscat(ArcName,DateText); wcscat(ArcName,Ext); }