Beispiel #1
0
char* mthr(float time1, float time2, char* inject)
{
    static char fmttime[] = "00:00A> 00:00A";
    int h1 = hours(time1);
    int m1 = mins(time1);
    int h2 = hours(time2);
    int m2 = mins(time2);
    if (clock_is_24h_style()) {
        mini_snprintf(fmttime, sizeof(fmttime), "%d:%02d%s %d:%02d",h1,m1,inject,h2,m2);
	} else {
        if (h1 > 11 && h2 > 11) {
            if (h1 > 12) h1 -= 12;
            if (h2 > 12) h2 -= 12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dP%s %d:%02dP",h1,m1,inject,h2,m2);
        } else if (h1 > 11) {
			if (h1 > 12) h1 -= 12;
			if (h2 == 0) h2=12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dP%s %d:%02dA",h1,m1,inject,h2,m2);
        } else if (h2 > 11) {
			if (h2 > 12) h2 -= 12;
			if (h1 == 0) h1=12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dA%s %d:%02dP",h1,m1,inject,h2,m2);
        } else {
			if (h1 == 0) h1=12;
			if (h2 == 0) h2=12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dA%s %d:%02dA",h1,m1,inject,h2,m2);
        }
    }
    return fmttime;
}
Beispiel #2
0
void
write_proj_change_info (void) 
{
    status_t stat;
    int i;
    uint32_t h, m;
    char string[10];

    DictionaryIterator *iterator;

    app_message_outbox_begin(&iterator);

    for (i = 0 ; i < NUM_PROJECTS ; i++) {
	stat = persist_write_int(proj_time_val[i], (uint32_t)proj_time[i]);
	stat = persist_write_int(proj_run_val[i], (uint32_t)proj_running[i]);
	stat = persist_write_int(proj_start_val[i], (uint32_t)proj_start[i]);
	if (proj_name[i] && *proj_name[i]) {
	    stat = persist_write_string(proj_name_val[i], proj_name[i]);
	    dict_write_cstring(iterator, proj_name_val[i], proj_name[i]);
	} else {
	    stat = persist_write_string(proj_name_val[i], "");
	    dict_write_cstring(iterator, proj_name_val[i], proj_name[i]);
	}
	app_log(APP_LOG_LEVEL_WARNING,
		__FILE__,
		__LINE__,
		"Proj %d time info written as %d:%d", i, hours(proj_time[i]), minutes(proj_time[i]));
	h = (uint32_t)hours(proj_time[i]);
	stat = persist_write_int(proj_hour_val[i], h);
	m = (uint32_t)minutes(proj_time[i]);
	stat = persist_write_int(proj_min_val[i], m);

	snprintf(string, sizeof(string), "%u", (uint)h);
	dict_write_cstring(iterator, proj_hour_val[i], string);

	snprintf(string, sizeof(string), "%u", (uint)m);
	dict_write_cstring(iterator, proj_min_val[i], string);
    }

    app_log(APP_LOG_LEVEL_WARNING,
            __FILE__,
            __LINE__,
            "Writing autostop as %d", (int)autostop);
    stat = persist_write_int(AUTOSTOP, (uint32_t)autostop);
    snprintf(string, sizeof(string), "%u", (uint)autostop);
    dict_write_cstring(iterator, AUTOSTOP, string);

    app_message_outbox_send();

    if (bluetooth_connected == true && stat == 4) {
	proj_change_written = true;
    } else {
	app_log(APP_LOG_LEVEL_WARNING,
		__FILE__,
		__LINE__,
		"Proj time info written");
	proj_change_written = false;
    }
}
Time::operator CString() const
{
#if defined(__BORLANDC__) && !defined(__WIN32__)
	// TODO: get country info under DJGPP & Win32
	COUNTRY	countryInfo;

	country(0, &countryInfo);
#endif

#if defined(__BORLANDC__) && !defined(__WIN32__)
	// TODO: get country info under DJGPP & Win32
	switch (countryInfo.co_time)
#else
	switch (0)
#endif		
		{
		case 1:
			{
			MTrace(("Time=%s", (const char*)sformat("%02i%s%02i", hours(), ":", minutes())));
			return sformat("%02i%s%02i", hours(), ":", minutes());
			}

		case 0:
			{
			if (hours() == 0)
				{
				MTrace(("Time=%s", (const char*)sformat("12%s%02iam", ":", minutes())));
				return sformat("12%s%02iam", ":", minutes());
				}

			if (hours() == 12)
				{
				MTrace(("Time=%s", (const char*)sformat("12%s%02ipm", ":", minutes())));
				return sformat("12%s%02ipm", ":", minutes());
				}

			if (hours() > 12)
				{
				MTrace(("Time=%s", (const char*)sformat("%02i%s%02ipm", hours()-12, ":", minutes())));
				return sformat("%02i%s%02ipm", hours()-12, ":", minutes());
				}

			if (hours() < 12)
				{
				MTrace(("Time=%s", (const char*)sformat("%02i%s%02iam", hours(), ":", minutes())));
				return sformat("%02i%s%02iam", hours(), ":", minutes());
				}
			}
		}

	return CString();
}
// seti_time::utc() returns UTC in hours past midnight.
hours seti_time::utc() const {
  seti_time temp(*this);
  temp.base(UTC);
  double h=fmod(temp.hrs().uval(),24.0);
  if (h<0) h+=24;
  return hours(h);
}
		void prepared_statement_t::_bind_time_parameter(size_t index, const ::sqlpp::chrono::microsecond_point* value, bool is_null) {
			if(_handle->debug) {
				std::cerr << "ODBC debug: binding date_time parameter"
				" at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl;
			}
			SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0);
			SQL_TIME_STRUCT t_value = {0};
			if(!is_null) {
				const auto time = date::make_time(value->time_since_epoch());
				t_value.hour = time.hours().count();
				t_value.minute = time.minutes().count();
				t_value.second = time.seconds().count();
			}
			
			auto rc = SQLBindParameter(_handle->stmt, 
									   index, 
									   SQL_PARAM_INPUT, 
									   SQL_C_TYPE_TIME, 
									   SQL_TYPE_TIME, 
									   8,
									   0, 
									   (SQLPOINTER)&t_value, 
									   sizeof(SQL_DATE_STRUCT), 
									   &indPtr);
			if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				throw sqlpp::exception("ODBC error: couldn't bind date parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT));
			}
		}
		void prepared_statement_t::_bind_date_time_parameter(size_t index, const ::sqlpp::chrono::microsecond_point* value, bool is_null) {
			if(_handle->debug) {
				std::cerr << "ODBC debug: binding date_time parameter"
				" at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl;
			}
			SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0);
			SQL_TIMESTAMP_STRUCT ts_value = {0};
			if(!is_null) {
				const auto dp = ::date::floor<::date::days>(*value);
				const auto time = date::make_time(*value - dp);
				const auto ymd = ::date::year_month_day{dp};
				ts_value.year = static_cast<int>(ymd.year());
				ts_value.month = static_cast<unsigned>(ymd.month());
				ts_value.day = static_cast<unsigned>(ymd.day());
				ts_value.hour = time.hours().count();
				ts_value.minute = time.minutes().count();
				ts_value.second = time.seconds().count();
				ts_value.fraction = time.subseconds().count();
			}
			
			auto rc = SQLBindParameter(_handle->stmt, 
									   index, 
									   SQL_PARAM_INPUT, 
									   SQL_C_TYPE_TIMESTAMP, 
									   SQL_TYPE_TIMESTAMP, 
									   sizeof(SQL_TIMESTAMP_STRUCT),
									   0, 
									   (SQLPOINTER)&ts_value, 
									   sizeof(SQL_DATE_STRUCT), 
									   &indPtr);
			if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				throw sqlpp::exception("ODBC error: couldn't bind date parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT));
			}
		}
