def getPeriodsBetween(self, startTime, endTime, includeBeginning=True, includeEnd=True, preferPeriodBounds=False): periods = [] startDateTime = time_utils.getDateTimeInUTC(startTime) startTimeDayStart, _ = time_utils.getDayTimeBoundsForUTC(startTime) weekDay = startDateTime.isoweekday() while startTimeDayStart <= endTime: if weekDay in self.__periods: for (startH, startM), (endH, endM) in self.__periods[weekDay]: periodStartTime = startTimeDayStart + startH * time_utils.ONE_HOUR + startM * time_utils.ONE_MINUTE periodEndTime = startTimeDayStart + endH * time_utils.ONE_HOUR + endM * time_utils.ONE_MINUTE if startTime < periodEndTime and periodStartTime <= endTime: if not includeBeginning and startTime > periodStartTime: continue if not includeEnd and endTime < periodEndTime: continue if preferPeriodBounds: periods.append((periodStartTime, periodEndTime)) else: periods.append((max(startTime, periodStartTime), min(endTime, periodEndTime))) if weekDay == time_utils.WEEK_END: weekDay = time_utils.WEEK_START else: weekDay += 1 startTimeDayStart += time_utils.ONE_DAY return collapseIntervals(periods)
def getPeriodsBetween(self, startTime, endTime): """ Return the periods that includes two timestamps :param startTime: start time stamp in UTC :param endTime: end time stamp in UTC :return: list on periods as (start, end) """ periods = [] startDateTime = time_utils.getDateTimeInUTC(startTime) startTimeDayStart, _ = time_utils.getDayTimeBoundsForUTC(startTime) weekDay = startDateTime.isoweekday() while startTimeDayStart <= endTime: if weekDay in self.__periods: for (startH, startM), (endH, endM) in self.__periods[weekDay]: periodStartTime = startTimeDayStart + startH * time_utils.ONE_HOUR + startM * time_utils.ONE_MINUTE periodEndTime = startTimeDayStart + endH * time_utils.ONE_HOUR + endM * time_utils.ONE_MINUTE if startTime < periodEndTime and periodStartTime <= endTime: periods.append((max(startTime, periodStartTime), min(endTime, periodEndTime))) if weekDay == time_utils.WEEK_END: weekDay = time_utils.WEEK_START else: weekDay += 1 startTimeDayStart += time_utils.ONE_DAY return collapseIntervals(periods)
def __setData(self): dayStartUTC, _ = time_utils.getDayTimeBoundsForUTC( time_utils.getCurrentTimestamp()) vacationStart = dayStartUTC + time_utils.ONE_DAY + fortified_regions.g_cache.minVacationPreorderTime self.as_setDataS({ 'startVacation': vacationStart, 'vacationDuration': -1, 'isAmericanStyle': False, 'showMonth': SHOW_MAX_MONTH })
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 onLobbyStarted(self, event): if self.__showOnSplash: lastShowTstamp = self.__getShowTimestamp() now = time_utils.getServerUTCTime() if lastShowTstamp is not None: today = time_utils.getDayTimeBoundsForUTC(now)[0] offset = _START_OF_DAY_OFFSET.get(constants.CURRENT_REALM, timedelta(0)).total_seconds() dayStart = today + offset mustShow = lastShowTstamp < dayStart <= now or lastShowTstamp > now else: mustShow = True if mustShow: self.showCalendar(CalendarInvokeOrigin.SPLASH) self.__setShowTimestamp(now) return
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 __getDirectionsData(self): directions = [] fort = self.fortCtrl.getFort() start, finish = time_utils.getDayTimeBoundsForUTC(self.__selectedDefencePeriodStart) def filterToday(item): if start <= item.getStartTime() <= finish: return True return False attacksThisDayByUTC = fort.getAttacks(filterFunc=filterToday) hasFreeDirsLeft = len(attacksThisDayByUTC) < len(fort.getOpenedDirections()) for direction in xrange(1, fortified_regions.g_cache.maxDirections + 1): isOpened = bool(self.__item.getDirMask() & 1 << direction) name = _ms('#fortifications:General/directionName%d' % direction) data = {'name': name, 'uid': direction, 'isOpened': isOpened, 'ttHeader': _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANDESCRIPTION_DIRECTION_TOOLTIP_NOTAVAILABLE_HEADER, direction=name), 'ttBody': _ms(FORTIFICATIONS.FORTINTELLIGENCE_CLANDESCRIPTION_DIRECTION_TOOLTIP_NOTOPENED)} if isOpened: attackTime, attackerClanDBID, attackerClanName, byMyClan = self.__getDirectionAttackerInfo(direction) availableTime = self.__item.getDictDirOpenAttacks().get(direction, 0) if availableTime <= self.__selectedDefencePeriodStart: availableTime = None buildings = self.__getDirectionBuildings(direction) ttHeader, ttBody, infoMessage = self.__getDirectionTooltipData(name, buildings, attackerClanDBID, attackerClanName, attackTime, availableTime) isBusy = attackerClanDBID is not None isInCooldown = availableTime is not None isAvailableForAttack = self.fortCtrl.getFort().canPlanAttackOn(self.__selectedDefencePeriodStart, self.__item) == ATTACK_PLAN_RESULT.OK isAvailable = not self.__weAreAtWar and hasFreeDirsLeft and not isBusy and not isInCooldown and isAvailableForAttack data.update({'buildings': buildings, 'isAvailable': isAvailable, 'infoMessage': infoMessage, 'ttHeader': ttHeader, 'ttBody': ttBody, 'isAttackDeclaredByMyClan': byMyClan, 'attackerClanID': attackerClanDBID, 'attackerClanName': attackerClanName}) directions.append(data) return directions
def adjustVacationToUTC(vacationStart, vacationDuration): vacationStart, _ = time_utils.getDayTimeBoundsForUTC(vacationStart) return (vacationStart, vacationDuration)