aboutsummaryrefslogtreecommitdiff
path: root/ql/types/date.py
diff options
context:
space:
mode:
authorBicker <bickerkards@tuta.io>2019-05-22 17:45:37 +0200
committerBicker <bickerkards@tuta.io>2019-05-22 17:45:37 +0200
commit25314fd2aed81aa5281bc3d93dbcc7919368ebe1 (patch)
tree1995521ee652e419926de5fced0f2e3b655e70fb /ql/types/date.py
Initial commitHEADmaster
Diffstat (limited to 'ql/types/date.py')
-rw-r--r--ql/types/date.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/ql/types/date.py b/ql/types/date.py
new file mode 100644
index 0000000..fca5366
--- /dev/null
+++ b/ql/types/date.py
@@ -0,0 +1,67 @@
+from datetime import date
+
+from gui.widgets.calendar import CalendarWidget
+from ql.ast.nodes.expressions.literals.date_literal import DateNode
+from ql.types.boolean import QLBoolean
+from ql.types.type import QLType
+
+
+class QLDate(QLType):
+ def __init__(self, day=1, month=1, year=1):
+ super(QLDate, self).__init__()
+ self.__day = int(day)
+ self.__month = int(month)
+ self.__year = int(year)
+ date(self.year, self.month, self.day)
+
+ @property
+ def day(self):
+ return self.__day
+
+ @property
+ def month(self):
+ return self.__month
+
+ @property
+ def year(self):
+ return self.__year
+
+ def __repr__(self):
+ return '{}-{}-{}'.format(self.day, self.month, self.year)
+
+ def __str__(self):
+ return '{}-{}-{}'.format(self.day, self.month, self.year)
+
+ def __eq__(self, other):
+ if isinstance(other, QLDate):
+ return QLBoolean(self.day == other.day and self.month == other.month and self.year == other.year)
+
+ return QLBoolean(False)
+
+ def __ne__(self, other):
+ return QLBoolean(not self == other)
+
+ def __lt__(self, other):
+ return QLBoolean(self.year < other.year or (self.month < other.month and self.year == other.year) or
+ (self.day < other.day and self.month == other.month and self.year == other.year))
+
+ def __gt__(self, other):
+ return QLBoolean(self.year > other.year or (self.month > other.month and self.year == other.year) or
+ (self.day > other.day and self.month == other.month and self.year == other.year))
+
+ def __le__(self, other):
+ return QLBoolean(self < other or self == other)
+
+ def __ge__(self, other):
+ return QLBoolean(self > other or self == other)
+
+ def get_json_value(self):
+ return {'day': self.day, 'month': self.month, 'year': self.year}
+
+ @staticmethod
+ def get_literal_node(value):
+ return DateNode(None, QLDate, value)
+
+ @staticmethod
+ def pyqt5_default_widget():
+ return CalendarWidget()