Skip to content

Commit

Permalink
Fix Oracle date filters
Browse files Browse the repository at this point in the history
  • Loading branch information
t3eHawk committed Dec 20, 2022
1 parent 905121a commit 323c123
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pydin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ def target_date(self):
def date_from(self):
"""The beggining of the target date of this model."""
if hasattr(self, 'date_field'):
return self.target_date.start
return self.converter(self.target_date.start)

@property
def date_to(self):
"""The end of the target date of this model."""
if hasattr(self, 'date_field'):
return self.target_date.end
return self.converter(self.target_date.end)

@property
def value_field(self):
Expand Down Expand Up @@ -210,6 +210,13 @@ def format_custom_query(self, value):
else:
return value

def converter(self, value):
"""Convert the given value into the appropriate model format."""
if value and hasattr(self, '_convert'):
return self._convert(value)
else:
return value

def explain(self, parameter_name=None):
"""Get model or chosen parameter description."""
if not parameter_name:
Expand Down Expand Up @@ -1065,6 +1072,17 @@ def endlog(self, output_rows=None, output_text=None,
error_text=error_text)
pass

def _convert(self, value):
if isinstance(value, dt.datetime):
if self.db.vendor == 'oracle':
string = f'{value:%Y-%m-%d %H:%M:%S}'
fmt = 'yyyy-mm-dd hh24:mi:ss'
return sa.func.to_date(string, fmt)
else:
return value
else:
return value

def _format(self, text):
text = text.format(task=self.task)
return text
Expand Down

0 comments on commit 323c123

Please sign in to comment.