예제 #1
0
파일: utils.py 프로젝트: scanner/asimap
def formatdate(datetime, localtime=False, usegmt=False):
    """
    This is the reverse. It will take a datetime object and format
    and do the deconversions necessary to pass it to email.utils.formatdate()
    and thus return a string properly formatted as an RFC822 date.
    """
    return email.utils.formatdate(calendar.timegm(datetime.utctimetuple()),
                                  localtime=localtime, usegmt=usegmt)
예제 #2
0
def datetime_to_struct(datetime):
    """Convert a datetime object to an UTC-based 9-tuple.

    The reverse of ``struct_to_datetime``.
    """
    if not datetime:
        return datetime
    return datetime.utctimetuple()
예제 #3
0
def from_datetime(datetime):
	"""
	Takes a UTC timestamp (a datetime object)
	and converts it into a 9-tuple to be used by feedparser.
	"""
	if datetime==None:
		return None
	return datetime.utctimetuple()
예제 #4
0
def formatdate(datetime, localtime=False, usegmt=False):
    """
    This is the reverse. It will take a datetime object and format
    and do the deconversions necessary to pass it to email.utils.formatdate()
    and thus return a string properly formatted as an RFC822 date.
    """
    return email.utils.formatdate(calendar.timegm(datetime.utctimetuple()),
                                  localtime=localtime,
                                  usegmt=usegmt)
예제 #5
0
파일: util.py 프로젝트: adbadb/cluster
def seconds_from_datetime(dt):
    """Convert datetime into seconds since epochs in UTC timezone. IE, to use for
  instance.launch_time:
     toseconds(instance.launch_time).

  to invert (assuming UTC timestamps):
     import pytz
     utc = pytz.UTC
     utc.localize(datetime.fromtimestamp(seconds))
  """
    return time.mktime(dt.utctimetuple())
예제 #6
0
 def testDateTime(self):
     iso_string = "2013-06-13T21:33:44+09:00"
     datetime = dateutil.parser.parse(iso_string)
     time_tuple = datetime.utctimetuple()
     self.assertEqual(time_tuple.tm_year, 2013)
     self.assertEqual(time_tuple.tm_mon, 6)
     self.assertEqual(time_tuple.tm_mday, 13)
     self.assertEqual(time_tuple.tm_hour, 12)
     self.assertEqual(time_tuple.tm_min, 33)
     self.assertEqual(time_tuple.tm_sec, 44)
     native = isoToNative(iso_string)
     self.assertIsNone(native.tzinfo)
     time_tuple = native.utctimetuple()
     self.assertEqual(time_tuple.tm_year, 2013)
     self.assertEqual(time_tuple.tm_mon, 6)
     self.assertEqual(time_tuple.tm_mday, 13)
     self.assertEqual(time_tuple.tm_hour, 12)
     self.assertEqual(time_tuple.tm_min, 33)
     self.assertEqual(time_tuple.tm_sec, 44)
예제 #7
0
 def from_datetime(cls, datetime):
     return calendar.timegm(datetime.utctimetuple())
예제 #8
0
파일: util.py 프로젝트: adbadb/cluster
def toseconds(dt):
    """Converts datetime object to seconds."""
    return time.mktime(dt.utctimetuple())
예제 #9
0
def datetime_to_utc(dt):
    """Converts a datetime object to UTC timestamp
        naive datetime will be considered UTC."""

    return calendar.timegm(dt.utctimetuple())
예제 #10
0
파일: utils.py 프로젝트: Hinge/bulbs
def to_timestamp(datetime):
    # Converts a datetime object to unix UTC time
    return calendar.timegm(datetime.utctimetuple()) 
예제 #11
0
파일: utils.py 프로젝트: ct2034/bulbs
def to_timestamp(datetime):
    # Converts a datetime object to unix UTC time
    return calendar.timegm(datetime.utctimetuple())
예제 #12
0
파일: slides.py 프로젝트: nievie/5lide
def datetime_to_timestamp(datetime):
    import calendar
    if datetime:
        return calendar.timegm(datetime.utctimetuple())
    else:
        return None
예제 #13
0
 def timestamp(self, datetime=datetime.datetime.utcnow()):
     ''' return unix timestamp from datetime '''
     return int(time.mktime(datetime.utctimetuple())*1000)
예제 #14
0
파일: utils.py 프로젝트: palli/statmon
def timestamp(datetime):
	return int ( time.mktime( datetime.utctimetuple() ) )
예제 #15
0
파일: TimeUtil.py 프로젝트: Justasic/cia-vc
def datetimeToTimestamp(datetime):
    """Convert a UTC datetime object to a UTC timestamp"""
    return mktime_utc(datetime.utctimetuple())
예제 #16
0
def datetimeToTimestamp(datetime):
    """Convert a UTC datetime object to a UTC timestamp"""
    return mktime_utc(datetime.utctimetuple())