Skip to content

Commit

Permalink
Add next_nth, previous_nth methods to Week, Months
Browse files Browse the repository at this point in the history
  • Loading branch information
xavetar committed Mar 25, 2024
1 parent 1f1dcbc commit 21696b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions api/src/types/planets/earth/calendar/constants/months.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@ impl Months {
pub fn previous(&self) -> Months {
return Months::from((self.index() - 1_u8) % MONTHS_IN_YEAR);
}

pub fn next_nth(&self, nth: u128) -> Months {
return Months::from(((self.index() as u128 + nth) % MONTHS_IN_YEAR as u128) as u8);
}

pub fn previous_nth(&self, nth: u128) -> Months {
return Months::from(((self.index() as u128 - nth) % MONTHS_IN_YEAR as u128) as u8);
}
}
8 changes: 8 additions & 0 deletions api/src/types/planets/earth/calendar/constants/week.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,12 @@ impl Week {
pub fn previous(&self) -> Week {
return Week::from((self.index() - 1_u8) % DAYS_IN_WEEK);
}

pub fn next_nth(&self, nth: u128) -> Week {
return Week::from(((self.index() as u128 + nth) % DAYS_IN_WEEK as u128) as u8);
}

pub fn previous_nth(&self, nth: u128) -> Week {
return Week::from(((self.index() as u128 - nth) % DAYS_IN_WEEK as u128) as u8);
}
}
2 changes: 1 addition & 1 deletion tools/date-cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn parse_args(timezone: &mut Zone, method: &mut fn(CalendarView, u64, u8, u8
} else {
panic!("[ERROR] Invalid sign in timezone: {char:?}", char = zone_str.chars().nth(0));
}

let zone_values: Vec<u8> = zone_str[1..]
.split(':')
.map(|x| x.parse::<u8>())
Expand Down

0 comments on commit 21696b0

Please sign in to comment.