Conditions | 3 |
Total Lines | 15 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
27 | def get(self, object): |
||
28 | """Get the current date |
||
29 | |||
30 | :param object: the instance of the field |
||
31 | :returns: datetime or None |
||
32 | """ |
||
33 | value = super(DatetimeField, self).get(object) |
||
34 | if not isinstance(value, datetime): |
||
35 | return None |
||
36 | # append current timezone if timezone naive |
||
37 | if value.tzinfo is None: |
||
38 | tz = current_timezone() |
||
39 | tzinfo = pytz.timezone(tz) |
||
40 | value = tzinfo.localize(value) |
||
41 | return value |
||
42 | |||
47 |