OpenMS
DateTime.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Nico Pfeifer $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/CONCEPT/Types.h>
12 #include <OpenMS/OpenMSConfig.h>
13 
14 #include <memory> // unique_ptr
15 #include <string>
16 
17 // foward declarations
18 class QDateTime;
19 
20 namespace OpenMS
21 {
22  class String;
23 
32  class OPENMS_DLLAPI DateTime
33  {
34 public:
35 
42 
44  DateTime(const DateTime& date);
45 
47  DateTime(DateTime&&) noexcept;
48 
50  DateTime& operator=(const DateTime& source);
51 
53  DateTime& operator=(DateTime&&) & noexcept;
54 
57 
59  bool operator==(const DateTime& rhs) const;
60 
62  bool operator!=(const DateTime& rhs) const;
63 
65  bool operator<(const DateTime& rhs) const;
66 
74  void setDate(const String& date);
75 
83  void setTime(const String& date);
84 
92  void setDate(UInt month, UInt day, UInt year);
93 
101  void setTime(UInt hour, UInt minute, UInt second);
102 
110  void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second);
111 
117  void get(UInt& month, UInt& day, UInt& year, UInt& hour, UInt& minute, UInt& second) const;
118 
124  void getDate(UInt& month, UInt& day, UInt& year) const;
125 
131  String getDate() const;
132 
138  void getTime(UInt& hour, UInt& minute, UInt& second) const;
139 
140  // add @param s seconds to date time
141  DateTime& addSecs(int s);
142 
148  String getTime() const;
149 
151  static DateTime now();
152 
154  bool isValid() const;
155 
157  bool isNull() const;
158 
160  void clear();
161 
162  /* @brief Returns a string representation of the DateTime object.
163  @param format "yyyy-MM-ddThh:mm:ss" corresponds to ISO 8601 and should be preferred.
164  */
165  String toString(const std::string& format = "yyyy-MM-ddThh:mm:ss") const;
166 
167  /* @brief Creates a DateTime object from string representation.
168  @param format "yyyy-MM-ddThh:mm:ss" corresponds to ISO 8601 and should be preferred.
169  */
170  static DateTime fromString(const std::string& date, const std::string& format = "yyyy-MM-ddThh:mm:ss");
171 
177  String get() const;
178 
192  void set(const String& date);
193 
194  private:
195  std::unique_ptr<QDateTime> dt_; // use PImpl, to avoid costly #include
196  };
197 
198 } // namespace OPENMS
DateTime Class.
Definition: DateTime.h:33
DateTime()
Default constructor.
DateTime(DateTime &&) noexcept
Move constructor.
DateTime(const DateTime &date)
Copy constructor.
A more convenient string class.
Definition: String.h:34
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
const std::string & toString(const DriftTimeUnit value)