<s> from delorean import Delorean <EOL> from pytz import all_timezones <EOL> class UtcDatetime ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , the_datetime , the_timezone ) : <EOL> """<STR_LIT>""" <EOL> the_timezone = self . _get_timezone_parameter ( the_timezone ) <EOL> self . _delorean = Delorean ( datetime = the_datetime , timezone = the_timezone ) . shift ( "<STR_LIT>" ) <EOL> self . _delorean . truncate ( '<STR_LIT>' ) <EOL> @ staticmethod <EOL> def get_all_timezones ( ) : <EOL> """<STR_LIT>""" <EOL> return all_timezones <EOL> @ staticmethod <EOL> def get_current_utc_datetime ( ) : <EOL> """<STR_LIT>""" <EOL> delorean = Delorean ( ) <EOL> return UtcDatetime ( delorean . datetime , "<STR_LIT>" ) <EOL> def datetime_in_timezone ( self , the_timezone ) : <EOL> """<STR_LIT>""" <EOL> the_timezone = self . _get_timezone_parameter ( the_timezone ) <EOL> tmp_delorean = Delorean ( datetime = self . _delorean . datetime ) <EOL> return tmp_delorean . shift ( the_timezone ) . datetime <EOL> def advance_in_time ( self , periodicity ) : <EOL> """<STR_LIT>""" <EOL> if periodicity . period == "<STR_LIT>" : <EOL> return UtcDatetime ( self . _delorean . next_year ( periodicity . frequency ) . datetime , "<STR_LIT>" ) <EOL> elif periodicity . period == "<STR_LIT>" : <EOL> return UtcDatetime ( self . _delorean . next_month ( periodicity . frequency ) . datetime , "<STR_LIT>" ) <EOL> elif periodicity . period == "<STR_LIT>" : <EOL> return UtcDatetime ( self . _delorean . next_day ( periodicity . frequency ) . datetime , "<STR_LIT>" ) <EOL> def back_in_time ( self , periodicity ) : <EOL> """<STR_LIT>""" <EOL> if periodicity . period == "<STR_LIT>" : <EOL> return UtcDatetime ( self . _delorean . last_year ( periodicity . frequency ) . datetime , "<STR_LIT>" ) <EOL> elif periodicity . period == "<STR_LIT>" : <EOL> return UtcDatetime ( self . _delorean . last_month ( periodicity . frequency ) . datetime , "<STR_LIT>" ) <EOL> elif periodicity . period == "<STR_LIT>" : <EOL> return UtcDatetime ( self . _delorean . last_day ( periodicity . frequency ) . datetime , "<STR_LIT>" ) <EOL> @ property <EOL> def to_iso8601 ( self ) : <EOL> return self . datetime_utc . strftime ( '<STR_LIT>' ) <EOL> @ property <EOL> def datetime_utc ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . datetime <EOL> @ property <EOL> def date_utc ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . date <EOL> @ staticmethod <EOL> def deserialize ( data ) : <EOL> """<STR_LIT>""" <EOL> if data is None : <EOL> return None <EOL> return UtcDatetime ( data , "<STR_LIT>" ) <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . datetime <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if self is other : <EOL> return True <EOL> return isinstance ( other , self . __class__ ) and self . _delorean == other . _delorean <EOL> def __ne__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return not self . __eq__ ( other ) <EOL> def __lt__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . datetime < other . _delorean . datetime <EOL> def __le__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . datetime <= other . _delorean . datetime <EOL> def __gt__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . datetime > other . _delorean . datetime <EOL> def __ge__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . datetime >= other . _delorean . datetime <EOL> def __sub__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . _delorean . datetime - other . _delorean . datetime <EOL> def _get_timezone_parameter ( self , the_timezone ) : <EOL> """<STR_LIT>""" <EOL> if the_timezone == "<STR_LIT>" : <EOL> return "<STR_LIT>" <EOL> if the_timezone not in self . get_all_timezones ( ) : <EOL> raise ValueError ( "<STR_LIT>" % the_timezone ) <EOL> return the_timezone <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _delorean . naive ( ) , self . _delorean . timezone ( ) ) </s>
