Concrete date type. Constructors: __new__() fromtimestamp() today() fromordinal() strptime() Operators: __repr__, __str__ __eq__, __le__, __lt__, __ge__, __gt__, __hash__ __add__, __radd__, __sub__ (add/radd only with timedelta arg) Methods: time
| 948 | timedelta.resolution = timedelta(microseconds=1) |
| 949 | |
| 950 | class date: |
| 951 | """Concrete date type. |
| 952 | |
| 953 | Constructors: |
| 954 | |
| 955 | __new__() |
| 956 | fromtimestamp() |
| 957 | today() |
| 958 | fromordinal() |
| 959 | strptime() |
| 960 | |
| 961 | Operators: |
| 962 | |
| 963 | __repr__, __str__ |
| 964 | __eq__, __le__, __lt__, __ge__, __gt__, __hash__ |
| 965 | __add__, __radd__, __sub__ (add/radd only with timedelta arg) |
| 966 | |
| 967 | Methods: |
| 968 | |
| 969 | timetuple() |
| 970 | toordinal() |
| 971 | weekday() |
| 972 | isoweekday(), isocalendar(), isoformat() |
| 973 | ctime() |
| 974 | strftime() |
| 975 | |
| 976 | Properties (readonly): |
| 977 | year, month, day |
| 978 | """ |
| 979 | __slots__ = '_year', '_month', '_day', '_hashcode' |
| 980 | |
| 981 | def __new__(cls, year, month=None, day=None): |
| 982 | """Constructor. |
| 983 | |
| 984 | Arguments: |
| 985 | |
| 986 | year, month, day (required, base 1) |
| 987 | """ |
| 988 | if (month is None and |
| 989 | isinstance(year, (bytes, str)) and len(year) == 4 and |
| 990 | 1 <= ord(year[2:3]) <= 12): |
| 991 | # Pickle support |
| 992 | if isinstance(year, str): |
| 993 | try: |
| 994 | year = year.encode('latin1') |
| 995 | except UnicodeEncodeError: |
| 996 | # More informative error message. |
| 997 | raise ValueError( |
| 998 | "Failed to encode latin1 string when unpickling " |
| 999 | "a date object. " |
| 1000 | "pickle.load(data, encoding='latin1') is assumed.") |
| 1001 | self = object.__new__(cls) |
| 1002 | self.__setstate(year) |
| 1003 | self._hashcode = -1 |
| 1004 | return self |
| 1005 | year, month, day = _check_date_fields(year, month, day) |
| 1006 | self = object.__new__(cls) |
| 1007 | self._year = year |
no outgoing calls