Untitled

By Bistre Crow, 10 Years ago, written in Python, viewed 488 times.
URL http://pb.stoleyour.com/view/3c34b3bc Embed
Download Paste or View RawExpand paste to full width of browser
  1. import time,datetime
  2.  
  3.  
  4. def et(stamp=None):
  5.         """Calculate Eorzea time from a UTC+0 Unixtimestamp. datetime.datetime.utcnow() is preferred, time.time() is not timezone neutral
  6.  
  7.  
  8.        Returns a six-tuple containing year, month, day, hour, minute and seconds"""
  9.         ratio = 20.571428571428573
  10.  
  11.         utc = stamp
  12.  
  13.         epoch = datetime.datetime(year=2010, month=7, day=12, hour=0, minute=0, second=0)
  14.  
  15.         jptime = utc + (9*60*60)
  16.  
  17.         epoch = time.mktime(epoch.timetuple())
  18.  
  19.         diff = jptime - epoch
  20.         diff -= 90000
  21.  
  22.         delta = (diff * ratio)
  23.  
  24.         gameSecond = int((delta % 60)) | 0
  25.         delta -= gameSecond
  26.         delta /= 60.0
  27.  
  28.         gameMinute = int((delta % 60)) | 0
  29.         delta -= gameMinute
  30.         delta /= 60.0
  31.  
  32.         gameHour = int((delta % 24)) | 0
  33.         delta -= gameHour
  34.         delta /= 24.0
  35.  
  36.         gameDay = int((delta % 32)) | 0
  37.         delta -= gameDay
  38.         delta /= 32.0
  39.  
  40.         gameMonth = int((delta % 12)) | 0
  41.         delta -= gameMonth
  42.         delta /= 12.0
  43.  
  44.         gameYear = int(delta) | 0
  45.  
  46.         gameDay += 2
  47.         gameMonth += 1
  48.         gameMinute += 1
  49.  
  50.         if gameMinute == 60:
  51.                 gameHour += 1
  52.                 gameMinute = 0
  53.         if gameDay == 33:
  54.                 gameDay = 1
  55.         elif gameDay == 34:
  56.                 gameDay = 2
  57.         return(int(gameYear), int(gameMonth), int(gameDay), int(gameHour), int(gameMinute), int(gameSecond))
  58.  
  59. def eth(values=None):
  60.         """Human-redable parser for eorzea.et. Returns a string that contains the current Eorzea hour, minute, second, along with the current date"""
  61.         gameYear, gameMonth, gameDay, gameHour, gameMinute, gameSecond = values
  62.         return("Eorzea time: %s:%s:%s (%s.%s.%s)" %
  63.                 ("0" + str(gameHour) if len(str(gameHour)) == 1 else gameHour,
  64.                 "0" + str(gameMinute) if len(str(gameMinute)) == 1 else gameMinute,
  65.                 "0" + str(gameSecond) if len(str(gameSecond)) == 1 else gameSecond,
  66.                 gameYear,
  67.                 "0" + str(gameMonth) if len(str(gameMonth)) == 1 else gameMonth,
  68.                 "0" + str(gameDay) if len(str(gameDay)) == 1 else gameDay))
  69.  
  70.  

Reply to "Untitled"

Here you can reply to the paste above