<s> from __future__ import absolute_import <EOL> from . . utils import from_iso8601 <EOL> import datetime <EOL> import six <EOL> class Time ( object ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return str ( self . to_json ( ) ) <EOL> def to_json ( self ) : <EOL> return self . v . isoformat ( ) <EOL> class Date ( Time ) : <EOL> """<STR_LIT>""" <EOL> def apply_with ( self , _ , v , ctx ) : <EOL> """<STR_LIT>""" <EOL> self . v = None <EOL> if isinstance ( v , float ) : <EOL> self . v = datetime . date . fromtimestamp ( v ) <EOL> elif isinstance ( v , datetime . date ) : <EOL> self . v = v <EOL> elif isinstance ( v , six . string_types ) : <EOL> self . v = from_iso8601 ( v ) . date ( ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' + str ( type ( v ) ) ) <EOL> class Datetime ( Time ) : <EOL> """<STR_LIT>""" <EOL> def apply_with ( self , _ , v , ctx ) : <EOL> """<STR_LIT>""" <EOL> self . v = None <EOL> if isinstance ( v , float ) : <EOL> self . v = datetime . datetime . utcfromtimestamp ( v ) <EOL> elif isinstance ( v , datetime . datetime ) : <EOL> self . v = v <EOL> elif isinstance ( v , six . string_types ) : <EOL> self . v = from_iso8601 ( v ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' + str ( type ( v ) ) ) </s>
