def getVacationPeriod(self): if self.itemData.vacationStart is not None and self.itemData.vacationFinish is not None: start = time_utils.getTimestampFromUTC(self.itemData.vacationStart.timetuple()) finish = time_utils.getTimestampFromUTC(self.itemData.vacationFinish.timetuple()) return (start, finish) else: return (None, None)
def getFormattedRemainingTime(strEndDate, isRoundUp=False): if strEndDate: endDate = _stringToStruct(strEndDate) endDate = time_utils.getTimestampFromUTC(endDate) currentTimeUTC = _getCurrentUTCTime() currentTimestampUTC = time_utils.getTimestampFromUTC(currentTimeUTC.timetuple()) dtime = endDate - currentTimestampUTC if dtime >= 0 and dtime != float('inf'): return _remainingTimeToEndHelper(dtime, isRoundUp) return (0, FORMAT_EMPTY_STR)
def isPeriodCloseToEnd(strStartDate, strEndDate, percents=0.1): if strStartDate and strEndDate: periodTime = getTimeStampFromDate(strEndDate) - getTimeStampFromDate(strStartDate) if periodTime >= 0: periodTime *= percents currentTimeUTC = _getCurrentUTCTime() currentTimestampUTC = int(time_utils.getTimestampFromUTC(currentTimeUTC.timetuple())) endDate = _stringToStruct(strEndDate) dtime = int(time_utils.getTimestampFromUTC(endDate)) - currentTimestampUTC if periodTime >= dtime >= 0 or dtime < 0: return True return False
def getTimeStatus(strDate): if strDate: value, txtid = getFormattedRemainingTime(strDate, False) if txtid: return (value, txtid) endDate = _stringToStruct(strDate) endDate = time_utils.getTimestampFromUTC(endDate) currentTimeUTC = _getCurrentUTCTime() currentTimestampUTC = time_utils.getTimestampFromUTC(currentTimeUTC.timetuple()) dtime = endDate - currentTimestampUTC if dtime < 0: value, txtid = _remainingTimeToEndHelper(-dtime, False) if txtid: return (-value, txtid) return (0, FORMAT_EMPTY_STR)
def isCurrentTimeInPeriod(strStartDate, strEndDate): if strStartDate and strEndDate: endDate = getTimeStampFromDate(strEndDate) startDate = getTimeStampFromDate(strStartDate) currentTime = _getCurrentUTCTime() return startDate <= int(time_utils.getTimestampFromUTC(currentTime.timetuple())) <= endDate return False
def getFormattedRemainingTime(strEndDate, isRoundUp = False): """ :param strEndDate: UTC date represents as string (2017-01-22T23:23:00) :param isRoundUp: round up time based on time_utils.getTillTimeString() get numeric data (days left, hours left etc) and string with id data (day, hour, minute) according to confluence: https://confluence.wargaming.net/pages/viewpage.action?pageId=463366746 TLEL-02 """ if strEndDate: endDate = _stringToStruct(strEndDate) endDate = time_utils.getTimestampFromUTC(endDate) currentTimeUTC = _getCurrentUTCTime() currentTimestampUTC = time_utils.getTimestampFromUTC(currentTimeUTC.timetuple()) dtime = endDate - currentTimestampUTC if dtime >= 0 and dtime != float('inf'): return _remainingTimeToEndHelper(dtime, isRoundUp) return (0, FORMAT_EMPTY_STR)
def isPeriodCloseToEnd(strStartDate, strEndDate, percents = 0.1): """ :param strStartDate: UTC date represents as string (2017-01-22T23:23:00) :param strEndDate: UTC date represents as string (2017-01-22T23:23:00) :param percents: percents to end value (1..100) according to confluence: https://confluence.wargaming.net/pages/viewpage.action?pageId=473439182 """ if strStartDate and strEndDate: periodTime = getTimeStampFromDate(strEndDate) - getTimeStampFromDate(strStartDate) if periodTime >= 0: periodTime *= percents currentTimeUTC = _getCurrentUTCTime() currentTimestampUTC = int(time_utils.getTimestampFromUTC(currentTimeUTC.timetuple())) endDate = _stringToStruct(strEndDate) dtime = int(time_utils.getTimestampFromUTC(endDate)) - currentTimestampUTC if periodTime >= dtime >= 0 or dtime < 0: return True return False
def isCurrentTimeInPeriod(strStartDate, strEndDate): """ :param strStartDate: UTC date represents as string (2017-01-22T23:23:00) :param strEndDate: UTC date represents as string (2017-01-22T23:23:00) """ if strStartDate and strEndDate: endDate = getTimeStampFromDate(strEndDate) startDate = getTimeStampFromDate(strStartDate) currentTime = _getCurrentUTCTime() return startDate <= int(time_utils.getTimestampFromUTC(currentTime.timetuple())) <= endDate return False
def getUpdateStatus_ts(tsUpdateDate): if tsUpdateDate is not None: currentTime = _getCurrentUTCTime() currentTimestamp = int(time_utils.getTimestampFromUTC(currentTime.timetuple())) currDayStart, currDayEnd = time_utils.getDayTimeBoundsForUTC(tsUpdateDate) if currDayStart - time_utils.ONE_DAY <= currentTimestamp <= currDayEnd - time_utils.ONE_DAY: return FORMAT_TOMORROW_STR if currDayStart <= currentTimestamp <= currDayEnd: return FORMAT_TODAY_STR if currDayStart + time_utils.ONE_DAY <= currentTimestamp <= currDayEnd + time_utils.ONE_DAY: return FORMAT_YESTERDAY_STR return
def getTimeStatus(strDate): """ :param strDate: UTC date represents as string (2017-01-22T23:23:00) get numeric data (+days left, +hours left etc) if it before current time or numeric data (-days left, -hours left etc) if it after current time and string with id data (day, hour, minute) """ if strDate: value, txtid = getFormattedRemainingTime(strDate, False) if txtid: return (value, txtid) endDate = _stringToStruct(strDate) endDate = time_utils.getTimestampFromUTC(endDate) currentTimeUTC = _getCurrentUTCTime() currentTimestampUTC = time_utils.getTimestampFromUTC(currentTimeUTC.timetuple()) dtime = endDate - currentTimestampUTC if dtime < 0: value, txtid = _remainingTimeToEndHelper(-dtime, False) if txtid: return (-value, txtid) return (0, FORMAT_EMPTY_STR)
def getUpdateStatus_ts(tsUpdateDate): """ get string with update status: 'today', 'yesterday' or 'tomorrow' according to confluence: https://confluence.wargaming.net/display/WGCGK/Excel+View#ExcelView-5 paragraph 5 :param tsUpdateDate: UTC date represents as timestamp (1259453) """ if tsUpdateDate is not None: currentTime = _getCurrentUTCTime() currentTimestamp = int(time_utils.getTimestampFromUTC(currentTime.timetuple())) currDayStart, currDayEnd = time_utils.getDayTimeBoundsForUTC(tsUpdateDate) if currDayStart - time_utils.ONE_DAY <= currentTimestamp <= currDayEnd - time_utils.ONE_DAY: return FORMAT_TOMORROW_STR if currDayStart <= currentTimestamp <= currDayEnd: return FORMAT_TODAY_STR if currDayStart + time_utils.ONE_DAY <= currentTimestamp <= currDayEnd + time_utils.ONE_DAY: return FORMAT_YESTERDAY_STR return
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 getJoiningTime(self): return time_utils.getTimestampFromUTC(self.joined_at.timetuple())
def getClanCooldownTill(self): return time_utils.getTimestampFromUTC(self.in_clan_cooldown_till.timetuple())
def _getTimestamp(datetimeValue): return time_utils.getTimestampFromUTC(datetimeValue.timetuple())
def getUpdatedAt(self): return time_utils.getTimestampFromUTC(self.updated_at.timetuple())
def getCreationDate(self): return time_utils.getTimestampFromUTC(self.created_at.timetuple())
def getTimeStampFromDate(strDate): return int(time_utils.getTimestampFromUTC(_stringToStruct(strDate)))
def getTimeNewOffDay(self): if self.itemData.defHourChangeDay is not None: return time_utils.getTimestampFromUTC(self.itemData.defHourChangeDay.timetuple()) else: return
def __doClockworkLogic(self, mode): if not self.isStrongholdSettingsValid(): if mode & self.CWL_RETURN_MATCHING_BUTTON_STATUS == self.CWL_RETURN_MATCHING_BUTTON_STATUS: return True return isInBattle = self._hasInArenaMembers() isInQueue = self._isInQueue() dtime = None peripheryStartTimestampUTC = 0 currentTimestampUTC = 0 matchmakerNextTick = None inactiveMatchingButton = True forceUpdateBuildings = mode & self.CWL_FORCE_UPDATE_BUILDINGS == self.CWL_FORCE_UPDATE_BUILDINGS currentTimeUTC, clientTimeUTC = self._getCurrentUTCTime() timer = self.__strongholdSettings.getTimer() peripheryStartTimeUTC = currentTimeUTC.replace(hour=0, minute=0, second=0, microsecond=0) peripheryEndTimeUTC = currentTimeUTC.replace(hour=0, minute=0, second=0, microsecond=0) if timer.getBattlesStartTime() and timer.getBattlesEndTime(): isInactivePeriphery = False peripheryStartTimeUTC, peripheryEndTimeUTC = self.__calculatePeripheryTimeHelper(currentTimeUTC) peripheryStartTimestampUTC = int(time_utils.getTimestampFromUTC(peripheryStartTimeUTC.timetuple())) currentTimestampUTC = int(time_utils.getTimestampFromUTC(currentTimeUTC.timetuple())) else: peripheryEndTimeUTC -= datetime.timedelta(days=1) peripheryStartTimeUTC -= datetime.timedelta(days=1) isInactivePeriphery = True dtime = 0 if self.__strongholdSettings.isSortie(): textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_UNAVAILABLE if isInQueue: textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINQUEUE dtime = peripheryStartTimestampUTC - currentTimestampUTC if dtime < 0 or dtime > timer.getSortiesBeforeStartLag(): dtime = 0 elif isInBattle: textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINBATTLE elif self.isStrongholdUnitWaitingForData(): textid = TOOLTIPS.STRONGHOLDS_TIMER_WAITINGFORDATA elif peripheryStartTimeUTC <= currentTimeUTC <= peripheryEndTimeUTC: dtime = int((peripheryEndTimeUTC - currentTimeUTC).total_seconds()) inactiveMatchingButton = False if dtime <= timer.getSortiesBeforeEndLag(): textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_ENDOFBATTLESOON else: textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_AVAILABLE elif isInactivePeriphery: dtime = 0 else: dtime = peripheryStartTimestampUTC - currentTimestampUTC if dtime <= timer.getSortiesBeforeStartLag(): if dtime < 0: dtime = 0 textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON if dtime <= self.MATCHMAKING_BATTLE_BUTTON_SORTIE: inactiveMatchingButton = False else: peripheryStartTimeUTC, _ = self.__calculatePeripheryTimeHelper(clientTimeUTC) peripheryStartTimestampUTC = int(time_utils.getTimestampFromUTC(peripheryStartTimeUTC.timetuple())) currentTimestampUTC = int(time_utils.getTimestampFromUTC(clientTimeUTC.timetuple())) peripheryStartTimestamp = self._convertUTCStructToLocalTimestamp(peripheryStartTimeUTC) currentTimestamp = self._convertUTCStructToLocalTimestamp(clientTimeUTC) dtime = peripheryStartTimestampUTC - currentTimestampUTC currDayStart, currDayEnd = time_utils.getDayTimeBoundsForLocal(peripheryStartTimestamp) if currDayStart - time_utils.ONE_DAY <= currentTimestamp <= currDayEnd - time_utils.ONE_DAY: textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETOMORROW elif currDayStart <= currentTimestamp <= currDayEnd: textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETODAY else: textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_UNAVAILABLE if not isInactivePeriphery: dtime = time_utils.ONE_YEAR matchmakerNextTick = timer.getTimeToReady() if matchmakerNextTick is not None: dtime = int(matchmakerNextTick - currentTimestampUTC) else: matchmakerNextTick = timer.getMatchmakerNextTick() if matchmakerNextTick is not None: dtime = int(matchmakerNextTick - currentTimestampUTC) battlesBeforeStartLag = timer.getFortBattlesBeforeStartLag() if self.__prevMatchmakingTimerState == FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON and 0 <= int(dtime - battlesBeforeStartLag) < self.MATCHMAKING_ZERO_TIME_WAITING_FOR_DATA and mode & self.CWL_REGULAR_MODE == self.CWL_REGULAR_MODE: dtime = battlesBeforeStartLag if isInQueue: textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINQUEUE if dtime < 0 or dtime > battlesBeforeStartLag: dtime = 0 elif isInBattle: textid = TOOLTIPS.STRONGHOLDS_TIMER_SQUADINBATTLE elif self.isStrongholdUnitWaitingForData(): textid = TOOLTIPS.STRONGHOLDS_TIMER_WAITINGFORDATA elif dtime > battlesBeforeStartLag: textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_UNAVAILABLE if matchmakerNextTick is not None: peripheryStartTimeUTC, _ = self.__calculatePeripheryTimeHelper(clientTimeUTC) peripheryStartTimestampUTC = int(time_utils.getTimestampFromUTC(peripheryStartTimeUTC.timetuple())) currentTimestampUTC = int(time_utils.getTimestampFromUTC(clientTimeUTC.timetuple())) currentTimestamp = self._convertUTCStructToLocalTimestamp(clientTimeUTC) dtime = int(matchmakerNextTick - currentTimestampUTC) matchmakerNextTickLocal = time_utils.getDateTimeInUTC(matchmakerNextTick) matchmakerNextTickLocal = self._convertUTCStructToLocalTimestamp(matchmakerNextTickLocal) currDayStart, currDayEnd = time_utils.getDayTimeBoundsForLocal(matchmakerNextTickLocal) if currDayStart - time_utils.ONE_DAY <= currentTimestamp <= currDayEnd - time_utils.ONE_DAY: textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETOMORROW elif currDayStart <= currentTimestamp <= currDayEnd: textid = FORTIFICATIONS.SORTIE_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLETODAY elif dtime >= 0: textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON if dtime <= self.MATCHMAKING_BATTLE_BUTTON_BATTLE or not self.__strongholdSettings.isFirstBattle(): inactiveMatchingButton = False else: dtimeWD = dtime + self.MATCHMAKING_ZERO_TIME_WAITING_FOR_DATA if dtimeWD >= 0: textid = FORTIFICATIONS.ROSTERINTROWINDOW_INTROVIEW_FORTBATTLES_NEXTTIMEOFBATTLESOON dtime = 0 if mode & self.CWL_REGULAR_MODE == self.CWL_REGULAR_MODE: self.__prevMatchmakingTimerState = textid if mode & self.CWL_INVOKE_LISTENERS == self.CWL_INVOKE_LISTENERS: header = self.__strongholdSettings.getHeader() g_eventDispatcher.strongholdsOnTimer({'peripheryStartTimestamp': peripheryStartTimestampUTC, 'matchmakerNextTick': matchmakerNextTick, 'clan': header.getClan(), 'enemyClan': header.getEnemyClan(), 'textid': textid, 'dtime': dtime, 'isSortie': self.__strongholdSettings.isSortie(), 'isFirstBattle': self.__strongholdSettings.isFirstBattle(), 'currentBattle': header.getCurrentBattle(), 'maxLevel': header.getMaxLevel(), 'direction': header.getDirection(), 'forceUpdateBuildings': forceUpdateBuildings}) if mode & self.CWL_RETURN_MATCHING_BUTTON_STATUS == self.CWL_RETURN_MATCHING_BUTTON_STATUS: return inactiveMatchingButton elif mode & self.CWL_RETURN_MATCHMAKER_NEXT_TICK == self.CWL_RETURN_MATCHMAKER_NEXT_TICK: return matchmakerNextTick else: return
def _now(self): return time_utils.getTimestampFromUTC(datetime.utcnow().timetuple())
def parsedate(httpDate): return time_utils.getTimestampFromUTC(feedparser._parse_date(httpDate))
def getClanCooldownTill(self): return time_utils.getTimestampFromUTC( self.in_clan_cooldown_till.timetuple())
def getPeripheryTime(primeTime): currentTimeUTC = _getCurrentUTCTime() prStartTimeUTC, prEndTimeUTC = _calculatePeripheryTimeHelper(currentTimeUTC, primeTime) dateStartTimestamp = int(time_utils.getTimestampFromUTC(prStartTimeUTC.utctimetuple())) dateEndTimestamp = int(time_utils.getTimestampFromUTC(prEndTimeUTC.utctimetuple())) return (backport.getShortTimeFormat(dateStartTimestamp), backport.getShortTimeFormat(dateEndTimestamp))