Beispiel #7
0
int main()
{
	#if __STDC__ == 1
	printf("This is Ansi C standardized\r\n");
	
	char return_key;
	double start_of_the_timer,end_of_the_timer,time_in_minutes,time_in_hours;
	
	start_of_the_timer = start_timer();
	
	printf("Timer started, press enter to get time since start of program\r\n");
	return_key=getchar();
	
	end_of_the_timer = end_timer(start_of_the_timer);
	printf("%lf was the number of seconds since you pressed enter\r\n",end_of_the_timer);
	
	time_in_minutes = minutes(end_of_the_timer);
	printf("%lf was the number of minutes since being stopped\r\n",time_in_minutes);
	
	time_in_hours = hours(time_in_minutes);
	printf("%lf was the number of hours since being stopped\r\n",time_in_hours);
	
	return 0;
	
	#else
		printf("This is not Ansi C standardized\r\n");
		return 0;
	#endif	
}
Beispiel #8
0
/*
 Still UNTESTED: create Unix like long representing the date/time
 */							
uint32_t RTCCValue::getTimestamp()
{
  int i;
  uint32_t tseconds;

    uint32_t yr = year() + 2000 - 1970;

  // seconds from 1970 till 1 jan 00:00:00 of the given year
  tseconds= yr*(SECS_PER_DAY * 365);
  for (i = 0; i < yr; i++) {
    if (LEAP_YEAR(i)) {
      tseconds +=  SECS_PER_DAY;   // add extra days for leap years
    }
  }

  // add days for this year, months start from 1
  for (i = 1; i < month(); i++) {
    if ( (i == 2) && LEAP_YEAR(yr)) {
      tseconds += SECS_PER_DAY * 29;
    } else {
      tseconds += SECS_PER_DAY * monthDays[i-1];  //monthDay array starts from 0
    }
  }
  tseconds+= (day()-1) * SECS_PER_DAY;
  tseconds+= hours() * SECS_PER_HOUR;
  tseconds+= minutes() * SECS_PER_MIN;
  tseconds+= seconds();
  return tseconds;
}
Beispiel #9
0
void CTime::serialize(CDictionary& toDictionary) const
{
	toDictionary.setValueForKey(cMillisecondsKey, milliseconds());
	toDictionary.setValueForKey(cSecondsKey, seconds());
	toDictionary.setValueForKey(cMinutesKey, minutes());
	toDictionary.setValueForKey(cHoursKey, hours());
}
string Feed::time(){
	time_t message_time(this->timestamp());
	struct tm *particles = gmtime(&message_time);
	ostringstream hour_temp;
	hour_temp << (particles->tm_hour+2)%24;
	string hours(hour_temp.str());
	if (hours.size() == 1){
		hours.insert(0,"0");
	}
	ostringstream min_temp;
	min_temp << particles->tm_min;
	string minutes(min_temp.str());
	if (minutes.size() == 1){
		minutes.insert(0,"0");
	}
	ostringstream sec_temp;
	sec_temp << particles->tm_sec;
	string seconds(sec_temp.str());
	if (seconds.size() == 1){
		seconds.insert(0,"0");
	}
	ostringstream temp;
	temp << "[" << hours << ":" << minutes << ":" << seconds << "]";
	return temp.str();
}
Beispiel #11
0
void UpdateProgThread::calcResults()
{
	if (isPaused())
		return;

	uint64 done = 0;
	gcTime curTime;

	auto elasped = curTime - m_tStartTime;

	//only go fowards if total time elasped is greater than a second
	if (elasped.seconds() == 0)
		return;

	{
		std::lock_guard<std::mutex> guard(m_pProgMutex);

		for (size_t x=0; x<m_vProgInfo.size(); x++)
			done += m_vProgInfo[x];
	}
	

	if (done == 0)
		return;

	MCFCore::Misc::ProgressInfo temp = MCFCore::Misc::ProgressInfo();

	temp.doneAmmount = done+m_uiDoneSize;
	temp.totalAmmount = m_uiTotalSize;
	temp.percent = (uint8)(((done+m_uiDoneSize)*100)/m_uiTotalSize);

	auto diff = curTime - m_tLastUpdateTime;

	if (temp.doneAmmount >= temp.totalAmmount)
	{
		temp.doneAmmount = temp.totalAmmount;
	}
	else if (diff.seconds() < 5)
	{
		auto total = curTime - m_tStartTime;
		total -= m_tTotPauseTime;

		double avgRate	= done / (double)total.seconds();
		uint64 pred		= (uint64)((m_uiTotalSize - done - m_uiDoneSize) / avgRate);
		
		auto predTime = gcDuration(std::chrono::seconds((long)pred));

		temp.hour	= (uint8)predTime.hours();
		temp.min	= (uint8)predTime.minutes();
		temp.rate	= (uint32)avgRate;
	}
	else
	{
		temp.hour	= (uint8)-1;
		temp.min	= (uint8)-1;
	}

	onProgUpdateEvent(temp);
}
Beispiel #12
0
void TestStockTime::test1()
{

  date d(2002,Feb,1); //an arbitrary date

  //construct a time by adding up some durations durations
  StockTime t1(d, hours(5)+minutes(4)+seconds(2)+millisec(1));

  //construct a new time by subtracting some times
  StockTime t2 = t1 - hours(5)- minutes(4)- seconds(2)- millisec(1);

  //construct a duration by taking the difference between times
  time_duration td = t2 - t1;
    
  std::cout << to_simple_string(t2) << " - " 
         << to_simple_string(t1) << " = "
         << to_simple_string(td) << std::endl;

}
Beispiel #13
0
static void SaveStatistics(const char *fn, TArray<FStatistics> &statlist)
{
	unsigned int j;

	FILE * f = fopen(fn, "wt");
	if (f==NULL) return;

	qsort(&statlist[0], statlist.Size(), sizeof(statlist[0]), compare_episode_names);
	for(unsigned i=0;i<statlist.Size ();i++)
	{
		FStatistics &ep_stats = statlist[i];

		qsort(&ep_stats.stats[0], ep_stats.stats.Size(), sizeof(ep_stats.stats[0]), compare_dates);

		fprintf(f, "%s \"%s\"\n{\n", ep_stats.epi_header.GetChars(), ep_stats.epi_name.GetChars());
		for(j=0;j<ep_stats.stats.Size();j++)
		{
			FSessionStatistics *sst = &ep_stats.stats[j];
			if (sst->info[0]>0)
			{
				fprintf(f,"\t%2i. %10s \"%-22s\" %02d:%02d:%02d %i\n", j+1, sst->name, sst->info, 
					hours(sst->timeneeded),	minutes(sst->timeneeded), seconds(sst->timeneeded),	sst->skill);

				TArray<FLevelStatistics> &ls = sst->levelstats;
				if (ls.Size() > 0)
				{
					fprintf(f,"\t{\n");

					qsort(&ls[0], ls.Size(), sizeof(ls[0]), compare_level_names);

					for(unsigned k=0;k<ls.Size ();k++)
					{
						fprintf(f, "\t\t%-8s \"%-22s\" %02d:%02d:%02d\n", ls[k].name, ls[k].info, 
							hours(ls[k].timeneeded), minutes(ls[k].timeneeded), seconds(ls[k].timeneeded));
					}
					fprintf(f,"\t}\n");
				}
			}
		}
		fprintf(f,"}\n\n");
	}
	fclose(f);
}
string get_time_string_s_file()
{
	auto tm = boost::posix_time::microsec_clock::local_time();
	auto date = tm.date();
	auto time = tm.time_of_day();
	char buff[32];
	sprintf_s(buff, "%u-%02u-%02u %02u.%02u.%02u", (int)date.year(), (int)date.month(), (int)date.day(), \
		(int)time.hours(), (int)time.minutes(), (int)time.seconds());
	return buff;
}
Beispiel #15
0
bool RTCCValue::valid()
{
   char ayear  = year();
   char amonth = month();
   char aday   = day();
   char ahour  = hours();
   char amin   = minutes();
   char asec   = seconds();
   return (ayear >= 0 && ayear <= 99 && amonth >= 1 && amonth <= 12 && aday >= 1 && aday <= 31
           && ahour >= 0 && ahour <= 23 && amin >= 0 && amin <= 59 && asec >= 0 && asec <= 59 );
}
Beispiel #16
0
void Ut::observatory(int index)
{
qDebug() << "observatory" << index;
	QString line(obss[base + index]);
qDebug() << line;
	QStringList row = line.split('\t');
	timezone = row[13].toInt();
	longitude = hours(row[13].left(row[13].indexOf(' ')).toInt(), 
			row[13].mid(row[13].indexOf(' ')).toDouble(), 0);
	ui.lon->setText(row[12] + "; " + row[13]);
}
Beispiel #17
0
std::string TimeSpan::str() const
{
	int totalMinutes =
		days() * 24 * 60 +
		hours() * 60 +
		minutes();

	Buffer b(64);
	b << totalMinutes << "m " << seconds() << "s";
	return b.str();
}
Beispiel #18
0
    bool
  parseDateRFC850(const QStringList & l, QDateTime & dt)
  {
    if ("GMT" != l[3])
      return false;

    QStringList dateTokenList(QStringList::split('-', l[1]));

    if (3 != dateTokenList.count())
      return false;

    uint day(dateTokenList[0].toUInt());

    bool haveMonth = false;
    uint month = 0;

    QStringList::ConstIterator it;

    for (it = monthList.begin(); it != monthList.end(); ++it)
    {
      if (*it == dateTokenList[1])
      {
        haveMonth = true;
        break;
      }

      ++month;
    }

    if (!haveMonth)
      return false;

    uint year(dateTokenList[2].toUInt());

    if (year < 50)
      year += 2000;
    else if (year < 100)
      year += 1900;

    QStringList timeTokenList(QStringList::split(':', l[2]));

    if (3 != timeTokenList.count())
      return false;

    uint hours    (timeTokenList[0].toUInt());
    uint minutes  (timeTokenList[1].toUInt());
    uint seconds  (timeTokenList[2].toUInt());

    dt.setDate(QDate(year, month + 1, day));
    dt.setTime(QTime(hours, minutes, seconds));

    return dt.isValid();
  }
