Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Avoid repetitions in can_* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
VasanthakumarV committed Sep 23, 2021
1 parent b758df9 commit f2df942
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions src/compute/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,18 @@ where
/// assert_eq!(can_year(&data_type), false);
/// ```
pub fn can_year(data_type: &DataType) -> bool {
matches!(
data_type,
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, _)
)
can_date(data_type)
}

pub fn can_month(data_type: &DataType) -> bool {
matches!(
data_type,
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, _)
)
can_date(data_type)
}

pub fn can_day(data_type: &DataType) -> bool {
can_date(data_type)
}

fn can_date(data_type: &DataType) -> bool {
matches!(
data_type,
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, _)
Expand All @@ -396,32 +394,18 @@ pub fn can_day(data_type: &DataType) -> bool {
/// assert_eq!(can_hour(&data_type), false);
/// ```
pub fn can_hour(data_type: &DataType) -> bool {
matches!(
data_type,
DataType::Time32(TimeUnit::Second)
| DataType::Time32(TimeUnit::Millisecond)
| DataType::Time64(TimeUnit::Microsecond)
| DataType::Time64(TimeUnit::Nanosecond)
| DataType::Date32
| DataType::Date64
| DataType::Timestamp(_, _)
)
can_time(data_type)
}

pub fn can_minute(data_type: &DataType) -> bool {
matches!(
data_type,
DataType::Time32(TimeUnit::Second)
| DataType::Time32(TimeUnit::Millisecond)
| DataType::Time64(TimeUnit::Microsecond)
| DataType::Time64(TimeUnit::Nanosecond)
| DataType::Date32
| DataType::Date64
| DataType::Timestamp(_, _)
)
can_time(data_type)
}

pub fn can_second(data_type: &DataType) -> bool {
can_time(data_type)
}

fn can_time(data_type: &DataType) -> bool {
matches!(
data_type,
DataType::Time32(TimeUnit::Second)
Expand Down

0 comments on commit f2df942

Please sign in to comment.