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