Path: blob/main/crates/polars-plan/src/dsl/function_expr/datetime.rs
6940 views
use super::*;12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]3#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]4#[derive(Clone, PartialEq, Debug, Eq, Hash)]5pub enum TemporalFunction {6Millennium,7Century,8Year,9IsLeapYear,10IsoYear,11Quarter,12Month,13DaysInMonth,14Week,15WeekDay,16Day,17OrdinalDay,18Time,19Date,20Datetime,21#[cfg(feature = "dtype-duration")]22Duration(TimeUnit),23Hour,24Minute,25Second,26Millisecond,27Microsecond,28Nanosecond,29#[cfg(feature = "dtype-duration")]30TotalDays,31#[cfg(feature = "dtype-duration")]32TotalHours,33#[cfg(feature = "dtype-duration")]34TotalMinutes,35#[cfg(feature = "dtype-duration")]36TotalSeconds,37#[cfg(feature = "dtype-duration")]38TotalMilliseconds,39#[cfg(feature = "dtype-duration")]40TotalMicroseconds,41#[cfg(feature = "dtype-duration")]42TotalNanoseconds,43ToString(String),44CastTimeUnit(TimeUnit),45WithTimeUnit(TimeUnit),46#[cfg(feature = "timezones")]47ConvertTimeZone(TimeZone),48TimeStamp(TimeUnit),49Truncate,50#[cfg(feature = "offset_by")]51OffsetBy,52#[cfg(feature = "month_start")]53MonthStart,54#[cfg(feature = "month_end")]55MonthEnd,56#[cfg(feature = "timezones")]57BaseUtcOffset,58#[cfg(feature = "timezones")]59DSTOffset,60Round,61Replace,62#[cfg(feature = "timezones")]63ReplaceTimeZone(Option<TimeZone>, NonExistent),64Combine(TimeUnit),65DatetimeFunction {66time_unit: TimeUnit,67time_zone: Option<TimeZone>,68},69}7071impl Display for TemporalFunction {72fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {73use TemporalFunction::*;74let s = match self {75Millennium => "millennium",76Century => "century",77Year => "year",78IsLeapYear => "is_leap_year",79IsoYear => "iso_year",80Quarter => "quarter",81Month => "month",82DaysInMonth => "days_in_month",83Week => "week",84WeekDay => "weekday",85Day => "day",86OrdinalDay => "ordinal_day",87Time => "time",88Date => "date",89Datetime => "datetime",90#[cfg(feature = "dtype-duration")]91Duration(_) => "duration",92Hour => "hour",93Minute => "minute",94Second => "second",95Millisecond => "millisecond",96Microsecond => "microsecond",97Nanosecond => "nanosecond",98#[cfg(feature = "dtype-duration")]99TotalDays => "total_days",100#[cfg(feature = "dtype-duration")]101TotalHours => "total_hours",102#[cfg(feature = "dtype-duration")]103TotalMinutes => "total_minutes",104#[cfg(feature = "dtype-duration")]105TotalSeconds => "total_seconds",106#[cfg(feature = "dtype-duration")]107TotalMilliseconds => "total_milliseconds",108#[cfg(feature = "dtype-duration")]109TotalMicroseconds => "total_microseconds",110#[cfg(feature = "dtype-duration")]111TotalNanoseconds => "total_nanoseconds",112ToString(_) => "to_string",113#[cfg(feature = "timezones")]114ConvertTimeZone(_) => "convert_time_zone",115CastTimeUnit(_) => "cast_time_unit",116WithTimeUnit(_) => "with_time_unit",117TimeStamp(tu) => return write!(f, "dt.timestamp({tu})"),118Truncate => "truncate",119#[cfg(feature = "offset_by")]120OffsetBy => "offset_by",121#[cfg(feature = "month_start")]122MonthStart => "month_start",123#[cfg(feature = "month_end")]124MonthEnd => "month_end",125#[cfg(feature = "timezones")]126BaseUtcOffset => "base_utc_offset",127#[cfg(feature = "timezones")]128DSTOffset => "dst_offset",129Round => "round",130Replace => "replace",131#[cfg(feature = "timezones")]132ReplaceTimeZone(_, _) => "replace_time_zone",133DatetimeFunction { .. } => return write!(f, "dt.datetime"),134Combine(_) => "combine",135};136write!(f, "dt.{s}")137}138}139140141