summaryrefslogtreecommitdiff
path: root/src/month.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2022-03-16 14:52:31 -0400
committerBotahamec <botahamec@outlook.com>2022-03-16 14:52:31 -0400
commite0e0a18a4bc873583e973d771669e88a92b20d92 (patch)
treeba060d810c4621ec7e489afb19ad180a6b2ab755 /src/month.rs
parent5ca69f1830763b689bae9c4873a2912b3f1e23b1 (diff)
parent954cfd1385709d41ef0ece9c78b8dcee236f55e4 (diff)
Merge branch 'master' of https://github.com/botahamec/botic
Diffstat (limited to 'src/month.rs')
-rw-r--r--src/month.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/month.rs b/src/month.rs
index c5407f7..9582957 100644
--- a/src/month.rs
+++ b/src/month.rs
@@ -36,6 +36,7 @@ impl Month {
/// assert_eq!(Some(Month::January), Month::from_u8(1));
/// assert_eq!(None, Month::from_u8(0));
/// assert_eq!(None, Month::from_u8(13));
+ #[must_use]
pub const fn from_u8(num: u8) -> Option<Self> {
match num {
1 => Some(January),
@@ -66,6 +67,7 @@ impl Month {
/// assert_eq!(Some(Month::January), Month::from_abbreviation("Jan"));
/// assert_eq!(None, Month::from_abbreviation("Janu"));
/// ```
+ #[must_use]
pub fn from_abbreviation(abbreviation: &str) -> Option<Self> {
match abbreviation {
"Jan" => Some(January),
@@ -96,6 +98,7 @@ impl Month {
/// assert_eq!(Some(Month::January), Month::from_name("January"));
/// assert_eq!(None, Month::from_name("Janu"));
/// ```
+ #[must_use]
pub fn from_name(name: &str) -> Option<Self> {
match name {
"January" => Some(January),
@@ -123,6 +126,7 @@ impl Month {
///
/// assert_eq!(1, Month::January.number());
/// ```
+ #[must_use]
pub const fn number(self) -> u8 {
self as u8
}
@@ -136,6 +140,7 @@ impl Month {
///
/// assert_eq!("January", Month::January.name());
/// ```
+ #[must_use]
pub const fn name(self) -> &'static str {
match self {
January => "January",
@@ -162,6 +167,7 @@ impl Month {
///
/// assert_eq!("Jan", Month::January.abbreviation());
/// ```
+ #[must_use]
pub const fn abbreviation(self) -> &'static str {
match self {
January => "Jan",
@@ -182,6 +188,7 @@ impl Month {
// TODO docs
// TODO handle ordinals greater than 365
+ #[must_use]
pub const fn from_ordinal_common(ordinal: u16) -> Self {
if ordinal < 31 {
January
@@ -210,6 +217,7 @@ impl Month {
}
}
+ #[must_use]
pub const fn from_ordinal_leap(ordinal: u16) -> Self {
if ordinal < 31 {
January
@@ -238,6 +246,7 @@ impl Month {
}
}
+ #[must_use]
pub const fn from_ordinal(ordinal: u16, leap_year: bool) -> Self {
if leap_year {
Self::from_ordinal_leap(ordinal)
@@ -253,6 +262,7 @@ impl Month {
///
/// assert_eq!(Month::January.next(), Month::February);
/// ```
+ #[must_use]
pub const fn next(self) -> Self {
match self {
January => February,
@@ -277,6 +287,7 @@ impl Month {
///
/// assert_eq!(Month::January.previous(), Month::December);
/// ```
+ #[must_use]
pub const fn previous(self) -> Self {
match self {
January => December,
@@ -298,6 +309,7 @@ impl Month {
/// Returns the number of days up to the end of the month in a year.
/// This doesn't account for leap day
+ #[must_use]
pub const fn last_day_ordinal_common(self) -> u16 {
match self {
January => 31,
@@ -358,6 +370,7 @@ impl Month {
}
/// Returns the number of days up to the end of the month in a leap year.
+ #[must_use]
pub const fn last_day_ordinal_leap(self) -> u16 {
match self {
January => 31,
@@ -377,6 +390,7 @@ impl Month {
/// Returns the number of days up to the end of the month.
/// Whether or not it's a leap year must be indicated
+ #[must_use]
pub const fn last_day_ordinal(self, leap_year: bool) -> u16 {
if leap_year {
self.last_day_ordinal_leap()