]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MIUtilDateTimeStd.cpp
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MIUtilDateTimeStd.cpp
1 //===-- MIUtilDateTimeStd.cpp -----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // In-house headers:
11 #include "MIUtilDateTimeStd.h"
12 #include "MICmnResources.h"
13
14 //++
15 //------------------------------------------------------------------------------------
16 // Details: CMIUtilDateTimeStd constructor.
17 // Type:    Method.
18 // Args:    None.
19 // Return:  None.
20 // Throws:  None.
21 //--
22 CMIUtilDateTimeStd::CMIUtilDateTimeStd() {}
23
24 //++
25 //------------------------------------------------------------------------------------
26 // Details: CMIUtilDateTimeStd destructor.
27 // Type:    Method.
28 // Args:    None.
29 // Return:  None.
30 // Throws:  None.
31 //--
32 CMIUtilDateTimeStd::~CMIUtilDateTimeStd() {}
33
34 //++
35 //------------------------------------------------------------------------------------
36 // Details: Retrieve system local current date. Format is MM/DD/YYYY.
37 // Type:    Method.
38 // Args:    None.
39 // Return:  CMIUtilString - Text description.
40 // Throws:  None.
41 //--
42 CMIUtilString CMIUtilDateTimeStd::GetDate() {
43   CMIUtilString strDate(MIRSRC(IDS_WORD_INVALIDBRKTS));
44
45   std::time(&m_rawTime);
46   const std::tm *pTi = std::localtime(&m_rawTime);
47   if (std::strftime(&m_pScratch[0], sizeof(m_pScratch), "%d/%m/%y", pTi) > 0)
48     strDate = m_pScratch;
49
50   return strDate;
51 }
52
53 //++
54 //------------------------------------------------------------------------------------
55 // Details: Retrieve system local current time. Format is HH:MM:SS 24 hour
56 // clock.
57 // Type:    Method.
58 // Args:    None.
59 // Return:  CMIUtilString - Text description.
60 // Throws:  None.
61 //--
62 CMIUtilString CMIUtilDateTimeStd::GetTime() {
63   std::time(&m_rawTime);
64   const std::tm *pTi = std::localtime(&m_rawTime);
65   const CMIUtilString seconds(CMIUtilString::Format("%d", pTi->tm_sec));
66   const CMIUtilString zero((seconds.length() == 1) ? "0" : "");
67   const CMIUtilString strTime(CMIUtilString::Format(
68       "%d:%d:%s%s", pTi->tm_hour, pTi->tm_min, zero.c_str(), seconds.c_str()));
69
70   return strTime;
71 }
72
73 //++
74 //------------------------------------------------------------------------------------
75 // Details: Retrieve system local current date and time in yyyy-MM-dd--HH-mm-ss
76 // format for log file names.
77 // Type:    Method.
78 // Args:    None.
79 // Return:  CMIUtilString - Text description.
80 // Throws:  None.
81 //--
82 CMIUtilString CMIUtilDateTimeStd::GetDateTimeLogFilename() {
83   std::time(&m_rawTime);
84   const std::tm *pTi = std::localtime(&m_rawTime);
85   const CMIUtilString strTime(CMIUtilString::Format(
86       "%d%02d%02d%02d%02d%02d", pTi->tm_year + 1900, pTi->tm_mon, pTi->tm_mday,
87       pTi->tm_hour, pTi->tm_min, pTi->tm_sec));
88
89   return strTime;
90 }