Exemplo n.º 1
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;
    }
}
Exemplo n.º 2
0
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();
}
Exemplo n.º 3
0
EngineState::EngineState(unique_ptr<TranspositionTable> transposition_table,
                         unique_ptr<PawnTable> pawn_table,
                         unique_ptr<EgbbProber> eggb_prober,
                         BoardState* const board_state):
  m_transposition_table(move(transposition_table)),
  m_pawn_table(move(pawn_table)),
  m_egbb_prober(move(eggb_prober)),
  m_board_state(board_state),
  m_my_time(minutes(5)),
  m_opponent_time(minutes(5)),
  m_increment(0)
{
  assert(board_state);
}
Exemplo n.º 4
0
	// returns true if our external IP changed
	bool ip_voter::maybe_rotate()
	{
		time_point now = aux::time_now();

		// if we have more than or equal to 50 votes,
		// we rotate. Also, if it's been more than 5 minutes
		// and we have at least one vote, we also rotate.
		// this is the inverse condition, since this is the case
		// were we exit, without rotating
		if (m_total_votes < 50
			&& (now - m_last_rotate < minutes(5) || m_total_votes == 0))
			return false;

		// this shouldn't really happen if we have at least one
		// vote.
		if (m_external_addresses.empty()) return false;

		// rotate
		std::vector<external_ip_t>::iterator i = std::max_element(
			m_external_addresses.begin(), m_external_addresses.end());
		TORRENT_ASSERT(i != m_external_addresses.end());

		bool ret = m_external_address != i->addr;
		m_external_address = i->addr;

		m_external_address_voters.clear();
		m_total_votes = 0;
		m_external_addresses.clear();
		m_last_rotate = now;
		m_valid_external = true;
		return ret;
	}
Exemplo n.º 5
0
		void StopAreaTransferAddAction::_setFromParametersMap(const ParametersMap& map)
		{
			try
			{
				_from = StopPointTableSync::Get(map.get<RegistryKeyType>(PARAMETER_FROM_ID), *_env);
			}
			catch(ObjectNotFoundException<StopPoint>&)
			{
				throw ActionException("No such from stop point");
			}

			try
			{
				_to = StopPointTableSync::Get(map.get<RegistryKeyType>(PARAMETER_TO_ID), *_env);
			}
			catch(ObjectNotFoundException<StopPoint>&)
			{
				throw ActionException("No such to stop point");
			}

			if(_from->getConnectionPlace() != _to->getConnectionPlace())
			{
				throw ActionException("Internal transfers must concern two stops within the same stop area.");
			}

			if(map.get<string>(PARAMETER_DURATION) != StopAreaTableSync::FORBIDDEN_DELAY_SYMBOL)
			{
				_duration = minutes(map.get<long>(PARAMETER_DURATION));
			}
		}
		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 ContinuousServiceUpdateAction::_setFromParametersMap(const ParametersMap& map)
		{
			try
			{
				_service = ContinuousServiceTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_SERVICE_ID), *_env);
			}
			catch(ObjectNotFoundException<ContinuousService>&)
			{
				throw ActionException("No such service");
			}

			_duration = minutes(map.get<int>(PARAMETER_WAITING_DURATION));

			time_duration endTime(not_a_date_time);
			if(!map.getDefault<string>(PARAMETER_END_TIME).empty())
			{
				try
				{
					endTime = duration_from_string(map.get<string>(PARAMETER_END_TIME));
				}
				catch(bad_lexical_cast)
				{
					throw ActionException("Bad end time");
				}
			}


			time_duration startTime(_service->getDepartureSchedule(false, 0));

			_range = endTime - startTime;
		}
		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));
			}
		}
