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 87 88 89 90
|
//===-- MIUtilDateTimeStd.cpp -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// In-house headers:
#include "MIUtilDateTimeStd.h"
#include "MICmnResources.h"
//++
//------------------------------------------------------------------------------------
// Details: CMIUtilDateTimeStd constructor.
// Type: Method.
// Args: None.
// Return: None.
// Throws: None.
//--
CMIUtilDateTimeStd::CMIUtilDateTimeStd() {}
//++
//------------------------------------------------------------------------------------
// Details: CMIUtilDateTimeStd destructor.
// Type: Method.
// Args: None.
// Return: None.
// Throws: None.
//--
CMIUtilDateTimeStd::~CMIUtilDateTimeStd() {}
//++
//------------------------------------------------------------------------------------
// Details: Retrieve system local current date. Format is MM/DD/YYYY.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text description.
// Throws: None.
//--
CMIUtilString CMIUtilDateTimeStd::GetDate() {
CMIUtilString strDate(MIRSRC(IDS_WORD_INVALIDBRKTS));
std::time(&m_rawTime);
const std::tm *pTi = std::localtime(&m_rawTime);
if (std::strftime(&m_pScratch[0], sizeof(m_pScratch), "%d/%m/%y", pTi) > 0)
strDate = m_pScratch;
return strDate;
}
//++
//------------------------------------------------------------------------------------
// Details: Retrieve system local current time. Format is HH:MM:SS 24 hour
// clock.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text description.
// Throws: None.
//--
CMIUtilString CMIUtilDateTimeStd::GetTime() {
std::time(&m_rawTime);
const std::tm *pTi = std::localtime(&m_rawTime);
const CMIUtilString seconds(CMIUtilString::Format("%d", pTi->tm_sec));
const CMIUtilString zero((seconds.length() == 1) ? "0" : "");
const CMIUtilString strTime(CMIUtilString::Format(
"%d:%d:%s%s", pTi->tm_hour, pTi->tm_min, zero.c_str(), seconds.c_str()));
return strTime;
}
//++
//------------------------------------------------------------------------------------
// Details: Retrieve system local current date and time in yyyy-MM-dd--HH-mm-ss
// format for log file names.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text description.
// Throws: None.
//--
CMIUtilString CMIUtilDateTimeStd::GetDateTimeLogFilename() {
std::time(&m_rawTime);
const std::tm *pTi = std::localtime(&m_rawTime);
const CMIUtilString strTime(CMIUtilString::Format(
"%d%02d%02d%02d%02d%02d", pTi->tm_year + 1900, pTi->tm_mon, pTi->tm_mday,
pTi->tm_hour, pTi->tm_min, pTi->tm_sec));
return strTime;
}
|