unsigned int GameTime::getWeek() const { date firstMonday = previous_weekday(GAME_START.date(), greg_weekday(Monday)); date lastMonday = previous_weekday(getPtime(this->ticks).date(), greg_weekday(Monday)); date_duration duration = lastMonday - firstMonday; return duration.days() / 7 + 1; }
UString GameTime::getLongDateString() const { std::stringstream ss; if (DATE_LONG_FORMAT == nullptr) { apoc_date_facet *dateFacet = new apoc_date_facet("%A, %E %B, %Y"); DATE_LONG_FORMAT = new std::locale(std::locale::classic(), dateFacet); std::vector<std::string> months = { tr("January").str(), tr("February").str(), tr("March").str(), tr("April").str(), tr("May").str(), tr("June").str(), tr("July").str(), tr("August").str(), tr("September").str(), tr("October").str(), tr("November").str(), tr("December").str()}; dateFacet->long_month_names(months); std::vector<std::string> weekdays = { tr("Sunday").str(), tr("Monday").str(), tr("Tuesday").str(), tr("Wednesday").str(), tr("Thursday").str(), tr("Friday").str(), tr("Saturday").str()}; dateFacet->long_weekday_names(weekdays); std::vector<std::string> days = { tr("1st").str(), tr("2nd").str(), tr("3rd").str(), tr("4th").str(), tr("5th").str(), tr("6th").str(), tr("7th").str(), tr("8th").str(), tr("9th").str(), tr("10th").str(), tr("11th").str(), tr("12th").str(), tr("13th").str(), tr("14th").str(), tr("15th").str(), tr("16th").str(), tr("17th").str(), tr("18th").str(), tr("19th").str(), tr("20th").str(), tr("21st").str(), tr("22nd").str(), tr("23rd").str(), tr("24th").str(), tr("25th").str(), tr("26th").str(), tr("27th").str(), tr("28th").str(), tr("29th").str(), tr("30th").str(), tr("31st").str()}; dateFacet->longDayNames(days); } ss.imbue(*DATE_LONG_FORMAT); ss << getPtime(this->ticks).date(); return ss.str(); }
UString GameTime::getShortTimeString() const { std::stringstream ss; if (TIME_SHORT_FORMAT == nullptr) { // locale controls the facet time_facet *timeFacet = new time_facet("%H:%M"); TIME_SHORT_FORMAT = new std::locale(std::locale::classic(), timeFacet); } ss.imbue(*TIME_SHORT_FORMAT); ss << getPtime(this->ticks); return ss.str(); }
PointDataSaver::PointDataSaver(const std::string & referenceTime, const std::string & dataProvider, bool loadPlaceDefinition, const mox::ForecastCollection & forecasts) : pqxx::transactor<>("PointDataSaver"), dataProvider_(dataProvider), loadPlaceDefinition_(loadPlaceDefinition), forecasts_(forecasts) { if ( not referenceTime.empty() ) { try { referenceTime_ = getPtime(referenceTime); } catch ( std::exception & ) { throw std::logic_error("Invalid reference time specification: " + referenceTime); } } }
unsigned int GameTime::getMinutes() const { return getPtime(this->ticks).time_of_day().minutes(); }
unsigned int GameTime::getHours() const { return getPtime(this->ticks).time_of_day().hours(); }
unsigned int GameTime::getDay() const { return getPtime(this->ticks).date().day(); }
int getBEtime (char *toptarg, char flag, time_t tTime[]) { char *cp ,*cp1, *cp3; time_t sbtime; int cc; char endTime; checkThree (toptarg, ',', &cp, &cp1, &cp3); if (cp1 != NULL) { lserrno = LSE_BAD_TIME; return -1; } if (cp == NULL) { checkThree (toptarg, '.', &cp, &cp1, &cp3); if (cp != NULL) { lserrno = LSE_BAD_TIME; return -1; } endTime = FALSE; sbtime = 0; if ((cc = getPtime (toptarg, endTime, sbtime, flag, &tTime[0])) == -1) return -1; endTime = TRUE; if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1) return -1; if (checkBEtime ( tTime[0], tTime[1]) == -1) return -1; return 0; } while (TRUE) { if ( *toptarg == ',' ) { tTime[0] = 0; toptarg ++; break; } if ( (*toptarg == '.')&&(*(toptarg+1) == ',') ) { tTime[0] = time(0); toptarg = cp; } if ( *toptarg == ',' ) { tTime[0] = time(0); toptarg = cp +1; break; } if ( (*toptarg == '.') && (*(toptarg+1) == '-') ) { sbtime = time(0); toptarg += 2; *cp = '\000'; endTime = FALSE; if (getPtime (toptarg, endTime, sbtime, flag, &tTime[0]) == -1) return -1; toptarg = cp+1; break; } if ( (*toptarg == '@') && (*(toptarg+1) == ',') ) { endTime = FALSE; tTime[0] = getToday(endTime); toptarg = cp+1; break; } if ( (*toptarg == '@') && (*(toptarg+1) == '-') ) { endTime = FALSE; sbtime = getToday(endTime); toptarg += 2; *cp = '\000'; if (getPtime (toptarg, endTime, sbtime, flag, &tTime[0]) == -1) return -1; toptarg = cp+1; break; } endTime = FALSE; *cp = '\000'; sbtime = 0; if (getPtime (toptarg, endTime, sbtime, flag, &tTime[0]) == -1) { *cp = ','; return -1; } toptarg = cp + 1; break; } if ( (*toptarg == '.' && *(toptarg+1) == '\0') || (*toptarg == '\0')) { tTime[1] = time(0); if (checkBEtime ( tTime[0], tTime[1] ) == -1) { *cp = ','; return -1; } return 0; } if ((*toptarg == '.') && (*(toptarg+1) == '-')) { sbtime = time(0); toptarg += 2; endTime = FALSE; if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1) { *cp = ','; return -1; } if (checkBEtime ( tTime[0], tTime[1] ) == -1) { *cp = ','; return -1; } return 0; } if ((*toptarg == '@') && (*(toptarg+1) == '\0')) { endTime = TRUE; tTime[1] = getToday(endTime); if (checkBEtime ( tTime[0], tTime[1] ) == -1) { *cp = ','; return -1; } return 0; } if ((*toptarg == '@') && (*(toptarg+1) == '-')) { endTime = TRUE; sbtime = getToday(endTime); toptarg += 2; if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1) { *cp = ','; return -1; } if (checkBEtime ( tTime[0], tTime[1] ) == -1) { *cp = ','; return -1; } return 0; } endTime = TRUE; sbtime = FALSE; toptarg = cp+1; if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1) { *cp = ','; return -1; } if (checkBEtime ( tTime[0], tTime[1] ) == -1) { *cp = ','; return -1; } return 0; }