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