Present  0.9
 All Classes Files Functions Variables Typedefs Friends Macros Pages
day-delta.h
Go to the documentation of this file.
1 /*
2  * Present - Date/Time Library
3  *
4  * Definition of the DayDelta structure and declarations of the corresponding
5  * functions
6  *
7  * This file may be included individually ONLY if being used by a C compiler.
8  * However, it is recommended (and required for C++ projects) to include
9  * "present.h" rather than these individual header files.
10  *
11  * Licensed under the MIT License.
12  * For details, see LICENSE.
13  */
14 
15 #include <time.h>
16 
17 #include "present/internal/cpp-guard.h"
18 #include "present/internal/header-utils.h"
19 #include "present/internal/types.h"
20 
21 #include "present/internal/present-day-delta-data.h"
22 
23 #ifndef _PRESENT_DAY_DELTA_H_
24 #define _PRESENT_DAY_DELTA_H_
25 
26 /*
27  * Forward Declarations
28  */
29 
30 struct TimeDelta;
31 
32 /*
33  * C++ Class / C Struct Definition
34  */
35 
40 struct PRESENT_API DayDelta {
41  /* Internal data representation */
42  struct PresentDayDeltaData data_;
43 
44 #ifdef __cplusplus
45 
46  static DayDelta from_days(int_delta days);
47 
49  static DayDelta from_weeks(int_delta weeks);
50 
52  static DayDelta zero();
53 
55  int_delta days() const;
56 
58  int_delta weeks() const;
59 
61  double weeks_decimal() const;
62 
64  TimeDelta to_TimeDelta() const;
65 
67  bool is_negative() const;
68 
70  void negate();
71 
76  DayDelta operator-() const;
77 
79  DayDelta & operator++();
81  DayDelta operator++(int);
83  DayDelta & operator--();
85  DayDelta operator--(int);
86 
88  DayDelta & operator*=(const long & scale_factor);
90  DayDelta & operator/=(const long & scale_factor);
91 
93  friend const DayDelta operator*(
94  const DayDelta & delta,
95  const long & scale_factor);
97  friend const DayDelta operator/(
98  const DayDelta & delta,
99  const long & scale_factor);
100 
102  DayDelta & operator+=(const DayDelta & other);
104  DayDelta & operator-=(const DayDelta & other);
105 
107  friend const DayDelta operator+(
108  const DayDelta & lhs,
109  const DayDelta & rhs);
111  friend const DayDelta operator-(
112  const DayDelta & lhs,
113  const DayDelta & rhs);
114 
116  static short compare(const DayDelta & lhs, const DayDelta & rhs);
117 
119  static short compare(const DayDelta & lhs, const TimeDelta & rhs);
121  static short compare(const TimeDelta & lhs, const DayDelta & rhs);
122 
124  friend bool operator==(const DayDelta & lhs, const DayDelta & rhs);
126  friend bool operator==(const DayDelta & lhs, const TimeDelta & rhs);
127 
128  friend bool operator!=(const DayDelta & lhs, const DayDelta & rhs);
129  friend bool operator!=(const DayDelta & lhs, const TimeDelta & rhs);
130 
132  friend bool operator<(const DayDelta & lhs, const DayDelta & rhs);
134  friend bool operator<(const DayDelta & lhs, const TimeDelta & rhs);
135 
137  friend bool operator<=(const DayDelta & lhs, const DayDelta & rhs);
139  friend bool operator<=(const DayDelta & lhs, const TimeDelta & rhs);
140 
142  friend bool operator>(const DayDelta & lhs, const DayDelta & rhs);
144  friend bool operator>(const DayDelta & lhs, const TimeDelta & rhs);
145 
147  friend bool operator>=(const DayDelta & lhs, const DayDelta & rhs);
149  friend bool operator>=(const DayDelta & lhs, const TimeDelta & rhs);
150 #endif
151 };
152 
153 /*
154  * C Method Declarations
155  */
156 
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160 
164 PRESENT_API struct DayDelta
166 
171 PRESENT_API void
172 DayDelta_ptr_from_days(struct DayDelta * const result, int_delta days);
173 
177 PRESENT_API struct DayDelta
179 
184 PRESENT_API void
185 DayDelta_ptr_from_weeks(struct DayDelta * const result, int_delta weeks);
186 
190 PRESENT_API struct DayDelta
191 DayDelta_zero(void);
192 
197 PRESENT_API void
198 DayDelta_ptr_zero(struct DayDelta * const result);
199 
203 PRESENT_API int_delta
204 DayDelta_days(const struct DayDelta * const self);
205 
210 PRESENT_API int_delta
211 DayDelta_weeks(const struct DayDelta * const self);
212 
217 PRESENT_API double
218 DayDelta_weeks_decimal(const struct DayDelta * const self);
219 
223 PRESENT_API struct TimeDelta
224 DayDelta_to_TimeDelta(const struct DayDelta * const self);
225 
229 PRESENT_API present_bool
230 DayDelta_is_negative(const struct DayDelta * const self);
231 
236 PRESENT_API void
237 DayDelta_negate(struct DayDelta * const self);
238 
242 PRESENT_API void
243 DayDelta_multiply_by(struct DayDelta * const self, long scale_factor);
244 
248 PRESENT_API void
249 DayDelta_divide_by(struct DayDelta * const self, long scale_factor);
250 
255 PRESENT_API void
257  struct DayDelta * const self,
258  const struct DayDelta * const other);
259 
264 PRESENT_API void
266  struct DayDelta * const self,
267  const struct DayDelta * const other);
268 
276 PRESENT_API short
278  const struct DayDelta * const lhs,
279  const struct DayDelta * const rhs);
280 
288 PRESENT_API short
290  const struct DayDelta * const lhs,
291  const struct TimeDelta * const rhs);
292 
296 PRESENT_API present_bool
298  const struct DayDelta * const lhs,
299  const struct DayDelta * const rhs);
300 
304 PRESENT_API present_bool
306  const struct DayDelta * const lhs,
307  const struct TimeDelta * const rhs);
308 
312 PRESENT_API present_bool
314  const struct DayDelta * const lhs,
315  const struct DayDelta * const rhs);
316 
320 PRESENT_API present_bool
322  const struct DayDelta * const lhs,
323  const struct TimeDelta * const rhs);
324 
329 PRESENT_API present_bool
331  const struct DayDelta * const lhs,
332  const struct DayDelta * const rhs);
333 
338 PRESENT_API present_bool
340  const struct DayDelta * const lhs,
341  const struct TimeDelta * const rhs);
342 
346 PRESENT_API present_bool
348  const struct DayDelta * const lhs,
349  const struct DayDelta * const rhs);
350 
354 PRESENT_API present_bool
356  const struct DayDelta * const lhs,
357  const struct TimeDelta * const rhs);
358 
363 PRESENT_API present_bool
365  const struct DayDelta * const lhs,
366  const struct DayDelta * const rhs);
367 
372 PRESENT_API present_bool
374  const struct DayDelta * const lhs,
375  const struct TimeDelta * const rhs);
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 
381 #endif /* _PRESENT_DAY_DELTA_H_ */
382 
int_delta DayDelta_weeks(const struct DayDelta *const self)
Get the number of weeks represented by a DayDelta.
short DayDelta_compare_to_TimeDelta(const struct DayDelta *const lhs, const struct TimeDelta *const rhs)
Compare a DayDelta to a TimeDelta.
struct DayDelta DayDelta_from_weeks(int_delta weeks)
Create a new DayDelta based on a positive or negative number of weeks.
int_delta DayDelta_days(const struct DayDelta *const self)
Get the number of days represented by a DayDelta.
double DayDelta_weeks_decimal(const struct DayDelta *const self)
Get the number of weeks represented by a DayDelta, with a fractional part if necessary.
present_int64 int_delta
Definition: types.h:86
void DayDelta_ptr_from_days(struct DayDelta *const result, int_delta days)
Create a new DayDelta based on a positive or negative number of days.
present_bool DayDelta_equal_TimeDelta(const struct DayDelta *const lhs, const struct TimeDelta *const rhs)
Determine whether a DayDelta equals a TimeDelta (lhs == rhs).
struct DayDelta DayDelta_zero(void)
Create a new DayDelta initialized to zero days.
void DayDelta_add(struct DayDelta *const self, const struct DayDelta *const other)
Add another DayDelta to a DayDelta.
present_bool DayDelta_less_than(const struct DayDelta *const lhs, const struct DayDelta *const rhs)
Determine whether a DayDelta is less than another DayDelta (lhs < rhs).
present_bool DayDelta_less_than_or_equal(const struct DayDelta *const lhs, const struct DayDelta *const rhs)
Determine whether a DayDelta is less than or equal to another DayDelta (lhs <= rhs).
present_bool DayDelta_greater_than_TimeDelta(const struct DayDelta *const lhs, const struct TimeDelta *const rhs)
Determine whether a DayDelta is greater than a TimeDelta (lhs > rhs).
present_bool DayDelta_less_than_TimeDelta(const struct DayDelta *const lhs, const struct TimeDelta *const rhs)
Determine whether a DayDelta is less than a TimeDelta (lhs < rhs).
void DayDelta_negate(struct DayDelta *const self)
Negate a DayDelta, making it negative if it was positive or positive if it was negative.
int_delta weeks() const
Get the number of weeks represented by a DayDelta.
void DayDelta_ptr_from_weeks(struct DayDelta *const result, int_delta weeks)
Create a new DayDelta based on a positive or negative number of weeks.
present_bool DayDelta_equal(const struct DayDelta *const lhs, const struct DayDelta *const rhs)
Determine whether two DayDelta instances are equal (lhs == rhs).
present_bool DayDelta_greater_than_or_equal_TimeDelta(const struct DayDelta *const lhs, const struct TimeDelta *const rhs)
Determine whether a DayDelta is greater than or equal to a TimeDelta (lhs >= rhs).
Class or struct representing a positive or negative delta of a number of days or weeks.
Definition: day-delta.h:40
Class or struct representing a positive or negative delta of a number of nanoseconds, seconds, minutes, hours, days, or weeks.
Definition: time-delta.h:40
struct TimeDelta DayDelta_to_TimeDelta(const struct DayDelta *const self)
Convert a DayDelta into an equivalent TimeDelta.
void DayDelta_subtract(struct DayDelta *const self, const struct DayDelta *const other)
Subtract another DayDelta from a DayDelta.
present_bool DayDelta_less_than_or_equal_TimeDelta(const struct DayDelta *const lhs, const struct TimeDelta *const rhs)
Determine whether a DayDelta is less than or equal to a TimeDelta (lhs <= rhs).
struct DayDelta DayDelta_from_days(int_delta days)
Create a new DayDelta based on a positive or negative number of days.
present_bool DayDelta_greater_than_or_equal(const struct DayDelta *const lhs, const struct DayDelta *const rhs)
Determine whether a DayDelta is greater than or equal to another DayDelta (lhs >= rhs)...
void DayDelta_multiply_by(struct DayDelta *const self, long scale_factor)
Scale a DayDelta by multiplying it by a scale factor.
int_delta days() const
Get the number of days represented by a DayDelta.
void DayDelta_ptr_zero(struct DayDelta *const result)
Create a new DayDelta initialized to zero days.
present_bool DayDelta_greater_than(const struct DayDelta *const lhs, const struct DayDelta *const rhs)
Determine whether a DayDelta is greater than another DayDelta (lhs > rhs).
void DayDelta_divide_by(struct DayDelta *const self, long scale_factor)
Scale a DayDelta by dividing it by a scale factor.
short DayDelta_compare(const struct DayDelta *const lhs, const struct DayDelta *const rhs)
Compare two DayDelta instances.
present_bool DayDelta_is_negative(const struct DayDelta *const self)
Determine whether a DayDelta is negative.
bool present_bool
Definition: types.h:21