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
use crate::Dt;
#[cfg(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(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
///
/// - Jiff only supports years in the range `-9999..=9999`. Years outside
/// this range will return a [`DtErr`].
/// - If Jiff cannot find the timezone name or if applying the timezone would cause
/// the [`jiff::Zoned`] to be outside the `-9999..=9999` year range then a
/// [`DtErr`] with [`DtErrKind::InvalidTimezoneOffset`] is returned.
#[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.
/// - Will error if the year is outside of `-9999..=9999`.
///
/// ## Errors
///
/// - Jiff only supports years in the range `-9999..=9999`. Years outside
/// this range will return a [`DtErr`].
/// - If Jiff cannot find the timezone name or if applying the timezone would cause
/// the [`jiff::Zoned`] to be outside the `-9999..=9999` year range then a
/// [`DtErr`] with [`DtErrKind::InvalidTimezoneOffset`] is returned.
#[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.
/// - Will error if the year is outside of `-9999..=9999`.
///
/// ## Errors
///
/// - Jiff only supports years in the range `-9999..=9999`. Years outside
/// this range will return a [`DtErr`].
/// - If Jiff cannot find the timezone name or if applying the timezone would cause
/// the [`jiff::Zoned`] to be outside the `-9999..=9999` year range then a
/// [`DtErr`] with [`DtErrKind::InvalidTimezoneOffset`] is returned.
#[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.
/// - Will error if the year is outside of `-9999..=9999`.
///
/// ## Errors
///
/// - Jiff only supports years in the range `-9999..=9999`. Years outside
/// this range will return a [`DtErr`].
/// - If Jiff cannot find the timezone name or if applying the timezone would cause
/// the [`jiff::Zoned`] to be outside the `-9999..=9999` year range then a
/// [`DtErr`] with [`DtErrKind::InvalidTimezoneOffset`] is returned.
#[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.
/// - Will error if the year is outside of `-9999..=9999`.
///
/// ## Errors
///
/// - Jiff only supports years in the range `-9999..=9999`. Years outside
/// this range will return a [`DtErr`].
/// - If Jiff cannot find the timezone name or if applying the timezone would cause
/// the [`jiff::Zoned`] to be outside the `-9999..=9999` year range then a
/// [`DtErr`] with [`DtErrKind::InvalidTimezoneOffset`] is returned.
#[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.
/// - Will error if the year is outside of `-9999..=9999`.
///
/// ## Errors
///
/// - Jiff only supports years in the range `-9999..=9999`. Years outside
/// this range will return a [`DtErr`].
/// - If Jiff cannot find the timezone name or if applying the timezone would cause
/// the [`jiff::Zoned`] to be outside the `-9999..=9999` year range then a
/// [`DtErr`] with [`DtErrKind::InvalidTimezoneOffset`] is returned.
#[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.
/// - Will error if the year is outside of `-9999..=9999`.
///
/// ## Errors
///
/// - Jiff only supports years in the range `-9999..=9999`. Years outside
/// this range will return a [`DtErr`].
/// - If Jiff cannot find the timezone name or if applying the timezone would cause
/// the [`jiff::Zoned`] to be outside the `-9999..=9999` year range then a
/// [`DtErr`] with [`DtErrKind::InvalidTimezoneOffset`] is returned.
#[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())
}
}