int Date::getTimeZoneOffset() { if (INT_MIN == s_timeZoneOffset) { Date utc(1970, 1, 1); s_timeZoneOffset = utc.stamp(); } return s_timeZoneOffset; }
LEMON_UNITTEST_CASE(DateTimeUnittest,datetimeTest) { time_t t = time_t::now(); localtime_t local(t); utctime_t utc(t); LEMON_CHECK(local.time() == utc.time()); }
// CLASS METHODS DatetimeTz CurrentTime::asDatetimeTz() { Datetime now = utc(); bsls::TimeInterval offset = LocalTimeOffset::localTimeOffset(now); now.addSeconds(offset.totalSeconds()); BSLS_ASSERT((-1440 < offset.totalMinutes()) && (offset.totalMinutes() < 1440)); return DatetimeTz(now, static_cast<int>(offset.totalMinutes())); }
Creature::Creature(const Common::UString &resRef) : Object(kObjectTypeCreature), _commandable(true), _walkRate(0.0f), _runRate(0.0f) { init(); Common::ScopedPtr<Aurora::GFF3File> utc(loadOptionalGFF3(resRef, Aurora::kFileTypeUTC)); if (!utc) throw Common::Exception("Creature \"%s\" has no blueprint", resRef.c_str()); load(utc->getTopLevel()); }
void show_times() { char buffer[100]; const int year = 2013; const int month = 4; int day = 7; // Set timezone (POSIX extension) setenv("TZ", "EST-10EST-9:03:00,M10,1.0,M4.1.0/3", 1); // Shows times for each hour in the selected day for ( int hour = 0; hour < 24; ++hour ) { utctime::UTCTime utc(year, month, day, hour, 0, 0); time_t ts = utc.timestamp(); // Output local time of returned timestamp tm* ptm = localtime(&ts); if ( ptm == 0 ) { std::cerr << "Couldn't get time!" << std::endl; return; } tm local_tm = *ptm; strftime(buffer, 100, "%b %d, %y %H:%M loc", &local_tm); std::cout << buffer << " : "; // Output GMT time of returned timestamp ptm = gmtime(&ts); if ( ptm == 0 ) { std::cerr << "Couldn't get time!" << std::endl; return; } tm gm_tm = *ptm; strftime(buffer, 100, "%b %d, %y %H:%M loc", &gm_tm); std::cout << buffer << " : "; // Output what UTCTime class says UTC time is std::cout << utc.time_string_inet() << std::endl; } }
int main(void) { try { utctime::UTCTime utc(1, 12, 31, 6, 6, 6); } catch(utctime::UTCTimeException& e) { std::cerr << e.what() << std::endl; return 1; } utctime::UTCTime utc; std::cout << "Current UTC time is: " << utc.time_string() << std::endl << std::endl; astro::show_planet_positions(std::cout); return 0; }
/* QDateTime Wpp::makeDateTime(const QString& ianaId, qint64 msecsSinceEpoch) { if ( ianaId.isEmpty() ) return QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch, QTimeZone(getSystemTimezoneId()) ); else return QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch, QTimeZone(ianaId.toLatin1()) ); } QDateTime Wpp::currentDateTime(const QString& ianaId) { return makeDateTime(ianaId, QDateTime::currentMSecsSinceEpoch()); } */ QString Wpp::formatDateTime(qint64 msecsSinceEpoch, const QString& format, const QString& ianaId) { //QDateTime dateTime = makeDateTime(ianaId, msecsSinceEpoch); QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch); QDateTime utc(dateTime.toTimeSpec(Qt::UTC)); QDateTime tzDateTime = utc.toTimeZone( QTimeZone(ianaId.toLatin1()) );// createTimeZone(ianaId) ); qDebug() << __FUNCTION__ << ":ianaId=" << ianaId; qDebug() << __FUNCTION__ << ":msecsSinceEpoch=" << msecsSinceEpoch; qDebug() << __FUNCTION__ << ":format=" << format; qDebug() << __FUNCTION__ << ":dateTime=" << dateTime; qDebug() << __FUNCTION__ << ":utc=" << utc; qDebug() << __FUNCTION__ << ":tzDateTime=" << tzDateTime; qDebug() << __FUNCTION__ << ":tzDateTime.toString(format)=" << tzDateTime.toString(format); return tzDateTime.toString(format); }
const Common::UString PartySelectionGUI::getPortrait(const Common::UString &templ) { Common::ScopedPtr<Aurora::GFF3File> utc(loadOptionalGFF3(templ, Aurora::kFileTypeUTC, MKTAG('U', 'T', 'C', ' '))); if (!utc) throw Common::Exception("Invalid creature template: %s", templ.c_str()); const Aurora::GFF3Struct &gff = utc->getTopLevel(); Common::UString portrait; uint32 portraitId = gff.getUint("PortraitId"); if (portraitId != 0) { const Aurora::TwoDAFile &twoda = TwoDAReg.get2DA("portraits"); portrait = twoda.getRow(portraitId).getString("BaseResRef"); } return gff.getString("Portrait", portrait); }
static jobjectArray TimeZones_getZoneStringsImpl(JNIEnv* env, jclass, jstring localeName, jobjectArray timeZoneIds) { Locale locale = getLocale(env, localeName); // We could use TimeZone::getDisplayName, but that's even slower // because it creates a new SimpleDateFormat each time. // We're better off using SimpleDateFormat directly. // We can't use DateFormatSymbols::getZoneStrings because that // uses its own set of time zone ids and contains empty strings // instead of GMT offsets (a pity, because it's a bit faster than this code). UErrorCode status = U_ZERO_ERROR; UnicodeString longPattern("zzzz", 4, US_INV); SimpleDateFormat longFormat(longPattern, locale, status); // 'z' only uses "common" abbreviations. 'V' allows all known abbreviations. // For example, "PST" is in common use in en_US, but "CET" isn't. UnicodeString commonShortPattern("z", 1, US_INV); SimpleDateFormat shortFormat(commonShortPattern, locale, status); UnicodeString allShortPattern("V", 1, US_INV); SimpleDateFormat allShortFormat(allShortPattern, locale, status); UnicodeString utc("UTC", 3, US_INV); // TODO: use of fixed dates prevents us from using the correct historical name when formatting dates. // TODO: use of dates not in the current year could cause us to output obsoleted names. // 15th January 2008 UDate date1 = 1203105600000.0; // 15th July 2008 UDate date2 = 1218826800000.0; // In the first pass, we get the long names for the time zone. // We also get any commonly-used abbreviations. std::vector<TimeZoneNames> table; typedef std::map<UnicodeString, UnicodeString*> AbbreviationMap; AbbreviationMap usedAbbreviations; size_t idCount = env->GetArrayLength(timeZoneIds); for (size_t i = 0; i < idCount; ++i) { ScopedLocalRef<jstring> javaZoneId(env, reinterpret_cast<jstring>(env->GetObjectArrayElement(timeZoneIds, i))); ScopedJavaUnicodeString zoneId(env, javaZoneId.get()); UnicodeString id(zoneId.unicodeString()); TimeZoneNames row; if (isUtc(id)) { // ICU doesn't have names for the UTC zones; it just says "GMT+00:00" for both // long and short names. We don't want this. The best we can do is use "UTC" // for everything (since we don't know how to say "Universal Coordinated Time"). row.tz = NULL; row.longStd = row.shortStd = row.longDst = row.shortDst = utc; table.push_back(row); usedAbbreviations[utc] = &utc; continue; } row.tz = TimeZone::createTimeZone(id); longFormat.setTimeZone(*row.tz); shortFormat.setTimeZone(*row.tz); int32_t daylightOffset; int32_t rawOffset; row.tz->getOffset(date1, false, rawOffset, daylightOffset, status); if (daylightOffset != 0) { // The TimeZone is reporting that we are in daylight time for the winter date. // The dates are for the wrong hemisphere, so swap them. row.standardDate = date2; row.daylightSavingDate = date1; } else { row.standardDate = date1; row.daylightSavingDate = date2; } longFormat.format(row.standardDate, row.longStd); shortFormat.format(row.standardDate, row.shortStd); if (row.tz->useDaylightTime()) { longFormat.format(row.daylightSavingDate, row.longDst); shortFormat.format(row.daylightSavingDate, row.shortDst); } else { row.longDst = row.longStd; row.shortDst = row.shortStd; } table.push_back(row); usedAbbreviations[row.shortStd] = &row.longStd; usedAbbreviations[row.shortDst] = &row.longDst; } // In the second pass, we create the Java String[][]. // We also look for any uncommon abbreviations that don't conflict with ones we've already seen. jobjectArray result = env->NewObjectArray(idCount, JniConstants::stringArrayClass, NULL); UnicodeString gmt("GMT", 3, US_INV); for (size_t i = 0; i < table.size(); ++i) { TimeZoneNames& row(table[i]); // Did we get a GMT offset instead of an abbreviation? if (row.shortStd.length() > 3 && row.shortStd.startsWith(gmt)) { // See if we can do better... UnicodeString uncommonStd, uncommonDst; allShortFormat.setTimeZone(*row.tz); allShortFormat.format(row.standardDate, uncommonStd); if (row.tz->useDaylightTime()) { allShortFormat.format(row.daylightSavingDate, uncommonDst); } else { uncommonDst = uncommonStd; } // If this abbreviation isn't already in use, we can use it. AbbreviationMap::iterator it = usedAbbreviations.find(uncommonStd); if (it == usedAbbreviations.end() || *(it->second) == row.longStd) { row.shortStd = uncommonStd; usedAbbreviations[row.shortStd] = &row.longStd; } it = usedAbbreviations.find(uncommonDst); if (it == usedAbbreviations.end() || *(it->second) == row.longDst) { row.shortDst = uncommonDst; usedAbbreviations[row.shortDst] = &row.longDst; } } // Fill in whatever we got. ScopedLocalRef<jobjectArray> javaRow(env, env->NewObjectArray(5, JniConstants::stringClass, NULL)); ScopedLocalRef<jstring> id(env, reinterpret_cast<jstring>(env->GetObjectArrayElement(timeZoneIds, i))); env->SetObjectArrayElement(javaRow.get(), 0, id.get()); setStringArrayElement(env, javaRow.get(), 1, row.longStd); setStringArrayElement(env, javaRow.get(), 2, row.shortStd); setStringArrayElement(env, javaRow.get(), 3, row.longDst); setStringArrayElement(env, javaRow.get(), 4, row.shortDst); env->SetObjectArrayElement(result, i, javaRow.get()); delete row.tz; } return result; }
void TimeKeeper::PPS_ISR_I(void) { drift_est.sample_prev = drift_est.sample; drift_est.sample = utc(); ppstimesync_sem.signalI(); }
// seti_time::ut1() returns UT1 in hours past midnight. Warning, can return // numbers less than 0 and greater than 24. hours seti_time::ut1() const { hours h(utc()+ut1_utc_diff()); return h; }
//------------------------------------------------------------------------------ // Parse a time string read from the EM file and convert it to // a Real (A1Mjd) epoch //------------------------------------------------------------------------------ Real CCSDSEMSegment::ParseEpoch(const std::string &epochString) { #ifdef DEBUG_PARSE_EPOCH MessageInterface::ShowMessage("ParseEpoch -- epochString = \"%s\"\n", epochString.c_str()); #endif // The epochs can be in either of two formats: // YYYY-MM-DDThh:mm:ss.mmm // YYYY-DOYThh:mm:ss std::string yyyymmdd, hhmmss, YYstr, MMstr, DDstr, hhstr, mmstr, ssmmmstr; Integer year, month = 0, day, hour, minute; Real seconds; bool doyUsed = false; std::size_t tPos = epochString.find_first_of("Tt"); if (tPos == std::string::npos) { std::string errmsg = "Error reading ephemeris message file segment. "; errmsg += "Missing or incorrectly formatted data Epoch.\n"; throw UtilityException(errmsg); } yyyymmdd = epochString.substr(0,tPos); hhmmss = epochString.substr(tPos+1); if ((hhmmss.length() < 8) || (GmatStringUtil::NumberOfOccurrences(hhmmss, ':') != 2)) { std::string errmsg = "Error reading ephemeris message file segment. "; errmsg += "hhmmss.sss part of Time \"" + epochString; errmsg += "\" is not formatted correctly.\n"; throw UtilityException(errmsg); } hhstr = hhmmss.substr(0,2); mmstr = hhmmss.substr(3,2); ssmmmstr = hhmmss.substr(6); if ((!GmatStringUtil::ToInteger(hhstr, hour)) || (!GmatStringUtil::ToInteger(mmstr, minute)) || (!GmatStringUtil::ToReal(ssmmmstr, seconds))) { std::string errmsg = "Error reading ephemeris message file segment. "; errmsg += "hhmmss.sss part of Time \"" + epochString; errmsg += "\" is not formatted correctly.\n"; throw UtilityException(errmsg); } Integer numDashes = GmatStringUtil::NumberOfOccurrences(yyyymmdd, '-'); if (numDashes == 1) // YYYY-DOYThh:mm:ss { doyUsed = true; YYstr = yyyymmdd.substr(0,4); DDstr = yyyymmdd.substr(5,3); if ((!GmatStringUtil::ToInteger(YYstr, year)) || (!GmatStringUtil::ToInteger(DDstr, day))) { std::string errmsg = "Error reading ephemeris message file segment. "; errmsg += "YYYY-DOY part of Time \"" + epochString; errmsg += "\" is not formatted correctly.\n"; throw UtilityException(errmsg); } } else if (numDashes == 2) // YYYY-MM-DDThh:mm:ss.mmm { doyUsed = false; YYstr = yyyymmdd.substr(0,4); MMstr = yyyymmdd.substr(5,2); DDstr = yyyymmdd.substr(8,2); if ((!GmatStringUtil::ToInteger(YYstr, year)) || (!GmatStringUtil::ToInteger(MMstr, month)) || (!GmatStringUtil::ToInteger(DDstr, day))) { std::string errmsg = "Error reading ephemeris message file segment. "; errmsg += "YYYY-MM-DD part of Time \"" + epochString; errmsg += "\" is not formatted correctly.\n"; throw UtilityException(errmsg); } } else { std::string errmsg = "Error reading ephemeris message file segment. "; errmsg += "Time \"" + epochString; errmsg += "\" is not formatted correctly.\n"; throw UtilityException(errmsg); } #ifdef DEBUG_PARSE_EPOCH MessageInterface::ShowMessage("epochString = %s, yyyymmdd = %s, hhmmss = %s\n", epochString.c_str(), yyyymmdd.c_str(), hhmmss.c_str()); MessageInterface::ShowMessage("year = %d, month = %d, day = %d\n", year, month, day); MessageInterface::ShowMessage("hour = %d, minute = %d, seconds = %lf\n", hour, minute, seconds); #endif if (doyUsed) { try { UtcDate utc(year, day, hour, minute, seconds); #ifdef DEBUG_PARSE_EPOCH MessageInterface::ShowMessage(" --- UTC data to packed calendar string = %s\n", utc.ToPackedCalendarString().c_str()); #endif return utc.ToA1Mjd(); } catch (Date::LeapYearError &lye) { std::ostringstream errmsg; errmsg << "Cannot read CCSDS file. File contains time \""; errmsg << epochString << "\", which specifies day number "; errmsg << day << " for a non-leap year.\n"; throw UtilityException(errmsg.str()); } } else { UtcDate utc(year, month, day, hour, minute, seconds); #ifdef DEBUG_PARSE_EPOCH MessageInterface::ShowMessage(" --- UTC data to packed calendar string = %s\n", utc.ToPackedCalendarString().c_str()); #endif return utc.ToA1Mjd(); } }