RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
DateTime.hpp
1 /*
2  * DateTime.hpp
3  *
4  * Copyright (C) 2019-20 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #ifndef LAUNCHER_PLUGINS_DATE_TIME_HPP
25 #define LAUNCHER_PLUGINS_DATE_TIME_HPP
26 
27 #include <string>
28 
29 #include <ctime>
30 #include <PImpl.hpp>
31 namespace rstudio {
32 namespace launcher_plugins {
33 
34 class Error;
35 
36 } // namespace launcher_plugins
37 } // namespace rstudio
38 namespace rstudio {
39 namespace launcher_plugins {
40 namespace system {
41 
42 // Forward Declaration
43 class DateTime;
44 
48 class TimeDuration final
49 {
50 public:
59  explicit TimeDuration(
60  int64_t in_hours = 0,
61  int64_t in_minutes = 0,
62  int64_t in_seconds = 0,
63  int64_t in_microseconds = 0);
64 
70  TimeDuration(const TimeDuration& in_other);
71 
77  TimeDuration(TimeDuration&& in_other) noexcept;
78 
82  ~TimeDuration() = default;
83 
89  static TimeDuration Infinity();
90 
98  static TimeDuration Hours(int64_t in_hours);
99 
107  static TimeDuration Minutes(int64_t in_minutes);
108 
116  static TimeDuration Seconds(int64_t in_seconds);
117 
125  static TimeDuration Microseconds(int64_t in_microseconds);
126 
134  TimeDuration& operator=(const TimeDuration& in_other);
135 
144  TimeDuration& operator=(TimeDuration&& in_other) noexcept;
145 
153  bool operator==(const TimeDuration& in_other) const;
154 
155 
163  bool operator!=(const TimeDuration& in_other) const;
164 
172  bool operator<(const TimeDuration& in_other) const;
173 
181  bool operator<=(const TimeDuration& in_other) const;
182 
190  bool operator>(const TimeDuration& in_other) const;
191 
199  bool operator>=(const TimeDuration& in_other) const;
200 
206  bool isInfinity() const;
207 
213  int64_t getHours() const;
214 
220  int64_t getMinutes() const;
221 
227  int64_t getSeconds() const;
228 
234  int64_t getMicroseconds() const;
235 
236 private:
237  // The private implementation of interval time.
238  PRIVATE_IMPL(m_impl);
239 
240  friend class DateTime;
241 };
242 
244 class DateTime final
245 {
246 public:
252  DateTime();
253 
259  DateTime(const DateTime& in_other);
260 
266  DateTime(DateTime&& in_other) noexcept;
267 
273  DateTime(std::time_t& in_time) noexcept;
274 
292  static Error fromString(const std::string& in_timeStr, DateTime& out_dateTime);
293 
306  static Error fromString(const std::string& in_timeStr, const std::string& in_format, DateTime& out_dateTime);
314  DateTime& operator=(const DateTime& in_other);
315 
323  DateTime& operator=(DateTime&& in_other) noexcept;
324 
332  TimeDuration operator-(const DateTime& in_other) const;
333 
341  DateTime operator-(const TimeDuration& in_intervalTime) const;
342 
350  DateTime& operator-=(const TimeDuration& in_intervalTime);
351 
359  DateTime operator+(const TimeDuration& in_intervalTime) const;
360 
368  DateTime& operator+=(const TimeDuration& in_intervalTime);
369 
377  bool operator==(const DateTime& in_other) const;
378 
386  bool operator!=(const DateTime& in_other) const;
387 
395  bool operator<(const DateTime& in_other) const;
396 
404  bool operator<=(const DateTime& in_other) const;
405 
413  bool operator>(const DateTime& in_other) const;
414 
422  bool operator>=(const DateTime& in_other) const;
423 
429  std::string toString() const;
430 
439  std::string toString(const char* in_format) const;
440 
449  std::string toString(const std::string& in_format) const;
450 
451 private:
452  // The private implementation of DateTime.
453  PRIVATE_IMPL(m_impl);
454 };
455 
456 } // namespace system
457 } // namespace launcher_plugins
458 } // namespace rstudio
459 
460 #endif
rstudio::launcher_plugins::system::TimeDuration::Infinity
static TimeDuration Infinity()
Constructs a TimeDuration which represents "any amount of time". Use with caution.
rstudio::launcher_plugins::system::DateTime::operator>=
bool operator>=(const DateTime &in_other) const
Less than operator.
rstudio::launcher_plugins::system::TimeDuration::operator!=
bool operator!=(const TimeDuration &in_other) const
Inequality comparison operator.
rstudio::launcher_plugins::system::TimeDuration::Minutes
static TimeDuration Minutes(int64_t in_minutes)
Constructs an TimeDuration which represents the specified number of minutes.
rstudio::launcher_plugins::system::TimeDuration::getHours
int64_t getHours() const
Gets the number of hours in this TimeDuration.
rstudio::launcher_plugins::system::TimeDuration::getSeconds
int64_t getSeconds() const
Gets the number of seconds in this TimeDuration.
rstudio::launcher_plugins::system::TimeDuration::~TimeDuration
~TimeDuration()=default
Destructor.
rstudio::launcher_plugins::system::TimeDuration::getMinutes
int64_t getMinutes() const
Gets the number of minutes in this TimeDuration.
rstudio::launcher_plugins::system::DateTime::operator+=
DateTime & operator+=(const TimeDuration &in_intervalTime)
Adds the given TimeDuration to this DateTime.
rstudio::launcher_plugins::system::DateTime::operator<=
bool operator<=(const DateTime &in_other) const
Less than operator.
rstudio::launcher_plugins::system::TimeDuration::operator>
bool operator>(const TimeDuration &in_other) const
Greater-than comparison operator.
rstudio::launcher_plugins::system::TimeDuration::getMicroseconds
int64_t getMicroseconds() const
Gets the number of days in this TimeDuration.
rstudio::launcher_plugins::system::TimeDuration::operator>=
bool operator>=(const TimeDuration &in_other) const
Greater-than-equal comparison operator.
rstudio::launcher_plugins::system::DateTime::toString
std::string toString() const
Converts this DateTime to an ISO 8601 time string.
rstudio::launcher_plugins::system::DateTime::DateTime
DateTime()
Constructor.
rstudio::launcher_plugins::system::TimeDuration::TimeDuration
TimeDuration(int64_t in_hours=0, int64_t in_minutes=0, int64_t in_seconds=0, int64_t in_microseconds=0)
Constructor.
rstudio::launcher_plugins::system::DateTime::operator>
bool operator>(const DateTime &in_other) const
Less than operator.
rstudio::launcher_plugins::system::DateTime::fromString
static Error fromString(const std::string &in_timeStr, DateTime &out_dateTime)
Constructs a DateTime by calling FromString and passing the default ISO 8601 string reperesentation....
rstudio::launcher_plugins::system::DateTime
Class which represents a date and time in UTC.
Definition: DateTime.hpp:244
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::system::DateTime::operator=
DateTime & operator=(const DateTime &in_other)
Assignment operator.
rstudio::launcher_plugins::system::TimeDuration::operator==
bool operator==(const TimeDuration &in_other) const
Equality comparison operator.
rstudio::launcher_plugins::system::DateTime::operator-
TimeDuration operator-(const DateTime &in_other) const
Subtracts two DateTimes to produce an TimeDuration.
rstudio::launcher_plugins::system::TimeDuration
Represents an duration of time (e.g. 5 hours, 43 minutes, and 21 seconds) as opposed to a point in ti...
Definition: DateTime.hpp:48
rstudio::launcher_plugins::system::TimeDuration::Hours
static TimeDuration Hours(int64_t in_hours)
Constructs an TimeDuration which represents the specified number of hours.
rstudio::launcher_plugins::system::DateTime::operator-=
DateTime & operator-=(const TimeDuration &in_intervalTime)
Subtracts the given TimeDuration from this DateTime.
rstudio::launcher_plugins::system::TimeDuration::Seconds
static TimeDuration Seconds(int64_t in_seconds)
Constructs an TimeDuration which represents the specified number of seconds.
rstudio::launcher_plugins::system::DateTime::operator+
DateTime operator+(const TimeDuration &in_intervalTime) const
Adds the given TimeDuration to a copy of this DateTime.
rstudio::launcher_plugins::system::TimeDuration::Microseconds
static TimeDuration Microseconds(int64_t in_microseconds)
Constructs an TimeDuration which represents the specified number of microseconds.
rstudio::launcher_plugins::system::TimeDuration::operator=
TimeDuration & operator=(const TimeDuration &in_other)
Assignment operator.
rstudio::launcher_plugins::system::DateTime::operator==
bool operator==(const DateTime &in_other) const
Equality operator.
rstudio::launcher_plugins::system::DateTime::operator!=
bool operator!=(const DateTime &in_other) const
Inequality operator.
rstudio::launcher_plugins::system::TimeDuration::operator<=
bool operator<=(const TimeDuration &in_other) const
Less-than-equal comparison operator.
rstudio::launcher_plugins::system::TimeDuration::operator<
bool operator<(const TimeDuration &in_other) const
Less-than comparison operator.
rstudio::launcher_plugins::system::DateTime::operator<
bool operator<(const DateTime &in_other) const
Less than operator.
rstudio::launcher_plugins::system::TimeDuration::isInfinity
bool isInfinity() const
Checks whether this TimeDuration represents "any amount of time".