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
use crate::Dt;
#[cfg(any(feature = "jiff-tz-bundle", feature = "jiff-tz"))]
use crate::DtErr;
impl Dt {
/// Adds (or subtracts) calendar years, preserving month and day-of-month.
/// - Uses standard last-day-of-month clamping.
/// - Negative values subtract.
#[inline(always)]
pub const fn add_yr(&self, n: i64) -> Self {
self.to_ymd().add_yr(n).to_dt()
}
/// Adds (or subtracts) calendar months.
/// Negative values subtract.
#[inline(always)]
pub const fn add_mo(&self, n: i64) -> Self {
self.to_ymd().add_mo(n).to_dt()
}
/// Adds (or subtracts) calendar weeks.
/// Negative values subtract.
#[inline(always)]
pub const fn add_wk(&self, n: i64) -> Self {
self.to_ymd().add_wk(n).to_dt()
}
/// Adds (or subtracts) calendar days.
/// Negative values subtract.
#[inline(always)]
pub const fn add_days(&self, n: i64) -> Self {
self.to_ymd().add_days(n).to_dt()
}
}
#[cfg(any(feature = "jiff-tz-bundle", feature = "jiff-tz"))]
impl Dt {
/// Adds the given number of years in the specified IANA timezone,
/// respecting timezone rules (including DST) and calendar arithmetic.
///
/// ## Notes
///
/// - Requires the `jiff-tz` feature.
/// - Assumes this [`Dt`] is counting seconds from the library's
/// `2000-01-01 12:00:00` epoch.
///
/// ## Errors
///
/// - [`DtErrKind::YearOutOfRange`] if the year of the date is outside the
/// `-9999..=9999` range (checked before involving Jiff).
/// - Specific errors for invalid time components when preparing values for Jiff:
/// [`DtErrKind::InvalidHour`], [`DtErrKind::InvalidMinute`],
/// [`DtErrKind::InvalidSecond`], [`DtErrKind::InvalidMonth`], or [`DtErrKind::InvalidDay`].
/// - [`DtErrKind::InvalidTimeZone`] if Jiff cannot find/resolve the IANA timezone name.
/// - [`DtErrKind::OutOfRange`] if the result of the calendar arithmetic operation
/// would be outside the range supported by Jiff (the checked_add fails).
#[inline(always)]
pub fn add_yr_tz(&self, n: i64, tz: &str) -> Result<Self, DtErr> {
Ok(self.to_ymd().add_yr_tz(n, tz)?.to_dt())
}
/// Adds the given number of months in the specified IANA timezone,
/// respecting timezone rules and calendar month-end clamping.
///
/// ## Notes
///
/// - Requires the `jiff-tz` feature.
/// - Assumes this [`Dt`] is counting seconds from the library's
/// `2000-01-01 12:00:00` epoch.
///
/// ## Errors
///
/// - [`DtErrKind::YearOutOfRange`] if the year of the date is outside the
/// `-9999..=9999` range (checked before involving Jiff).
/// - Specific errors for invalid time components when preparing values for Jiff:
/// [`DtErrKind::InvalidHour`], [`DtErrKind::InvalidMinute`],
/// [`DtErrKind::InvalidSecond`], [`DtErrKind::InvalidMonth`], or [`DtErrKind::InvalidDay`].
/// - [`DtErrKind::InvalidTimeZone`] if Jiff cannot find/resolve the IANA timezone name.
/// - [`DtErrKind::OutOfRange`] if the result of the calendar arithmetic operation
/// would be outside the range supported by Jiff (the checked_add fails).
#[inline(always)]
pub fn add_mo_tz(&self, n: i64, tz: &str) -> Result<Self, DtErr> {
Ok(self.to_ymd().add_mo_tz(n, tz)?.to_dt())
}
/// Adds the given number of weeks in the specified IANA timezone,
/// respecting timezone rules (including DST).
///
/// ## Notes
///
/// - Requires the `jiff-tz` feature.
/// - Assumes this [`Dt`] is counting seconds from the library's
/// `2000-01-01 12:00:00` epoch.
///
/// ## Errors
///
/// - [`DtErrKind::YearOutOfRange`] if the year of the date is outside the
/// `-9999..=9999` range (checked before involving Jiff).
/// - Specific errors for invalid time components when preparing values for Jiff:
/// [`DtErrKind::InvalidHour`], [`DtErrKind::InvalidMinute`],
/// [`DtErrKind::InvalidSecond`], [`DtErrKind::InvalidMonth`], or [`DtErrKind::InvalidDay`].
/// - [`DtErrKind::InvalidTimeZone`] if Jiff cannot find/resolve the IANA timezone name.
/// - [`DtErrKind::OutOfRange`] if the result of the calendar arithmetic operation
/// would be outside the range supported by Jiff (the checked_add fails).
#[inline(always)]
pub fn add_wk_tz(&self, n: i64, tz: &str) -> Result<Self, DtErr> {
Ok(self.to_ymd().add_wk_tz(n, tz)?.to_dt())
}
/// Adds the given number of calendar days in the specified IANA timezone,
/// respecting timezone rules (including DST).
///
/// ## Notes
///
/// - Requires the `jiff-tz` feature.
/// - Assumes this [`Dt`] is counting seconds from the library's
/// `2000-01-01 12:00:00` epoch.
///
/// ## Errors
///
/// - [`DtErrKind::YearOutOfRange`] if the year of the date is outside the
/// `-9999..=9999` range (checked before involving Jiff).
/// - Specific errors for invalid time components when preparing values for Jiff:
/// [`DtErrKind::InvalidHour`], [`DtErrKind::InvalidMinute`],
/// [`DtErrKind::InvalidSecond`], [`DtErrKind::InvalidMonth`], or [`DtErrKind::InvalidDay`].
/// - [`DtErrKind::InvalidTimeZone`] if Jiff cannot find/resolve the IANA timezone name.
/// - [`DtErrKind::OutOfRange`] if the result of the calendar arithmetic operation
/// would be outside the range supported by Jiff (the checked_add fails).
#[inline(always)]
pub fn add_days_tz(&self, n: i64, tz: &str) -> Result<Self, DtErr> {
Ok(self.to_ymd().add_days_tz(n, tz)?.to_dt())
}
/// Adds the given number of hours in the specified IANA timezone,
/// respecting timezone rules (including DST).
///
/// ## Notes
///
/// - Requires the `jiff-tz` feature.
/// - Assumes this [`Dt`] is counting seconds from the library's
/// `2000-01-01 12:00:00` epoch.
///
/// ## Errors
///
/// - [`DtErrKind::YearOutOfRange`] if the year of the date is outside the
/// `-9999..=9999` range (checked before involving Jiff).
/// - Specific errors for invalid time components when preparing values for Jiff:
/// [`DtErrKind::InvalidHour`], [`DtErrKind::InvalidMinute`],
/// [`DtErrKind::InvalidSecond`], [`DtErrKind::InvalidMonth`], or [`DtErrKind::InvalidDay`].
/// - [`DtErrKind::InvalidTimeZone`] if Jiff cannot find/resolve the IANA timezone name.
/// - [`DtErrKind::OutOfRange`] if the result of the calendar arithmetic operation
/// would be outside the range supported by Jiff (the checked_add fails).
#[inline(always)]
pub fn add_hr_tz(&self, n: i64, tz: &str) -> Result<Self, DtErr> {
Ok(self.to_ymd().add_hr_tz(n, tz)?.to_dt())
}
/// Adds the given number of minutes in the specified IANA timezone,
/// respecting timezone rules (including DST).
///
/// ## Notes
///
/// - Requires the `jiff-tz` feature.
/// - Assumes this [`Dt`] is counting seconds from the library's
/// `2000-01-01 12:00:00` epoch.
///
/// ## Errors
///
/// - [`DtErrKind::YearOutOfRange`] if the year of the date is outside the
/// `-9999..=9999` range (checked before involving Jiff).
/// - Specific errors for invalid time components when preparing values for Jiff:
/// [`DtErrKind::InvalidHour`], [`DtErrKind::InvalidMinute`],
/// [`DtErrKind::InvalidSecond`], [`DtErrKind::InvalidMonth`], or [`DtErrKind::InvalidDay`].
/// - [`DtErrKind::InvalidTimeZone`] if Jiff cannot find/resolve the IANA timezone name.
/// - [`DtErrKind::OutOfRange`] if the result of the calendar arithmetic operation
/// would be outside the range supported by Jiff (the checked_add fails).
#[inline(always)]
pub fn add_min_tz(&self, n: i64, tz: &str) -> Result<Self, DtErr> {
Ok(self.to_ymd().add_min_tz(n, tz)?.to_dt())
}
/// Adds the given number of seconds in the specified IANA timezone,
/// respecting timezone rules (including DST).
///
/// ## Notes
///
/// - Requires the `jiff-tz` feature.
/// - Assumes this [`Dt`] is counting seconds from the library's
/// `2000-01-01 12:00:00` epoch.
///
/// ## Errors
///
/// - [`DtErrKind::YearOutOfRange`] if the year of the date is outside the
/// `-9999..=9999` range (checked before involving Jiff).
/// - Specific errors for invalid time components when preparing values for Jiff:
/// [`DtErrKind::InvalidHour`], [`DtErrKind::InvalidMinute`],
/// [`DtErrKind::InvalidSecond`], [`DtErrKind::InvalidMonth`], or [`DtErrKind::InvalidDay`].
/// - [`DtErrKind::InvalidTimeZone`] if Jiff cannot find/resolve the IANA timezone name.
/// - [`DtErrKind::OutOfRange`] if the result of the calendar arithmetic operation
/// would be outside the range supported by Jiff (the checked_add fails).
#[inline(always)]
pub fn add_sec_tz(&self, n: i64, tz: &str) -> Result<Self, DtErr> {
Ok(self.to_ymd().add_sec_tz(n, tz)?.to_dt())
}
}