diff options
Diffstat (limited to 'pandora/models/__init__.py')
-rw-r--r-- | pandora/models/__init__.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/pandora/models/__init__.py b/pandora/models/__init__.py index 7a60889..bafb6ce 100644 --- a/pandora/models/__init__.py +++ b/pandora/models/__init__.py | |||
@@ -57,6 +57,20 @@ class SyntheticField(namedtuple("SyntheticField", ["field"])): | |||
57 | raise NotImplementedError | 57 | raise NotImplementedError |
58 | 58 | ||
59 | 59 | ||
60 | class DateField(SyntheticField): | ||
61 | """Date Field | ||
62 | |||
63 | Handles a JSON map that contains a time field which is the timestamp with | ||
64 | nanosecond precision. | ||
65 | """ | ||
66 | |||
67 | def formatter(self, api_client, data, value): | ||
68 | if not value: | ||
69 | return None | ||
70 | |||
71 | return datetime.utcfromtimestamp(value["time"] / 1000) | ||
72 | |||
73 | |||
60 | class ModelMetaClass(type): | 74 | class ModelMetaClass(type): |
61 | 75 | ||
62 | def __new__(cls, name, parents, dct): | 76 | def __new__(cls, name, parents, dct): |
@@ -84,10 +98,6 @@ class PandoraModel(with_metaclass(ModelMetaClass, object)): | |||
84 | consumers of these instances can ignore all of the details of this class. | 98 | consumers of these instances can ignore all of the details of this class. |
85 | """ | 99 | """ |
86 | 100 | ||
87 | @staticmethod | ||
88 | def json_to_date(api_client, data): | ||
89 | return datetime.utcfromtimestamp(data["time"] / 1000) | ||
90 | |||
91 | @classmethod | 101 | @classmethod |
92 | def from_json_list(cls, api_client, data): | 102 | def from_json_list(cls, api_client, data): |
93 | """Convert a list of JSON values to a list of models | 103 | """Convert a list of JSON values to a list of models |