Skip to content

Commit a26a135

Browse files
committed
Linting
1 parent 8b9222e commit a26a135

File tree

2 files changed

+50
-59
lines changed

2 files changed

+50
-59
lines changed

src/lib.rs

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,22 @@ impl Cron {
9696
/// ```
9797
/// use croner::Cron;
9898
/// use chrono::Local;
99-
/// fn main() {
100-
/// // Parse cron expression
101-
/// let cron: Cron = "0 * * * * *".parse().expect("Couldn't parse cron string");
102-
///
103-
/// // Compare to time now
104-
/// let time = Local::now();
105-
/// let matches_all = cron.is_time_matching(&time).unwrap();
106-
///
107-
/// // Output results
108-
/// println!("Time is: {}", time);
109-
/// println!(
110-
/// "Pattern \"{}\" does {} time {}",
111-
/// cron.pattern.to_string(),
112-
/// if matches_all { "match" } else { "not match" },
113-
/// time
114-
/// );
115-
/// }
99+
///
100+
/// // Parse cron expression
101+
/// let cron: Cron = "0 * * * * *".parse().expect("Couldn't parse cron string");
102+
///
103+
/// // Compare to time now
104+
/// let time = Local::now();
105+
/// let matches_all = cron.is_time_matching(&time).unwrap();
106+
///
107+
/// // Output results
108+
/// println!("Time is: {}", time);
109+
/// println!(
110+
/// "Pattern \"{}\" does {} time {}",
111+
/// cron.pattern.to_string(),
112+
/// if matches_all { "match" } else { "not match" },
113+
/// time
114+
/// );
116115
/// ```
117116
pub fn is_time_matching<Tz: TimeZone>(&self, time: &DateTime<Tz>) -> Result<bool, CronError> {
118117
Ok(self.pattern.second_match(time.second())?
@@ -160,20 +159,18 @@ impl Cron {
160159
/// use chrono::Local;
161160
/// use croner::Cron;
162161
///
163-
/// fn main() {
164-
/// // Parse cron expression
165-
/// let cron: Cron = "0 18 * * * 5".parse().expect("Couldn't parse cron string");
162+
/// // Parse cron expression
163+
/// let cron: Cron = "0 18 * * * 5".parse().expect("Couldn't parse cron string");
166164
///
167-
/// // Get next match
168-
/// let time = Local::now();
169-
/// let next = cron.find_next_occurrence(&time, false).unwrap();
165+
/// // Get next match
166+
/// let time = Local::now();
167+
/// let next = cron.find_next_occurrence(&time, false).unwrap();
170168
///
171-
/// println!(
172-
/// "Pattern \"{}\" will match next time at {}",
173-
/// cron.pattern.to_string(),
174-
/// next
175-
/// );
176-
/// }
169+
/// println!(
170+
/// "Pattern \"{}\" will match next time at {}",
171+
/// cron.pattern.to_string(),
172+
/// next
173+
/// );
177174
/// ```
178175
pub fn find_next_occurrence<Tz: TimeZone>(
179176
&self,
@@ -209,20 +206,18 @@ impl Cron {
209206
/// use chrono::Local;
210207
/// use croner::Cron;
211208
///
212-
/// fn main() {
213-
/// // Parse cron expression
214-
/// let cron: Cron = "* * * * * *".parse().expect("Couldn't parse cron string");
209+
/// // Parse cron expression
210+
/// let cron: Cron = "* * * * * *".parse().expect("Couldn't parse cron string");
215211
///
216-
/// // Compare to time now
217-
/// let time = Local::now();
212+
/// // Compare to time now
213+
/// let time = Local::now();
218214
///
219-
/// // Get next 5 matches using iter_from
220-
/// println!("Finding matches of pattern '{}' starting from {}:", cron.pattern.to_string(), time);
215+
/// // Get next 5 matches using iter_from
216+
/// println!("Finding matches of pattern '{}' starting from {}:", cron.pattern.to_string(), time);
221217
///
222-
/// for time in cron.clone().iter_from(time).take(5) {
223-
/// println!("{}", time);
224-
/// }
225-
/// }
218+
/// for time in cron.clone().iter_from(time).take(5) {
219+
/// println!("{}", time);
220+
/// }
226221
/// ```
227222
///
228223
/// # Parameters
@@ -253,20 +248,19 @@ impl Cron {
253248
/// use chrono::Local;
254249
/// use croner::Cron;
255250
///
256-
/// fn main() {
257-
/// // Parse cron expression
258-
/// let cron: Cron = "* * * * * *".parse().expect("Couldn't parse cron string");
251+
/// // Parse cron expression
252+
/// let cron: Cron = "* * * * * *".parse().expect("Couldn't parse cron string");
259253
///
260-
/// // Compare to time now
261-
/// let time = Local::now();
254+
/// // Compare to time now
255+
/// let time = Local::now();
262256
///
263-
/// // Get next 5 matches using iter_from
264-
/// println!("Finding matches of pattern '{}' starting from {}:", cron.pattern.to_string(), time);
257+
/// // Get next 5 matches using iter_from
258+
/// println!("Finding matches of pattern '{}' starting from {}:", cron.pattern.to_string(), time);
265259
///
266-
/// for time in cron.clone().iter_after(time).take(5) {
267-
/// println!("{}", time);
268-
/// }
269-
/// }
260+
/// for time in cron.clone().iter_after(time).take(5) {
261+
/// println!("{}", time);
262+
/// }
263+
///
270264
/// ```
271265
///
272266
/// # Parameters

src/pattern.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl CronPattern {
5151
}
5252

5353
// Replace any '?' with '*' in the cron pattern
54-
self.pattern = self.pattern.replace("?", "*");
54+
self.pattern = self.pattern.replace('?', "*");
5555

5656
// Handle @nicknames
5757
if self.pattern.contains('@') {
@@ -257,10 +257,9 @@ impl CronPattern {
257257
if self
258258
.days_of_week
259259
.is_bit_set(date.weekday().num_days_from_sunday() as u8, nth_bit)?
260+
&& CronPattern::is_nth_weekday_of_month(date, nth, date.weekday())
260261
{
261-
if CronPattern::is_nth_weekday_of_month(date, nth, date.weekday()) {
262-
dow_matches = true;
263-
}
262+
dow_matches = true;
264263
}
265264
}
266265

@@ -282,12 +281,10 @@ impl CronPattern {
282281
dow_matches = dow_matches || self.days_of_week.is_bit_set(day_of_week, ALL_BIT)?;
283282

284283
// The day matches if it's set in the days bitset or the days of the week bitset
285-
if day_matches && self.star_dow {
286-
Ok(true)
287-
} else if dow_matches && self.star_dom {
284+
if (day_matches && self.star_dow) || (dow_matches && self.star_dom) {
288285
Ok(true)
289286
} else if !self.star_dom && !self.star_dow {
290-
if self.dom_and_dow == false {
287+
if !self.dom_and_dow {
291288
Ok(day_matches || dow_matches)
292289
} else {
293290
Ok(day_matches && dow_matches)

0 commit comments

Comments
 (0)