Beispiel #19
0
// NOT IMPLEMENTED BUT WOULD BE NICE !
void RTCCValue::setTimestamp(uint32_t unixTime) {
// break the given time_t into time components
// this is a more compact version of the C library localtime function
// note that year is offset from 1970 !!!

  uint8_t _year;
  uint8_t _month, _monthLength;
  uint32_t _time;
  unsigned long _days;

  _time = (uint32_t)unixTime;
  seconds(_time % 60);
  _time /= 60; // now it is minutes
  minutes(_time % 60);
  _time /= 60; // now it is hours
  hours(_time % 24);
  _time /= 24; // now it is days
  dayOfWeek(((_time + 4) % 7) + 1);  // Sunday is day 1

  _year = 0;
  _days = 0;
  while((unsigned)(_days += (LEAP_YEAR(_year) ? 366 : 365)) <= _time) {
    _year++;
  }
  year((1970 + _year) % 100); // year is offset from 1970

  _days -= LEAP_YEAR(_year) ? 366 : 365;
  _time  -= _days; // now it is days in this year, starting at 0

  _days=0;
  _month=0;
  _monthLength=0;
  for (_month=0; _month<12; _month++) {
    if (_month==1) { // february
      if (LEAP_YEAR(_year)) {
        _monthLength=29;
      } else {
        _monthLength=28;
      }
    } else {
      _monthLength = monthDays[_month];
    }

    if (_time >= _monthLength) {
      _time -= _monthLength;
    } else {
        break;
    }
  }
  month(_month + 1);  // jan is month 1
  day(_time + 1);     // day of month

}
Beispiel #20
0
/*
  Set a date/time using an UNSIGNED integer in 32 bits (NOT Unix date/time representation)
 */
