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
8384 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
fractional: bool,
33
},
34
#[cfg(feature = "dtype-duration")]
35
TotalHours {
36
fractional: bool,
37
},
38
#[cfg(feature = "dtype-duration")]
39
TotalMinutes {
40
fractional: bool,
41
},
42
#[cfg(feature = "dtype-duration")]
43
TotalSeconds {
44
fractional: bool,
45
},
46
#[cfg(feature = "dtype-duration")]
47
TotalMilliseconds {
48
fractional: bool,
49
},
50
#[cfg(feature = "dtype-duration")]
51
TotalMicroseconds {
52
fractional: bool,
53
},
54
#[cfg(feature = "dtype-duration")]
55
TotalNanoseconds {
56
fractional: bool,
57
},
58
ToString(String),
59
CastTimeUnit(TimeUnit),
60
WithTimeUnit(TimeUnit),
61
#[cfg(feature = "timezones")]
62
ConvertTimeZone(TimeZone),
63
TimeStamp(TimeUnit),
64
Truncate,
65
#[cfg(feature = "offset_by")]
66
OffsetBy,
67
#[cfg(feature = "month_start")]
68
MonthStart,
69
#[cfg(feature = "month_end")]
70
MonthEnd,
71
#[cfg(feature = "timezones")]
72
BaseUtcOffset,
73
#[cfg(feature = "timezones")]
74
DSTOffset,
75
Round,
76
Replace,
77
#[cfg(feature = "timezones")]
78
ReplaceTimeZone(Option<TimeZone>, NonExistent),
79
Combine(TimeUnit),
80
DatetimeFunction {
81
time_unit: TimeUnit,
82
time_zone: Option<TimeZone>,
83
},
84
}
85
86
impl Display for TemporalFunction {
87
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
88
use TemporalFunction::*;
89
let s = match self {
90
Millennium => "millennium",
91
Century => "century",
92
Year => "year",
93
IsLeapYear => "is_leap_year",
94
IsoYear => "iso_year",
95
Quarter => "quarter",
96
Month => "month",
97
DaysInMonth => "days_in_month",
98
Week => "week",
99
WeekDay => "weekday",
100
Day => "day",
101
OrdinalDay => "ordinal_day",
102
Time => "time",
103
Date => "date",
104
Datetime => "datetime",
105
#[cfg(feature = "dtype-duration")]
106
Duration(_) => "duration",
107
Hour => "hour",
108
Minute => "minute",
109
Second => "second",
110
Millisecond => "millisecond",
111
Microsecond => "microsecond",
112
Nanosecond => "nanosecond",
113
#[cfg(feature = "dtype-duration")]
114
TotalDays { .. } => "total_days",
115
#[cfg(feature = "dtype-duration")]
116
TotalHours { .. } => "total_hours",
117
#[cfg(feature = "dtype-duration")]
118
TotalMinutes { .. } => "total_minutes",
119
#[cfg(feature = "dtype-duration")]
120
TotalSeconds { .. } => "total_seconds",
121
#[cfg(feature = "dtype-duration")]
122
TotalMilliseconds { .. } => "total_milliseconds",
123
#[cfg(feature = "dtype-duration")]
124
TotalMicroseconds { .. } => "total_microseconds",
125
#[cfg(feature = "dtype-duration")]
126
TotalNanoseconds { .. } => "total_nanoseconds",
127
ToString(_) => "to_string",
128
#[cfg(feature = "timezones")]
129
ConvertTimeZone(_) => "convert_time_zone",
130
CastTimeUnit(_) => "cast_time_unit",
131
WithTimeUnit(_) => "with_time_unit",
132
TimeStamp(tu) => return write!(f, "dt.timestamp({tu})"),
133
Truncate => "truncate",
134
#[cfg(feature = "offset_by")]
135
OffsetBy => "offset_by",
136
#[cfg(feature = "month_start")]
137
MonthStart => "month_start",
138
#[cfg(feature = "month_end")]
139
MonthEnd => "month_end",
140
#[cfg(feature = "timezones")]
141
BaseUtcOffset => "base_utc_offset",
142
#[cfg(feature = "timezones")]
143
DSTOffset => "dst_offset",
144
Round => "round",
145
Replace => "replace",
146
#[cfg(feature = "timezones")]
147
ReplaceTimeZone(_, _) => "replace_time_zone",
148
DatetimeFunction { .. } => return write!(f, "dt.datetime"),
149
Combine(_) => "combine",
150
};
151
write!(f, "dt.{s}")
152
}
153
}
154
155