from datetime import datetime
import pytz


def getTimeStamp(tweet, timezone='US/Eastern'):
    """If properly included, get the time stamp of the tweet
    from the 'created_at' field
    
    returns a datetime object converted to US/Eastern time zone, 
    unless specified differently
    
    """
    
    if 'created_at' in tweet and tweet['created_at'] is not None:
        try:
            timestamp = datetime.strptime(tweet['created_at'],'%a %b %d %H:%M:%S +0000 %Y').replace(tzinfo=pytz.UTC)
            return timestamp.astimezone(pytz.timezone(timezone))
        except ValueError:
            return None
    else:
        return None