uint32_t RTCCValue::getInt() {
   char ayear  = year();
   char amonth = month();
   char aday   = day();
   char ahour  = hours();
   char amin   = minutes();
   char asec   = seconds();
   if (ayear >= 0 && ayear <= 99 && amonth >= 1 && amonth <= 12 && aday >= 1 && aday <= 31
       && ahour >= 0 && ahour <= 23 && amin >= 0 && amin <= 59 && asec >= 0 && asec <= 59 ) {
	return (uint32_t)asec+((uint32_t)amin*60)+((uint32_t)ahour*3600)+(((uint32_t)aday-1)*3600*24)+(((uint32_t)amonth-1)*3600*24*31)+((uint32_t)ayear*3600*24*31*12);
   } else return 0;
}
Beispiel #21
0
int main(void) {
	int n, i, j, k, m, x, y, z;
	int a, b, c, d;
	double h, g, t;
	char first[MAX_LEN], last[MAX_LEN];
	
	FILE *ifp, *ofp;
	ifp = fopen("clock.txt", "r");
	ofp = fopen("w2.txt", "w");
	fscanf(ifp, "%d", &n);
	
	struct employee prof[CONST];
	
	for (i=0; i<n; i++){
		fscanf(ifp, "%s %s %lf", prof[i].first, prof[i].last, &prof[i].payperhr);
    }
	fscanf(ifp, "%d", &k);
	
	for (i=0; i<k; i++) {
		for (x=0; x<n; x++)
				prof[x].hours_in_week = 0;
		fscanf(ifp, "%d", &m);
		for (y=0; y<m; y++) {
			fscanf(ifp, "%s %s", last, first);
			fscanf(ifp, "%d %d %d %d", &a, &b, &c, &d);
			h = hours(a, b, c, d);
			for (j=0; j<n; j++) {
				if(strcmp( first, prof[j].first) == 0 && strcmp( last, prof[j].last) == 0)
					prof[j].hours_in_week += h;
			}
		}
		for (z=0; z<n; z++) {
			g = gross(prof[z].hours_in_week, prof[z].payperhr);
			prof[z].gross += g;
			t = taxes(prof[z].hours_in_week, prof[z].payperhr);
			prof[z].taxes += t;
		}
	}

	fprintf(ofp, "Number of employees: %d\n\n", n);
	for (i=0; i<n; i++){
		fprintf(ofp, "W2 Form \n-------\n");
		fprintf(ofp, "Name: %s %s \n", prof[i].first, prof[i].last);
		fprintf(ofp, "Gross Pay: %.2lf \n", prof[i].gross);
		fprintf(ofp, "Taxes Withheld: %.2lf\n", prof[i].taxes);
		fprintf(ofp, "Internet Pay: %.2lf\n", (prof[i].gross - prof[i].taxes));
	
	}
	fclose(ifp);
	fclose(ofp);
	return 0;
}
Beispiel #22
0
	tstring GetFullTimeStringFromSecondsValue(UINT seconds)
	{
		tstringstream time;
		UINT minutes(seconds / 60);
		UINT hours(minutes / 60);
		minutes = minutes % 60;
		seconds = seconds % 60;
		time << ( hours < 10 ? _T("0") : _T("") ) << hours;
		time << _T(":");
		time << ( minutes < 10 ? _T("0") : _T("") ) << minutes;
		time << _T(":");
		time << ( seconds < 10 ? _T("0") : _T("") ) << seconds;
		return time.str();
	}
