Beispiel #1
0
bool GregorianDate::setDate(int y, int m, int d) {
	setYear(y);
	setMonth(m);
	setDay(d);
	return 1;
}
Beispiel #2
0
Date::Date(int day, int mon, int year)
{
    setDay(day);
    setMonth(mon);
    setYear(year);
}
Beispiel #3
0
bool rspfLocalTm::setIso8601(const std::string& timeString, bool shiftToGmtOffsetZero)
{
   rspfDate now;
   std::string::size_type pos = 0;
   rspf_int32 year  = 0;
   rspf_int32 month = 0;
   rspf_int32 day   = 0;
   rspf_int32 timeZoneOffset = 0;
   
   if(timeString[0] != 'T') // make sure it's not time only
   {
      // look for year
      //
      if(readIntegerFromString(year,
                               timeString,
                               pos,
                               4))
      {
         // retrieved the year portion
         // now check for separator not digit
         //
         
         // we at least have a year
         // now check for others
         setYear(year);
         if(!isdigit(timeString[pos]))
         {
            // skip separator
            ++pos;
         }
         if(readIntegerFromString(month,
                                  timeString,
                                  pos,
                                  2))
         
         {
            setMonth(month);
            if(!isdigit(timeString[pos]))
            {
               // skip separator
               ++pos;
            }
            if(readIntegerFromString(day,
                                     timeString,
                                     pos,
                                     2))
            {
               setDay(day);
            }
         }
      }
      else
      {
         return false;
      }
   }
   else // set year month day to current
   {
      setYear(now.getYear());
      setMonth(now.getMonth());
      setDay(now.getDay());
   }
   // check to see if we need to read time portion
   if(timeString[pos] == 'T')
   {
      ++pos; // skip T character
      rspf_int32 hours=0, minutes=0;
      
      if(readIntegerFromString(hours,
                               timeString,
                               pos,
                               2))
      {
         setHour(hours);
         
         // now check for separator
         if(!std::isdigit(timeString[pos]))
         {
            ++pos; // skip separator if present
         }
         if(readIntegerFromString(minutes,
                                  timeString,
                                  pos,
                                  2))
         {
            setMin(minutes);
            // now check for time zone if only a hour minute time
            //
            if(timeString[pos] == 'Z')
            {
               // no adjustment needed
            }
            else if(!readTimeZoneOffset(timeZoneOffset,
                                       timeString,
                                       pos))
            {
               double fractionalSeconds = 0.0;
               if(!std::isdigit(timeString[pos]))
               {
                  ++pos;
               }
               std::string::size_type endPos = timeString.find_first_not_of("0123456789.", pos);
               if(endPos == std::string::npos)
               {
                  fractionalSeconds = rspfString(timeString.begin()+pos,
                                                  timeString.end()).toDouble();
               }
               else
               {
                  fractionalSeconds = rspfString(timeString.begin()+pos,
                                                  timeString.begin()+endPos).toDouble();
               }
               setFloatSec(fractionalSeconds);
               pos = endPos;
               if(pos == std::string::npos)
               {
                  // we will not be too strict so if at the end then just return we got enough
                  return true;
               }
               if(timeString[pos] == 'Z')
               {
                  // no adjustment needed
               }
               else
               {
                  readTimeZoneOffset(timeZoneOffset,
                                          timeString,
                                     pos);
               }
            }
         }
      }
      else
      {
         // need at least hours 
         return false;
      }
   }
   else if(std::isdigit(timeString[pos]))
   {
      rspf_int32 hours=0, minutes=0;
      
      if(readIntegerFromString(hours,
                               timeString,
                               pos,
                               2))
      {
         setHour(hours);
         
         // now check for separator
         if(!std::isdigit(timeString[pos]))
         {
            ++pos; // skip separator if present
         }
         if(readIntegerFromString(minutes,
                                  timeString,
                                  pos,
                                  2))
         {
            setMin(minutes);
            
            if(!readTimeZoneOffset(timeZoneOffset,
                                  timeString,
                                  pos))
            {
               double fractionalSeconds = 0.0;
               if(!std::isdigit(timeString[pos]))
               {
                  ++pos;
               }
               std::string::size_type endPos = timeString.find_first_not_of("0123456789.", pos);
               if(endPos == std::string::npos)
               {
                  fractionalSeconds = rspfString(timeString.begin()+pos,
                                                  timeString.end()).toDouble();
               }
               else
               {
                  fractionalSeconds = rspfString(timeString.begin()+pos,
                                                  timeString.begin()+endPos).toDouble();
               }
               setFloatSec(fractionalSeconds);
               pos = endPos;
               if(pos == std::string::npos)
               {
                  // we will not be too strict so if at the end then just return we got enough
                  return true;
               }
               if(timeString[pos] == 'Z')
               {
                  // no adjustment needed
               }
               else
               {
                  readTimeZoneOffset(timeZoneOffset,
                                     timeString,
                                     pos);
               }
            }
         }
      }  
   }
   else
   {
      // need at least hours 
      return false;
   }
   
   if(shiftToGmtOffsetZero && (timeZoneOffset!=0))
   {
      addSeconds(-timeZoneOffset);
   }
   return true;
}
Beispiel #4
0
void cGameDate::fromString( const std::string& arg, eDateFormat format )
{
	LOGICAL success = false;

	if( !arg.empty() )
	{
		UI32 start = 0;
		UI32 index = arg.find_first_of( dateSeparator );

		switch( format )
		{
			case YMD:
				if( index == start + 4 )
				{
					setYear( (UI16) str2num( const_cast<char*>( arg.substr( start, 4 ).c_str() ) ) );
					start = index + 1;
					index = arg.find_first_of( dateSeparator, start );
					if( index == start + 2 )
					{
						setMonth( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
						start = index + 1;
						index = arg.find_first_of( dateTimeSeparator, start );
						if( index == start + 2 )
						{
							setDay( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
							start = index + 1;
							index = arg.find_first_of( timeSeparator, start );
							if( index == start + 2 )
							{
								setHour( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
								start = index + 1;
								setMinute( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
								success = true;
							}
						}
					}
				}
				break;
			case DMY:
				if( index == start + 2 )
				{
					setDay( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
					start = index + 1;
					index = arg.find_first_of( dateSeparator, start );
					if( index == start + 2 )
					{
						setMonth( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
						start = index + 1;
						index = arg.find_first_of( dateTimeSeparator, start );
						if( index == start + 4 )
						{
							setYear( (UI16) str2num( const_cast<char*>( arg.substr( start, 4 ).c_str() ) ) );
							start = index + 1;
							index = arg.find_first_of( timeSeparator, start );
							if( index == start + 2 )
							{
								setHour( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
								start = index + 1;
								setMinute( (UI08) str2num( const_cast<char*>( arg.substr( start, 2 ).c_str() ) ) );
								success = true;
							}
						}
					}
				}
				break;
		}
	}

	if( !success )
		setDefaultDate();
}