예제 #1
0
파일: Unit.cpp 프로젝트: BRAT-DEV/main
//----------------------------------------
bool CUnit::HasDateRef(CDate* dateRef /*= NULL*/, CStringArray* array /*= NULL*/) const
{
  if (!IsDate())
  {
    return false;
  }

  CStringArray ar;

  ar.ExtractStrings(GetText().c_str(), ' ');

  size_t len = ar.size();


  if (len <= 2)
  {
    return false;
  }

  int32_t index = ar.FindIndex("since");

  if (index < 0)
  {
    return false;
  }

  CDate dateTmp;

  int32_t result = BRATHL_ERROR;
  std::string strDate;

  for (uint32_t i = index + 1 ; i < ar.size() ; i++)
  {
    strDate.append(ar.at(i));
    strDate.append(" ");

  }

  strDate = CTools::StringTrim(strDate);
  
  result = dateTmp.SetDate(strDate.c_str());

  if (result == BRATHL_SUCCESS)
  {
    if (dateRef != NULL)
    {
      *dateRef = dateTmp;
    }
  }
  
  if (array != NULL)
  {
    array->Insert(ar);
  }

  return (result == BRATHL_SUCCESS);
}
예제 #2
0
CDate CDate::Now()
{
	CDate ret;
	time_t  v;
	time(&v);

	struct tm* t = localtime(&v);

	ret.SetDate(t->tm_year, t->tm_mon, t->tm_mday);
	return ret;
}
예제 #3
0
bool CDate::Parse(const core::string& str, CDate &tm)
{

	std::vector<core::string> tmpArray = core::StringUtil::Split(str, mT("/"));
	if (tmpArray.size() == 3)
	{
		int d = 0, m = 0, y = 0;
		d = core::StringConverter::toInt(tmpArray[0]);
		m = core::StringConverter::toInt(tmpArray[1]);
		y = core::StringConverter::toInt(tmpArray[2]);

		tm.SetDate(y, m, d);
		return true;
	}
	return false;
}
int main()
{
#ifdef __MSVC_DEBUG__
  InitLeakTest();
#endif

  CDate cdate;

  cout << "Enter a date: " << "\n";
  cin >> cdate;

  cout << "\n";
  cout << "Testing overloaded << operator..." << "\n";
  cout << "You Entered: " << cdate << "\n";

  cout << "\n";
  cout << "Testing c_str() function..." << "\n";
  char *buf = cdate.c_str();
  cout << "You Entered: " << buf << "\n";
  delete buf; // Free the memory allocated for the string

  cout << "\n";
  char sbuf[255];
  cout << "Enter a date string MM/DD/YYYY: ";
  cin >> sbuf;
  
  if(!cin) { 
    cout << "Bad input string" << "\n";
  }
  else {
    if(!cdate.SetDate(sbuf)) {
      cout << "Bad input value" << "\n";
    }
    else {
      buf = cdate.c_str();
      cout << "You Entered: " << buf << "\n";
      delete buf; // Free the memory allocated for the string
    }
  }

  return 0;
}
예제 #5
0
파일: ProductErs.cpp 프로젝트: adakite/main
//----------------------------------------
void CProductErs::ComputeHighResolutionFields(CDataSet* dataSet, double deltaLat, double deltaLon)
{
  // Save current recordset pointer
  CRecordSet* currentRecordSetOld = dataSet->GetCurrentRecordSet();

  //dataSet->SetCurrentRecordSet(dataSet->GetFirstRecordSet());

  CFieldSetDbl *fieldSetLat = NULL;
  CFieldSetDbl *fieldSetLon = NULL;
  CFieldSetDbl *fieldSetTimeStampSecond = NULL;
  CFieldSetDbl *fieldSetTimeStampMicrosecond = NULL;

  int32_t count = dataSet->size();

  for (int32_t index = 0 ; index < count ; index++)
  {
    dataSet->SetCurrentRecordSet(index);

    fieldSetLat = dataSet->GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_latitudeFieldName) );
    fieldSetLon = dataSet->GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_longitudeFieldName) );
    fieldSetTimeStampSecond = dataSet->GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_timeStampSecondFieldName) );
    fieldSetTimeStampMicrosecond = dataSet->GetFieldSetAsDbl( m_fieldNameEquivalence.Exists(m_timeStampMicrosecondFieldName) );

    // Compute latitude
    if (fieldSetLat != NULL)
    {
      fieldSetLat->m_value = CTools::Plus(fieldSetLat->m_value, 
                                          CTools::Multiply(deltaLat, 
                                                           static_cast<double>(index - m_refPoint)));
    }

    // Compute longitude
    if (fieldSetLon != NULL)
    {
      //fieldSetLon->m_value = CTools::NormalizeLongitude(-180,  
      //                                                  CTools::Plus(fieldSetLon->m_value, 
      //                                                               CTools::Multiply(deltaLon, 
      //                                                                                static_cast<double>(index - m_refPoint))));
      fieldSetLon->m_value = CTools::Plus(fieldSetLon->m_value, 
                                          CTools::Multiply(deltaLon, 
                                                           static_cast<double>(index - m_refPoint)));
    }

    // Compute timestamp
    
    // WARNING -  fieldSetTimeStampSecond, fieldSetTimeStampMicrosecond are converted to SI
    // after they have been read. So their value are stated in seconds
    
    // fieldSetTimeStampSecond = number of seconds from reference SI unit (i.e. 1950-01-01 00:00:00.0)
    
    // fieldSetTimeStampMicrosecond = number of museconds  within the seconds ( < 1 second)
    
    double nbSeconds = 0;

    if (fieldSetTimeStampSecond != NULL)
    {
      nbSeconds = CTools::Plus(nbSeconds, fieldSetTimeStampSecond->m_value);
    }

    if (fieldSetTimeStampMicrosecond != NULL)
    {
      nbSeconds = CTools::Plus(nbSeconds, fieldSetTimeStampMicrosecond->m_value);
    }
    
    nbSeconds = CTools::Plus(nbSeconds, 
                             CTools::Multiply(m_deltaTimeHighResolution, 
                                              static_cast<double>(index - m_refPoint)));
    double seconds;
    double muSeconds;

    CDate timeStamp;
    timeStamp.SetDate(nbSeconds);

    //WARNING At this point,
    // fieldSetTimeStampSecond is stated  in number of seconds and fieldSetTimeStampMicrosecond in numbers of microseconds
    timeStamp.Convert2SM(seconds,
                         muSeconds);

    // WARNING -  fieldSetTimeStampSecond, fieldSetTimeStampMicrosecond are converted to SI
    // after they have been read. So their value are stated in seconds
    //
    //WARNING At this point, muSeconds is stated in numbers of microseconds
    //
    // ====> Convert again muSeconds to a number of seconds     

    if (fieldSetTimeStampSecond != NULL)
    {
      fieldSetTimeStampSecond->m_value = seconds;
    }

    if (fieldSetTimeStampMicrosecond != NULL)
    {
      fieldSetTimeStampMicrosecond->m_value = muSeconds / 1.0E+6;
    }
      

    /*  
    // WARNING -  convert fieldSetTimeStampSecond, fieldSetTimeStampMicrosecond in SI
    // after they have been read. So their value are stated in seconds
    CUnit unit = fieldSetTimeStampSecond->GetField()->GetUnit();
    fieldSetTimeStampSecond->m_value = unit.Convert(fieldSetTimeStampSecond->m_value);

    unit = fieldSetTimeStampMicrosecond->GetField()->GetUnit();
    fieldSetTimeStampMicrosecond->m_value = unit.Convert(fieldSetTimeStampMicrosecond->m_value);
    */
  }

  // Restore current recordset pointer
  dataSet->SetCurrentRecordSet(currentRecordSetOld);
}