OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """Date and time interfaces.""" | 2 """Date and time interfaces.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 import abc | 6 import abc |
7 import calendar | 7 import calendar |
8 | 8 |
9 from dfdatetime import decorators | 9 from dfdatetime import decorators |
10 from dfdatetime import definitions | 10 from dfdatetime import definitions |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 875 |
876 return int(normalized_timestamp), remainder | 876 return int(normalized_timestamp), remainder |
877 | 877 |
878 return int(normalized_timestamp), None | 878 return int(normalized_timestamp), None |
879 | 879 |
880 @abc.abstractmethod | 880 @abc.abstractmethod |
881 def CopyToDateTimeString(self): | 881 def CopyToDateTimeString(self): |
882 """Copies the date time value to a date and time string. | 882 """Copies the date time value to a date and time string. |
883 | 883 |
884 Returns: | 884 Returns: |
885 str: date and time value formatted as: "YYYY-MM-DD hh:mm:ss.######" | 885 str: date and time value formatted as: "YYYY-MM-DD hh:mm:ss.######" or |
| 886 None if the timestamp cannot be copied to a date and time string. |
886 """ | 887 """ |
887 | 888 |
| 889 def CopyToDateTimeStringISO8601(self): |
| 890 """Copies the date time value to an ISO 8601 date and time string. |
| 891 |
| 892 Returns: |
| 893 str: date and time value formatted as an ISO 8601 date and time string or |
| 894 None if the timestamp cannot be copied to a date and time string. |
| 895 """ |
| 896 date_time_string = self.CopyToDateTimeString() |
| 897 if date_time_string: |
| 898 date_time_string = date_time_string.replace(' ', 'T') |
| 899 date_time_string = '{0:s}Z'.format(date_time_string) |
| 900 return date_time_string |
| 901 |
888 def GetDate(self): | 902 def GetDate(self): |
889 """Retrieves the date represented by the date and time values. | 903 """Retrieves the date represented by the date and time values. |
890 | 904 |
891 Returns: | 905 Returns: |
892 tuple[int, int, int]: year, month, day of month or (None, None, None) | 906 tuple[int, int, int]: year, month, day of month or (None, None, None) |
893 if the date and time values do not represent a date. | 907 if the date and time values do not represent a date. |
894 """ | 908 """ |
895 normalized_timestamp = self._GetNormalizedTimestamp() | 909 normalized_timestamp = self._GetNormalizedTimestamp() |
896 if normalized_timestamp is None: | 910 if normalized_timestamp is None: |
897 return None, None, None | 911 return None, None, None |
(...skipping 28 matching lines...) Expand all Loading... |
926 Returns: | 940 Returns: |
927 tuple[int, int, int]: hours, minutes, seconds or (None, None, None) | 941 tuple[int, int, int]: hours, minutes, seconds or (None, None, None) |
928 if the date and time values do not represent a time of day. | 942 if the date and time values do not represent a time of day. |
929 """ | 943 """ |
930 normalized_timestamp = self._GetNormalizedTimestamp() | 944 normalized_timestamp = self._GetNormalizedTimestamp() |
931 if normalized_timestamp is None: | 945 if normalized_timestamp is None: |
932 return None, None, None | 946 return None, None, None |
933 | 947 |
934 _, hours, minutes, seconds = self._GetTimeValues(normalized_timestamp) | 948 _, hours, minutes, seconds = self._GetTimeValues(normalized_timestamp) |
935 return hours, minutes, seconds | 949 return hours, minutes, seconds |
OLD | NEW |