def formatdate(timestamp): ts = time_utils.getTimeStructInUTC(timestamp) short_weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] return '%s, %02d %s %04d %02d:%02d:%02d GMT' % (short_weekdays[ts[6]], ts[2], months[ts[1] - 1], ts[0], ts[3], ts[4], ts[5])
def getUpdatePeriods(forbiddenUTCHours, localTimestamp = None): def __getHour(index): index += 1 if index == time_utils.HOURS_IN_DAY: index = 0 return index firstPeriod = 0 outcomePeriods = [] if forbiddenUTCHours and len(forbiddenUTCHours) < time_utils.HOURS_IN_DAY: utc = time_utils.getTimeStructInUTC(localTimestamp) utcCurrHour = utc.tm_hour forbiddenValue = utcCurrHour in forbiddenUTCHours hoursTillFirstUpdate = None hoursTillUpdate = 0 hour = utcCurrHour for i in range(0, time_utils.HOURS_IN_DAY + 1): hour = __getHour(hour) currForbiddenValue = hour in forbiddenUTCHours if currForbiddenValue != forbiddenValue: forbiddenValue = currForbiddenValue if hoursTillFirstUpdate is None: hoursTillFirstUpdate = hoursTillUpdate else: outcomePeriods.append((hoursTillUpdate + 1) * time_utils.ONE_HOUR) hoursTillUpdate = 0 elif i != time_utils.HOURS_IN_DAY: hoursTillUpdate += 1 else: outcomePeriods.append((hoursTillUpdate + 1 + hoursTillFirstUpdate) * time_utils.ONE_HOUR) secondsLeft = time_utils.ONE_HOUR - (utc.tm_min * time_utils.ONE_MINUTE + utc.tm_sec) firstPeriod = hoursTillFirstUpdate * time_utils.ONE_HOUR + secondsLeft return (firstPeriod, outcomePeriods)
def __calcStatus(self, hours = None, servers = None): servSettings = self.__getServerSettings() if servers is None: servers = servSettings.getForbiddenSortiePeripheryIDs() if servSettings else [] hours = hours or self._getForbiddenHours() utcHour = time_utils.getTimeStructInUTC(self._getTimeStamp()).tm_hour self.__sortiesAvailable = not isHourInForbiddenList(hours, utcHour) self.__currServerAvailable = connectionManager.peripheryID not in servers LOG_DEBUG('Sorties availability:', 'At current hour:', self.__sortiesAvailable, 'At current periphery:', self.__currServerAvailable) return
def __getDailyResetStatus(): timeLeft = time_utils.ONE_DAY - time_utils.getServerRegionalTimeCurrentDay() if timeLeft >= 0: timeFmt = backport.text(R.strings.quests.details.conditions.postBattle.deltaDailyReset.timeFmt()) parts = time_utils.getTimeStructInUTC(timeLeft) try: return time.strftime(timeFmt, parts) except ValueError: _logger.error('Current time locale: %r', locale.getlocale(locale.LC_TIME)) _logger.error('Selected language: %r', getLanguageCode()) _logger.exception('Invalid formatting string %r to delta of time %r', timeFmt, parts)
def formatdate(timestamp): ts = time_utils.getTimeStructInUTC(timestamp) short_weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] return "%s, %02d %s %04d %02d:%02d:%02d GMT" % ( short_weekdays[ts[6]], ts[2], months[ts[1] - 1], ts[0], ts[3], ts[4], ts[5], )
def _getCompleteWeeklyStatus(self, completeKey): curTime = time_utils.getTimeStructInUTC( time_utils.getCurrentTimestamp()) resetDay, resetSeconds = self._getWeeklyProgressResetTimeUTC() dayDelta = (resetDay - curTime.tm_wday) % 7 if dayDelta == 0: dayDelta = 7 timeDelta = dayDelta * time_utils.ONE_DAY + resetSeconds - ( curTime.tm_hour * time_utils.ONE_HOUR + curTime.tm_min * time_utils.ONE_MINUTE + curTime.tm_sec) if timeDelta > time_utils.ONE_WEEK: timeDelta -= time_utils.ONE_WEEK return backport.text(completeKey, time=self._getTillTimeString(timeDelta))
def makeBanInfo(*args): items = [] for item in args: if len(item) < 6: continue source, setter, expiresAt, reason, components, game = item[:6] if source.isdigit(): source = int(source) else: source = 0 if expiresAt.isdigit(): expiresAt = time_utils.getTimestampFromUTC(time_utils.getTimeStructInUTC(float(expiresAt))) else: expiresAt = 0 items.append(_BanInfoItem(source, setter, expiresAt, reason, XMPP_BAN_COMPONENT.fromString(components), game)) if items: info = BanInfo(items) else: info = None return info
def makeBanInfo(*args): items = [] for item in args: if len(item) < 4: continue source, setter, expiresAt, reason = item[:4] if source.isdigit(): source = int(source) else: source = 0 if expiresAt.isdigit(): expiresAt = time_utils.getTimestampFromUTC(time_utils.getTimeStructInUTC(float(expiresAt))) else: expiresAt = 0 items.append(_BanInfoItem(source, setter, expiresAt, reason)) if items: info = BanInfo(items) else: info = None return info
def isHourInForbiddenList(hours, currUtcTimeHour = None): if currUtcTimeHour is not None: cTime = currUtcTimeHour else: cTime = time_utils.getTimeStructInUTC(None).tm_hour return cTime in hours
def _calcStatus(self, hours = None): hours = hours or self.getForbiddenHours() utcHour = time_utils.getTimeStructInUTC(self._getTimeStamp()).tm_hour self._battlesAvailable = not isHourInForbiddenList(hours, utcHour) self._currServerAvailable = self.isServerAvailable()
def isHourInForbiddenList(hours, currUtcTimeHour=None): if currUtcTimeHour is not None: cTime = currUtcTimeHour else: cTime = time_utils.getTimeStructInUTC(None).tm_hour return cTime in hours
def _calcStatus(self, hours=None): hours = hours or self.getForbiddenHours() utcHour = time_utils.getTimeStructInUTC(self._getTimeStamp()).tm_hour self._battlesAvailable = not isHourInForbiddenList(hours, utcHour) self._currServerAvailable = self.isServerAvailable()
def __getDayMonth(timeStamp): timeStruct = time_utils.getTimeStructInUTC(timeStamp) return (timeStruct.tm_mday, timeStruct.tm_mon)