1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! > Rust implementation of `relativedelta` known from Python's [dateutil](https://pypi.org/project/python-dateutil/) library. Calculate dates by adding relative and offset values to a datetime instance. Currently, the [time](https://crates.io/crates/time) and [chrono](https://crates.io/crates/chrono) crates are supported.
//!
//! ## Usage
//!
//! Run `cargo add relativedelta` to add this crate to your project or put this in your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! relativedelta = "0.3"
//! ```
//!
//! ### Minimum Supported Rust Version (MSRV)
//!
//! This crate supports Rust 1.85.0 or later.
//!
//! ### Optional features
//!
//! - **chrono**: Enable support for the [chrono](https://crates.io/crates/chrono) crate.
//! - **time**: Enable support for the [time](https://crates.io/crates/time) crate.
//! - **serde**: Enable serialization/deserialization via [serde](https://crates.io/crates/serde).
//!
//! ## Overview
//!
//! The `RelativeDelta` datatype holds both relative and absolute values for *year*, *month*, *day*, *hour*, *minute*,
//! *second* and
//! *nanosecond*.
//!
//! Relative parts are manipulated and accessed through methods typically ending in "*s*" (e.g. `::with_years`,
//! `.and_days`).
//! Absolute values without "*s*" (e.g. `::with_year`, `.and_day`).
//!
//! All relative values represents an offset to date and time and therefore can take on both positive and negative values,
//! and can take on any value within its datatypes limitations. On construction, a **Builder** will attempt to aggregate
//! values
//! up, so e.g. if *hours* are not in the range \[-23;23]\, the final instance will be updated to instead add or subtract
//! extra
//! *days*, with only the remainder as *hours*.
//! All offsets are set to zero as default.
//!
//! Absolute values represents an explicit *year*, *month*, *day* and so on. So if one e.g. always seeks a certain day in a
//! month, one would use the `::with_day()` or `.and_day()` method. All absolute values are **Options** and defaults to
//! `None`.
//!
//! `RelativeDelta` also holds a weekday value, which is an Option of a tuple with `(Weekday, nth)`. This allows one to e.g.
//! ask for the second tuesday one year from today,
//! with `Utc::now() + RelativeDelta::with_years(1).and_weekday(Some(Weekday::Tue, 2)).build()`.
//!
//! ### Examples
//!
//! Here are some examples of how to use the `RelativeDelta` library:
//!
//! #### Basic Construction
//!
//! Create a `RelativeDelta` representing 1 year:
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! let years1 = RelativeDelta::with_years(1).build();
//! ```
//!
//! Create a `RelativeDelta` representing 12 months (equivalent to 1 year):
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! let months12 = RelativeDelta::with_months(12).build();
//! ```
//!
//! Combining relative values:
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! let one_year_32_days = RelativeDelta::with_years(1).and_days(32).build();
//! ```
//!
//! If the same parameter is specified twice, only the latest is applied:
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! let months6 = RelativeDelta::with_months(12).and_months(6).build();
//! ```
//!
//! Combining absolute and relative values:
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! // Set year to 2020, add 1 year, set month to January, add 3 months, add 12 days
//! let complex = RelativeDelta::with_year(2020)
//! .and_years(1)
//! .and_month(Some(1))
//! .and_months(3)
//! .and_days(12)
//! .build();
//! ```
//!
//! #### Operations Between `RelativeDelta` Instances
//!
//! Addition and subtraction (note that absolute values are lost in these operations):
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! let delta1 = RelativeDelta::with_years( - 4).and_months(3).build();
//! let delta2 = RelativeDelta::with_years(1).and_months(42).build();
//!
//! // Addition
//! let sum = delta1 + delta2; // RelativeDelta::with_years(-3).and_months(45).build()
//!
//! // Subtraction
//! let diff = delta1 - delta2; // RelativeDelta::with_years(-5).and_months(-39).build()
//!
//! // Negation and addition
//! let neg_sum = - delta1 + delta2; // RelativeDelta::with_years(5).and_months(39).build()
//! ```
//!
//! Multiplication with a float:
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! let delta = RelativeDelta::with_years(4).and_months(6).build();
//! let half = delta * 0.5; // RelativeDelta::with_years(2).and_months(3).build()
//! ```
//!
//! #### Modifying an Existing `RelativeDelta`
//!
//! Use the `.builder()` method to create a Builder from an existing `RelativeDelta`:
//!
//! ```rust
//! # use relativedelta::RelativeDelta;
//! let original = RelativeDelta::with_years(1).build();
//! let modified = original.builder().and_months(6).and_days( - 5).build();
//! ```
//!
//! #### Using `RelativeDelta` with Datetime Libraries
//! #### Working with Weekdays
//!
//! Get the 3rd Tuesday of next month:
//!
//! ```rust
//! # use relativedelta::{RelativeDelta, Weekday};
//! let third_tuesday_next_month = RelativeDelta::with_months(1)
//! .and_weekday(Some((Weekday::Tue, 3)))
//! .build();
//! ```
/// `RelativeDelta` is a relative date time representation for smart date calculations.
/// Weekday is a module that provides functionality for working with weekdays in the context of `RelativeDelta`.
pub use crateWeekday;
/// `chrono_impl` is a module that provides implementations for `RelativeDelta` using the chrono crate.
/// `time_impl` is a module that provides implementations for `RelativeDelta` using the time crate.
pub use crateRelativeDelta;