// entity time (XEP-0202) support BOOL CJabberProto::OnIqRequestTime(HXML, CJabberIqInfo *pInfo) { TCHAR stime[100]; TCHAR szTZ[10]; TimeZone_PrintDateTime(UTC_TIME_HANDLE, _T("I"), stime, _countof(stime), 0); int nGmtOffset = GetGMTOffset(); mir_sntprintf(szTZ, _countof(szTZ), _T("%+03d:%02d"), nGmtOffset / 60, nGmtOffset % 60); XmlNodeIq iq(_T("result"), pInfo); HXML timeNode = iq << XCHILDNS(_T("time"), JABBER_FEAT_ENTITY_TIME); timeNode << XCHILD(_T("utc"), stime); timeNode << XCHILD(_T("tzo"), szTZ); LPCTSTR szTZName = TimeZone_GetName(NULL); if (szTZName) timeNode << XCHILD(_T("tz"), szTZName); m_ThreadInfo->send(iq); return TRUE; }
std::string DateTime::ToString(const TimeFormat& tf) const { char buffer[80]; struct tm timeParts = *this; //conversion operator std::string str; if(tf == TimeFormat::CALENDAR_DATE_AND_TIME_FORMAT) { //this case we must handle specially because the msvc compiler insists on //writing out the time zone for %z as opposed to printing the actual offset //this is what we want it to look like //2007-05-10T16:08:18.0-05:00 float tz = GetGMTOffset(); int tzHour = (int)floorf(tz); int tzMin = (int)(tz - float(tzHour)); snprintf(buffer, 80, "%04d-%02d-%02dT%02d:%02d:%02d%+03d:%02d", timeParts.tm_year + 1900, timeParts.tm_mon + 1, timeParts.tm_mday, timeParts.tm_hour, timeParts.tm_min, timeParts.tm_sec, tzHour, tzMin); } else { if(tf == TimeFormat::LOCAL_DATE_AND_TIME_FORMAT) { strftime(buffer, 80, "%c", &timeParts); } else if(tf == TimeFormat::CLOCK_TIME_12_HOUR_FORMAT) { strftime(buffer, 80, "%I:%M:%S %p", &timeParts); } else if(tf == TimeFormat::LOCAL_DATE_FORMAT) { strftime(buffer, 80, "%x", &timeParts); } else if(tf == TimeFormat::LEXICAL_DATE_FORMAT) { strftime(buffer, 80, "%B %d, %Y", &timeParts); } else if(tf == TimeFormat::CALENDAR_DATE_FORMAT) { strftime(buffer, 80, "%Y-%m-%d", &timeParts); } else if(tf == TimeFormat::CLOCK_TIME_24_HOUR_FORMAT) { strftime(buffer, 80, "%H:%M:%S", &timeParts); } else if(tf == TimeFormat::WEEK_DATE_FORMAT) { strftime(buffer, 80, "%Y-W%U-%w", &timeParts); } else if(tf == TimeFormat::ORDINAL_DATE_FORMAT) { strftime(buffer, 80, "%Y-%j", &timeParts); } } str.assign(buffer); return str; }