Source code for

import datetime
import functools

from .impl import hapi

[docs] @functools.total_ordering class Date: """ A Hyper DATE value - year, month, and day. This class is similar to ````. The difference is that it supports a greater range of dates: while Python years range from 1 to 9999, Hyper supports years from ``-4712`` (4713 BC) to ``294276``. :param year: the year. :param month: the month, from 1 to 12. :param day: the day, from 1 to the number of days in the month. .. testsetup:: Date.__init__ from tableauhyperapi import * .. doctest:: Date.__init__ >>> print(Date(2019, 6, 13)) 2019-06-13 """ MINYEAR = -4712 """ The earliest representable year. """ MAXYEAR = 294276 """ The latest representable year. """ __slots__ = ('year', 'month', 'day') def __init__(self, year, month, day): self.year = year """ The year.""" self.month = month """ The month.""" = day """ The day."""
[docs] @staticmethod def today() -> 'Date': """ Returns the current local date. """ return Date.from_date(
[docs] @staticmethod def from_date(date: -> 'Date': """ Converts Python ```` to :any:`Date`. """ return Date(date.year, date.month,
[docs] def to_date(self) -> """ Converts to Python ````. Raises an exception if the date is not representable by the Python class. """ return, self.month,
@staticmethod def _from_hyper(v): comps = hapi.hyper_decode_date(v) return Date(comps.year, comps.month, def __repr__(self): return f'Date({self.year}, {self.month}, {})' def __str__(self): return f'{self.year}-{self.month:02}-{}' def __eq__(self, other): if not isinstance(other, Date): return NotImplemented return self.year == other.year and self.month == other.month and == def __lt__(self, other): if not isinstance(other, Date): return NotImplemented return (self.year, self.month, < (other.year, other.month, def __hash__(self): return hash((self.year, self.month,