Doxygen
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
24constexpr int SF_Date = 1<<0; //!< a date is presenting in the format string
25constexpr int SF_Time = 1<<1; //!< a time is presenting in the format string
26constexpr int SF_Seconds = 1<<2; //!< the seconds are presenting in the format string
27constexpr 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 */
32constexpr 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
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 */
60QCString 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 */
70QCString formatDateTime(const QCString &format,const std::tm &dt,int &formatUsed);
71
72/** Returns the filled in std::tm for the current date and time */
73std::tm getCurrentDateTime();
74
75/** Returns the current year as a string */
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 */
82
83#endif
This is an alternative implementation of QCString.
Definition qcstring.h:101
DateTimeType
Definition datetime.h:38
QCString dateToString(DateTimeType includeTime)
Returns the current date, when includeTime is set also the time is provided.
Definition datetime.cpp:63
constexpr int SF_Seconds
the seconds are presenting in the format string
Definition datetime.h:26
constexpr const char * SF_bit2str(int bitNumber)
Helper function that returns the name related one of the SF bits.
Definition datetime.h:32
QCString yearToString()
Returns the current year as a string.
Definition datetime.cpp:76
constexpr int SF_NumBits
number of bits in SF vector
Definition datetime.h:27
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:175
std::tm getCurrentDateTime()
Returns the filled in std::tm for the current date and time.
Definition datetime.cpp:30
constexpr int SF_Date
Date and time related functions.
Definition datetime.h:24
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:134
constexpr int SF_Time
a time is presenting in the format string
Definition datetime.h:25