Beispiel #23
0
// OK
double Ut::ST2UT(QDateTime q)
{
     double du  = q.date().toJulianDay() - 2451545;
qDebug() << "JD= " << QString::number(du + 2451545, 'g', 16);
     double T = du/36525;
     double GMST1 = 24110.54841 + T*(8640184.812866 + 0.093104*T - 6.2e-6*T*T);
     double LST = hours(q.time().hour(), q.time().minute(), q.time().second());
     double UT = LST - GMST1/3600.0 - longitude/15;
qDebug() << "UT=" << UT << longitude;
     UT = UT/24;
qDebug() << "UT/24" << UT;
     UT= 24*(UT - int(UT));
qDebug() << "UT=" << UT;
     return UT;           
}
Beispiel #24
0
void append_timestamp(Stream& stream, boost::posix_time::ptime timestamp)
{
    auto date         = timestamp.date();
    auto time         = timestamp.time_of_day();
    auto milliseconds = time.fractional_seconds() / 1000; // microseconds to milliseconds

    std::wstringstream buffer;

    buffer << std::setfill(L'0') << L"[" << std::setw(4) << date.year() << L"-" << std::setw(2)
           << date.month().as_number() << "-" << std::setw(2) << date.day().as_number() << L" " << std::setw(2)
           << time.hours() << L":" << std::setw(2) << time.minutes() << L":" << std::setw(2) << time.seconds() << L"."
           << std::setw(3) << milliseconds << L"] ";

    stream << buffer.str();
}
Beispiel #25
0
void
delete_old_lostitems(void)
{
    time_t expiry_time = time(NULL) - hours(lost_keep_hours);
    struct loststr lost;
    int i;

    for (i = 0; getlost(i, &lost); i++) {
        if (!lost.lost_owner)
            continue;
        if (lost.lost_timestamp >= expiry_time)
            continue;
        lost.lost_owner = 0;
        putlost(i, &lost);
    }
}
ptime StreamData::GetDateTime(std::string s)
{
	// parse 2012-02-03T17:31:51.0968Z 
	int Year, Month, Day, Hour, Minute, Second, Millisecond;
	if(sscanf(s.c_str(), "%d-%d-%dT%d:%d:%d.%d", &Year, &Month, &Day, &Hour, &Minute,&Second, &Millisecond)==7){}
	//12/2/2009 2:42:25 PM
	else if(sscanf(s.c_str(), "%d/%d/%4d%d:%d:%d", &Month, &Day, &Year,  &Hour, &Minute,&Second)==6){}
	else throw std::exception("Unrecognized date-time format\n");

	return ptime( date(Year,Month,Day),
		hours(Hour)  +
		minutes(Minute) +
		seconds(Second) +
		boost::posix_time::millisec(int(Millisecond)) );

	//return COleDateTime( Year, Month, Day, Hour, Minute, Second ); 
}
Beispiel #27
0
//If 12 hour time, subtract 12 from hr if hr > 12
char* thr(float time, char ap)
{
    static char fmttime[] = "00:00A";
    int h = hours(time);
    int m = mins(time);
    if (clock_is_24h_style()) {
        mini_snprintf(fmttime, sizeof(fmttime), "%d:%02d",h,m);
    } else {
        if (h > 11) {
            if (h > 12) h -= 12;
            mini_snprintf(fmttime, sizeof(fmttime), (ap==1)?"%d:%02dP":"%d:%02d",h,m);
        } else {
			if (h == 0) h=12;
            mini_snprintf(fmttime, sizeof(fmttime), (ap==1)?"%d:%02dA":"%d:%02d",h,m);
        }
    }
    return fmttime;
}
CString Time::longCString() const
{
#if defined(__BORLANDC__) && !defined(__WIN32__)
	// TODO: get country info under DJGPP & Win32
	COUNTRY	countryInfo;

	country(0, &countryInfo);
#endif

#if defined(__BORLANDC__) && !defined(__WIN32__)
	// TODO: get country info under DJGPP & Win32
	switch (countryInfo.co_time)
#else	
	switch (0)
#endif
		{
		case 1:
			return sformat("%02i%s%02i%s%02i", hours(), ":", minutes(), ":", seconds());

		case 0:
			{
			if (hours() == 0)
				{
				return sformat("12%s%02i%s%02iam", ":", minutes(), ":", seconds());
				}

			if (hours() == 12)
				{
				return sformat("12%s%02i%s%02ipm", ":", minutes(), ":", seconds());
				}

			if (hours() > 12)
				{
				return sformat("%02i%s%02i%s%02ipm", hours()-12, ":", minutes(), ":", seconds());
				}

			if (hours() < 12)
				{
				return sformat("%02i%s%02i%s%02iam", hours(), ":", minutes(), ":", seconds());
				}
			}
		}

	return CString();
}
Beispiel #29
0
int main()
{
	char return_key;
	double start_of_the_timer,end_of_the_timer,time_in_minutes,time_in_hours;
	
	start_of_the_timer = start_timer();
	
	printf("Timer started, press enter to get time since start of program\r\n");
	return_key=getchar();
	
	end_of_the_timer = end_timer(start_of_the_timer);
	printf("%lf was the number of seconds since you pressed enter\r\n",end_of_the_timer);
	
	time_in_minutes = minutes(end_of_the_timer);
	printf("%lf was the number of minutes since being stopped\r\n",time_in_minutes);
	
	time_in_hours = hours(time_in_minutes);
	printf("%lf was the number of hours since being stopped\r\n",time_in_hours);
	
	return 0;
}
Beispiel #30
0
int confOption::setValueFromFile(QString line)
{
  // Used to set values in confOptions from a file line
  
  QString rval = line.section("=",1).trimmed();

  qDebug() << "setting " << realName << " to " << rval << " (from file)";
    
  if (type == BOOL)
  {
    if (rval == "true" || rval == "on" || rval == "yes")
    {
      value = true;
      return 0;
    }
    else if (rval == "false" || rval == "off" || rval == "no")
    {
      value = false;
      return 0;
    }
    qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring...";
    return -1;
  }

  else if (type == INTEGER)
  {
    bool ok;
    qlonglong rvalToNmbr = rval.toLongLong(&ok);
    if (ok && rvalToNmbr >= minVal && rvalToNmbr <= maxVal)
    {
      value = rvalToNmbr;
      return 0;
    }
    qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring...";
    return -1;
  }

  else if (type == STRING)
  {
    value = rval;
    return 0;
  }  
  
  else if (type == LIST)
  {
    if (realName == "ShowStatus") // ShowStatus needs special treatment
    {
      if (rval.toLower() == "true" || rval.toLower() == "on")
        rval = "yes";
      else if (rval.toLower() == "false" || rval.toLower() == "off")
        rval = "no";
    }
    if (possibleVals.contains(rval))
    {
      value = rval.toLower();
      return 0;
    }
    qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring...";
    value = defVal;
    return -1;
  }

  else if (type == MULTILIST)
  {
    QVariantMap map;

    QStringList readList = rval.split(" ", QString::SkipEmptyParts);
    for (int i = 0; i < readList.size(); ++i)
    {
      if (!possibleVals.contains(readList.at(i)))
      {
        qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring...";
        return -1;
      }
    }
    
    for (int i = 0; i < possibleVals.size(); ++i)
    {
      if (readList.contains(possibleVals.at(i)))
        map[possibleVals.at(i)] = true;
      else
        map[possibleVals.at(i)] = false;
    }

    value = map;
    return 0;

  }  
  
  else if (type == TIME)
  {
    int pos = 0;
    QRegExp rxValid;

    // These regex check whether rval is a valid time interval
    if (hasNsec)
      rxValid = QRegExp("^(?:\\d*\\.?\\d *(ns|nsec|us|usec|ms|msec|s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|w|week|weeks|month|months|y|year|years)? *)+$");
    else
      rxValid = QRegExp("^(?:\\d*\\.?\\d *(us|usec|ms|msec|s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|w|week|weeks|month|months|y|year|years)? *)+$");

    pos = rxValid.indexIn(rval);

    if (pos > -1)
    {
      pos = 0;
      seconds secs(0);

      // This regex parses individual elements of the time interval
      QRegExp rxTimeParse = QRegExp("(\\d*\\.?\\d+) *([a-z]*)");

      while ((pos = rxTimeParse.indexIn(rval, pos)) != -1)
      {
        if (rxTimeParse.cap(2) == "ns" ||
            rxTimeParse.cap(2) == "nsec" )
        {
          nanoseconds ns(rxTimeParse.cap(1).trimmed().toDouble());
          secs += ns;
        }
        else if (rxTimeParse.cap(2) == "us" ||
            rxTimeParse.cap(2) == "usec" )
        {
          microseconds us(rxTimeParse.cap(1).trimmed().toDouble());
          secs += us;
        }
        else if (rxTimeParse.cap(2) == "ms" ||
            rxTimeParse.cap(2) == "msec" )
        {
          milliseconds ms(rxTimeParse.cap(1).trimmed().toDouble());
          secs += ms;
        }
        else if (rxTimeParse.cap(2) == "s" ||
                 rxTimeParse.cap(2) == "sec" ||
                 rxTimeParse.cap(2) == "second" ||
                 rxTimeParse.cap(2) == "seconds" )
        {
          seconds s(rxTimeParse.cap(1).trimmed().toDouble());
          secs += s;
        }
        else if (rxTimeParse.cap(2) == "m" ||
                 rxTimeParse.cap(2) == "min" ||
                 rxTimeParse.cap(2) == "minute" ||
                 rxTimeParse.cap(2) == "minutes" )
        {
          minutes min(rxTimeParse.cap(1).trimmed().toDouble());
          secs += min;
        }
        else if (rxTimeParse.cap(2) == "h" ||
                 rxTimeParse.cap(2) == "hr" ||
                 rxTimeParse.cap(2) == "hour" ||
                 rxTimeParse.cap(2) == "hours" )
        {
          hours hr(rxTimeParse.cap(1).trimmed().toDouble());
          secs += hr;
        }
        else if (rxTimeParse.cap(2) == "d" ||
                 rxTimeParse.cap(2) == "day" ||
                 rxTimeParse.cap(2) == "days")
        {
          days dy(rxTimeParse.cap(1).trimmed().toDouble());
          secs += dy;
        }
        else if (rxTimeParse.cap(2) == "w" ||
                 rxTimeParse.cap(2) == "week" ||
                 rxTimeParse.cap(2) == "weeks")
        {
          weeks w(rxTimeParse.cap(1).trimmed().toDouble());
          secs += w;
        }
        else if (rxTimeParse.cap(2) == "month" ||
                 rxTimeParse.cap(2) == "months")
        {
          months m(rxTimeParse.cap(1).trimmed().toDouble());
          secs += m;
        }
        else if (rxTimeParse.cap(2) == "y" ||
                 rxTimeParse.cap(2) == "year" ||
                 rxTimeParse.cap(2) == "years")
        {
          years y(rxTimeParse.cap(1).trimmed().toDouble());
          secs += y;
        }

        else if (rxTimeParse.cap(2).isEmpty())
        {
          // unitless number, convert it from defReadUnit to seconds
          seconds tmpSeconds(convertTimeUnit(rxTimeParse.cap(1).trimmed().toDouble(), defReadUnit, timeUnit::s).toDouble());
          secs += tmpSeconds;
        }

        pos += rxTimeParse.matchedLength();
      }

      // Convert the read value in seconds to defUnit
      if (defUnit == ns)
        value = nanoseconds(secs).count();
      else if (defUnit == us)
        value = microseconds(secs).count();
      else if (defUnit == ms)
        value = milliseconds(secs).count();
      else if (defUnit == s)
        value = secs.count();
      else if (defUnit == min)
        value = minutes(secs).count();
      else if (defUnit == h)
        value = hours(secs).count();
      else if (defUnit == d)
        value = days(secs).count();
      else if (defUnit == w)
        value = weeks(secs).count();
      else if (defUnit == month)
        value = months(secs).count();
      else if (defUnit == year)
        value = years(secs).count();

      value = value.toULongLong(); // Convert to ulonglong (we don't support float in ui)
      return 0;

    }
    else
    {
      qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring...";
      return -1;
    }
  }
  
  else if (type == RESLIMIT)
  {
    bool ok;
    int nmbr = rval.toUInt(&ok);
    if (ok)
    {
      value = nmbr;
      return 0;
    }
    else if (rval.toLower().trimmed() == "infinity" || rval.trimmed().isEmpty())
    {
      value = -1;
      return 0;
    }
    qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring...";
    return -1;
    
  }
  
  else if (type == SIZE)
  {
    // RegExp to match a number (possibly with decimals) followed by a size unit (or no unit for byte)
    QRegExp rxSize = QRegExp("(\\b\\d+\\.?\\d*(K|M|G|T|P|E)?\\b)");
    
    int pos = 0;
    pos = rxSize.indexIn(rval);
    if (pos > -1 && rxSize.cap(0) == rval.trimmed())
    {
      // convert the specified size unit to megabytes
      if (rxSize.cap(0).contains("K"))
        value = rxSize.cap(0).remove("K").toDouble() / 1024;
      else if (rxSize.cap(0).contains("M"))
        value = rxSize.cap(0).remove("M").toDouble();
      else if (rxSize.cap(0).contains("G"))
        value = rxSize.cap(0).remove("G").toDouble() * 1024;
      else if (rxSize.cap(0).contains("T"))
        value = rxSize.cap(0).remove("T").toDouble() * 1024 * 1024;
      else if (rxSize.cap(0).contains("P"))
        value = rxSize.cap(0).remove("P").toDouble() * 1024 * 1024 * 1024;
      else if (rxSize.cap(0).contains("E"))
        value = rxSize.cap(0).remove("E").toDouble() * 1024 * 1024 * 1024 * 1024;
      else
        value = rxSize.cap(0).toDouble() / 1024 / 1024;
      
      // Convert from double to ulonglong (we don't support float in ui)
      value = value.toULongLong();
      return 0;
    }
    else
    {
      qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring...";
      return -1;
    }
   
  }
  return -1;
}