Exemplo n.º 9
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	
}
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();
}
Exemplo n.º 11
0
void CTime::serialize(CDictionary& toDictionary) const
{
	toDictionary.setValueForKey(cMillisecondsKey, milliseconds());
	toDictionary.setValueForKey(cSecondsKey, seconds());
	toDictionary.setValueForKey(cMinutesKey, minutes());
	toDictionary.setValueForKey(cHoursKey, hours());
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
0
void TimeSelector::setChecked(bool on)
{
	if (on != mSelect->isChecked())
	{
		mSelect->setChecked(on);
		emit valueChanged(minutes());
	}
}
Exemplo n.º 15
0
QDomElement RecipeIngredient::toXml(QDomDocument document)
{
    QDomElement element = document.createElement("RecipeIngredient");
    element.appendChild(ingredient()->toXml(document));
    element.appendChild(quantity().toXml(document));
    element.setAttribute("minutes", minutes());
    return element;
}
Exemplo n.º 16
0
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();
}
Exemplo n.º 17
0
void JunctionUpdateAction::_setFromParametersMap(const ParametersMap& map)
{
    if(map.isDefined(PARAMETER_JUNCTION_ID))
    {
        try
        {
            _junction = JunctionTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_JUNCTION_ID), *_env);
        }
        catch (ObjectNotFoundException<Junction>&)
        {
            throw ActionException("No such junction");
        }
    }
    else
    {
        _junction = boost::shared_ptr<Junction>(new Junction);
    }

    if(map.isDefined(PARAMETER_FROM_ID))
    {
        try
        {
            _from = StopPointTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_FROM_ID), *_env);
        }
        catch(ObjectNotFoundException<StopPoint>&)
        {
            throw ActionException("No such from stop point");
        }
    }

    if(map.isDefined(PARAMETER_TO_ID))
    {
        try
        {
            _to = StopPointTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_TO_ID), *_env);
        }
        catch(ObjectNotFoundException<StopPoint>&)
        {
            throw ActionException("No such to stop point");
        }
    }

    if(map.isDefined(PARAMETER_LENGTH))
    {
        _length = map.get<double>(PARAMETER_LENGTH);
    }

    if(map.isDefined(PARAMETER_TIME))
    {
        _duration = minutes(map.get<long>(PARAMETER_TIME));
    }

    if(map.isDefined(PARAMETER_BIDIRECTIONAL))
    {
        _bidirectional = map.getDefault<bool>(PARAMETER_BIDIRECTIONAL);
    }
}
Exemplo n.º 18
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;

}
Exemplo n.º 19
0
/******************************************************************************
*  Called when the TimeSelector checkbox is toggled.
*/
void TimeSelector::selectToggled(bool on)
{
	mPeriod->setEnabled(on);
	if (mLabel)
		mLabel->setEnabled(on);
	if (on)
		mPeriod->setFocus();
	emit toggled(on);
	emit valueChanged(minutes());
}
Exemplo n.º 20
0
time_t
player_io_deadline(struct player *pl, int write)
{
    if (pl->may_sleep < (write ? PLAYER_SLEEP_FREELY : PLAYER_SLEEP_ON_INPUT))
	return 0;
    if (pl->state != PS_PLAYING)
	return pl->curup + login_grace_time;
    return pl->curup
	+ minutes(pl->nstat & NONVIS ? max_idle: max_idle_visitor);
}
Exemplo n.º 21
0
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;
}
Exemplo n.º 22
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);
}
Exemplo n.º 23
0
	tstring GetTimeStringFromSecondsValue(UINT seconds)
	{
		tstringstream time;
		UINT minutes(seconds / 60);
		seconds = seconds % 60;
		time << ( minutes < 10 ? _T("0") : _T("") ) << minutes;
		time << _T(":");
		time << ( seconds < 10 ? _T("0") : _T("") ) << seconds;
		return time.str();
	}
Exemplo n.º 24
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();
}
Exemplo n.º 25
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 );
}
Exemplo n.º 26
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

}
Exemplo n.º 27
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;
}
Exemplo n.º 28
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();
  }
Exemplo n.º 29
0
inline EPlaceState PlaceStateCheck(string const & openingHours, time_t timestamp)
{
  OSMTimeRange oh(openingHours);
  auto future = system_clock::from_time_t(timestamp);
  future += minutes(15);
  size_t nowState = oh(timestamp).IsOpen() ? 0 : 1;
  size_t futureState = oh(system_clock::to_time_t(future)).IsOpen() ? 0 : 1;

  EPlaceState state[2][2] = {{EPlaceState::Open, EPlaceState::CloseSoon},
                             {EPlaceState::OpenSoon, EPlaceState::Closed}};

  return state[nowState][futureState];
}
		void GenerateContinuousServiceAction::_setFromParametersMap(const ParametersMap& map)
		{
			try
			{
				_line = CommercialLineTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_LINE), *_env);
			}
			catch(ObjectNotFoundException<CommercialLine>&)
			{
				throw ActionException("No such line");
			}

			_waitingTime = minutes(map.get<int>(PARAMETER_WAITING_TIME));
			_minNumber = map.get<size_t>(PARAMETER_MIN_NUMBER);
		}