Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
datetime.h
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2022 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
* Documents produced by Doxygen are derivative works derived from the
12
* input used in their production; they are not affected by this license.
13
*
14
*/
15
16
#ifndef DATETIME_H
17
#define DATETIME_H
18
19
#include <ctime>
20
#include "
qcstring.h
"
21
22
/** @brief Date and time related functions. */
23
24
constexpr
int
SF_Date
= 1<<0;
//!< a date is presenting in the format string
25
constexpr
int
SF_Time
= 1<<1;
//!< a time is presenting in the format string
26
constexpr
int
SF_Seconds
= 1<<2;
//!< the seconds are presenting in the format string
27
constexpr
int
SF_NumBits
= 3;
//!< number of bits in SF vector
28
29
/** Helper function that returns the name related one of the SF bits. Used for generating warnings.
30
* @param[in] bitNumber bit value in range [0..SF_NumBits) for which to return the string value.
31
*/
32
constexpr
const
char
*
SF_bit2str
(
int
bitNumber)
33
{
34
constexpr
const
char
*partNames[] = {
"date"
,
"time"
,
"seconds"
};
35
return
bitNumber>=0 && bitNumber<
SF_NumBits
? partNames[bitNumber] :
""
;
36
}
37
38
enum class
DateTimeType
{
DateTime
,
39
Date
,
40
Time
41
};
42
43
/** Returns the filled in std::tm for a given string representing a date and/or time.
44
*
45
* @param[in] spec The string representation of the date and/or time
46
* Possible formats:
47
* - the empty string: the current date and time is returned
48
* - `YYYY-MM-DD HH:MM:SS`: the date and time are fully specified
49
* - `YYYY-MM-DD HH:MM`: the date and time without seconds
50
* - `YYYY-MM-DD`: the date without time
51
* - `HH:MM:SS`: the time with seconds but without date
52
* - `HH:MM`: the time without seconds and without date
53
*
54
* @param[out] dt The corresponding datetime value.
55
* @param[out] format The parts that have been found in spec; a bitwise or
56
* of `SF_Date`, `SF_Time` and `SF_Seconds`.
57
* @returns An empty string if the spec has a supported format,
58
* or an error message if the format is invalid.
59
*/
60
QCString
dateTimeFromString
(
const
QCString
&spec,std::tm &dt,
int
&format);
61
62
63
/** Return a string representation for a given std::tm value that is formatted according to the
64
* pattern given by a format.
65
* @param[in] format the string used for format the date and time, e.g. `%Y-%m-%d`
66
* @param[in] dt the date and time value to fill in
67
* @param[out] formatUsed A bitwise OR of `SF_Date`, `SF_Time` and `SF_Seconds` representing the
68
* the types of markers found in the format string.
69
*/
70
QCString
formatDateTime
(
const
QCString
&format,
const
std::tm &dt,
int
&formatUsed);
71
72
/** Returns the filled in std::tm for the current date and time */
73
std::tm
getCurrentDateTime
();
74
75
/** Returns the current year as a string */
76
QCString
yearToString
();
77
78
/** Returns the current date, when \c includeTime is set also the time is provided.
79
* @param[in] includeTime include the time in the output
80
*/
81
QCString
dateToString
(
DateTimeType
includeTime);
82
83
#endif
QCString
This is an alternative implementation of QCString.
Definition
qcstring.h:101
DateTimeType
DateTimeType
Definition
datetime.h:38
DateTimeType::Date
@ Date
Definition
datetime.h:39
DateTimeType::DateTime
@ DateTime
Definition
datetime.h:38
DateTimeType::Time
@ Time
Definition
datetime.h:40
dateToString
QCString dateToString(DateTimeType includeTime)
Returns the current date, when includeTime is set also the time is provided.
Definition
datetime.cpp:62
SF_Seconds
constexpr int SF_Seconds
the seconds are presenting in the format string
Definition
datetime.h:26
SF_bit2str
constexpr const char * SF_bit2str(int bitNumber)
Helper function that returns the name related one of the SF bits.
Definition
datetime.h:32
yearToString
QCString yearToString()
Returns the current year as a string.
Definition
datetime.cpp:75
SF_NumBits
constexpr int SF_NumBits
number of bits in SF vector
Definition
datetime.h:27
formatDateTime
QCString formatDateTime(const QCString &format, const std::tm &dt, int &formatUsed)
Return a string representation for a given std::tm value that is formatted according to the pattern g...
Definition
datetime.cpp:174
getCurrentDateTime
std::tm getCurrentDateTime()
Returns the filled in std::tm for the current date and time.
Definition
datetime.cpp:29
SF_Date
constexpr int SF_Date
Date and time related functions.
Definition
datetime.h:24
dateTimeFromString
QCString dateTimeFromString(const QCString &spec, std::tm &dt, int &format)
Returns the filled in std::tm for a given string representing a date and/or time.
Definition
datetime.cpp:133
SF_Time
constexpr int SF_Time
a time is presenting in the format string
Definition
datetime.h:25
qcstring.h
src
datetime.h
Generated by
1.17.0