gitql_ast/types/
datetime.rs1use std::any::Any;
2
3use crate::expression::Expr;
4use crate::expression::StringExpr;
5use crate::format_checker::is_valid_datetime_format;
6use crate::types::array::ArrayType;
7use crate::types::date::DateType;
8
9use super::base::DataType;
10
11#[derive(Clone)]
12pub struct DateTimeType;
13
14impl DataType for DateTimeType {
15 fn literal(&self) -> String {
16 "DateTime".to_string()
17 }
18
19 fn equals(&self, other: &Box<dyn DataType>) -> bool {
20 other.is_any() || other.is_date_time() || other.is_variant_with(|t| t.is_date_time())
21 }
22
23 fn as_any(&self) -> &dyn Any {
24 self
25 }
26
27 fn can_perform_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
28 vec![Box::new(DateTimeType)]
29 }
30
31 fn can_perform_group_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
32 vec![Box::new(ArrayType::new(Box::new(DateTimeType)))]
33 }
34
35 fn can_perform_bang_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
36 vec![Box::new(DateTimeType)]
37 }
38
39 fn can_perform_group_bang_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
40 vec![Box::new(ArrayType::new(Box::new(DateTimeType)))]
41 }
42
43 fn can_perform_gt_op_with(&self) -> Vec<Box<dyn DataType>> {
44 vec![Box::new(DateTimeType)]
45 }
46
47 fn can_perform_group_gt_op_with(&self) -> Vec<Box<dyn DataType>> {
48 vec![Box::new(ArrayType::new(Box::new(DateTimeType)))]
49 }
50
51 fn can_perform_gte_op_with(&self) -> Vec<Box<dyn DataType>> {
52 vec![Box::new(DateTimeType)]
53 }
54
55 fn can_perform_group_gte_op_with(&self) -> Vec<Box<dyn DataType>> {
56 vec![Box::new(ArrayType::new(Box::new(DateTimeType)))]
57 }
58
59 fn can_perform_lt_op_with(&self) -> Vec<Box<dyn DataType>> {
60 vec![Box::new(DateTimeType)]
61 }
62
63 fn can_perform_group_lt_op_with(&self) -> Vec<Box<dyn DataType>> {
64 vec![Box::new(ArrayType::new(Box::new(DateTimeType)))]
65 }
66
67 fn can_perform_lte_op_with(&self) -> Vec<Box<dyn DataType>> {
68 vec![Box::new(DateTimeType)]
69 }
70
71 fn can_perform_group_lte_op_with(&self) -> Vec<Box<dyn DataType>> {
72 vec![Box::new(ArrayType::new(Box::new(DateTimeType)))]
73 }
74
75 fn has_implicit_cast_from(&self, expr: &Box<dyn Expr>) -> bool {
76 if let Some(string_expr) = expr.as_any().downcast_ref::<StringExpr>() {
77 return is_valid_datetime_format(&string_expr.value);
78 }
79 false
80 }
81
82 fn can_perform_explicit_cast_op_to(&self) -> Vec<Box<dyn DataType>> {
83 vec![Box::new(DateType)]
84 }
85}