int Time::TimeCheck(Time time){ /*1 jika this sebelum time, -1 jika this sesudah time, 0 jika this sama dengan time*/
	if (GetHour() < time.GetHour()){
		return 1;
	}
	else if (GetHour() > time.GetHour()){
		return -1;
	}
	else {/*Tahun sama*/
		if (GetMinute() < time.GetMinute()){
			return 1;
		}
		else if (GetMinute() > time.GetMinute()){
			return -1;
		}
		else{/*Tahun dan bulan sama*/
			if (GetSecond() < time.GetSecond()){
				return 1;
			}
			else if (GetSecond() > time.GetSecond()){
				return -1;
			}
			else{/*Tahun dan bulan dan hari sama*/
				return 0;
			}
		}
	}
}
bool GetTimeInterval(char* time1,char* time2){
	int _t1 = GetSecond(time1);
	int _t2 = GetSecond(time2);
	if(abs(_t1-_t2)<5){
		return true;
	}else
		return false;
}
bool Z_DC_Spread_Policy::GetBarCloseFlag(IKBarSeries* pSeries,MarketDataField* pMD,int time){
	IKBar* _lastbar = pSeries->GetBar(pSeries->m_nCount - 1);
	int _t1 = GetSecond(_lastbar->m_sEndTime);
	int _t2 = GetSecond(pMD->UpdateTime);
	if(_t1 - _t2 <= time){
		return true;
	}
	return false;
}
Exemple #4
0
void XTime::GetTime(XString8 &strTime)
{
	int v=GetDayOfWeek();
	strTime=WeekDay(v);
	v=GetDay();
	if(v<10) strTime+=",0";
	else	 strTime+=",";
	strTime+=v;
	strTime+=' ';
	//v=GetMonth();
	strTime+=Month(GetMonth());
	strTime+=' ';
	strTime+=GetYear();
	strTime+=' ';
	if (this->GetHour()<10)
		strTime+='0';
	strTime+=GetHour();
	strTime+=':';
	if (this->GetMinute()<10)
		strTime+='0';
	strTime+=GetMinute();
	strTime+=':';
	if (this->GetSecond()<10)
		strTime+='0';
	strTime+=GetSecond();
	strTime+=" GMT";
}
Exemple #5
0
Expr* EvalPairp(Env* env, Expr* expr, Expr* cont){
  Expr* ret = malloc(sizeof(Expr));
  ret->type = Bool_Exp;
  ret->u.int_value = ( (Eval(env ,GetSecond(expr), cont))->type == Pair_Exp);
  ret->next = NullList();
  return ret;
}
Exemple #6
0
bool CMyTime::operator>(CMyTime& time)
{
	if(GetYear()>time.GetYear())return true;
	if(GetYear()==time.GetYear())
	{
		if(GetMonth()>time.GetMonth())return true;
		if(GetMonth()==time.GetMonth())
		{
			if(GetDay()>time.GetDay())return true;
			if(GetDay()==time.GetDay())
			{
				if(GetHour()>time.GetHour())return true;
				if(GetHour()==time.GetHour())
				{
					if(GetMinute()>time.GetMinute())return true;
					if(GetMinute()==time.GetMinute())
					{
						if(GetSecond()>time.GetSecond())return true;
					}
				}
			}
		}
	}
	return false;
}
Exemple #7
0
std::string CDateTime::GetLocalTime(std::string filter){
  std::string sOutput;
  std::ostringstream oss;

  if(filter == "MM/DD/YY"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetMonth() << "/" ;
    oss << std::setfill ('0') << std::setw(2);
    oss << GetDay() << "/";
    oss << std::setfill ('0') << std::setw(2);
    oss << (GetYear() - 2000);
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "MM-DD-YYYY"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetMonth() << "/" ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetDay() << "/" << GetYear();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "MM.DD.YYYY"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetMonth() << "." ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetDay() << "." << GetYear();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "HH:MM"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetHour() << ":" ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetMinute();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "HH:MM:SS"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetHour() << ":" ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetMinute() << ":";
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetSecond();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "MONTH D, YYYY"){
    oss << GetMonthName() << " ";
    oss << GetDay() << ", " ;
    //oss << std::setfill ('0') << std::setw(2);
    oss<< GetYear();
    sOutput = oss.str();
    return sOutput;
  }

  return "";
}
Exemple #8
0
uint8_t GetMinute()
{
	return GetSecond();
	uint8_t min,temp;
	//Read the Minute Register
	DS1307Read(0x01,&temp);
	min=(((temp & 0b01110000)>>4)*10)+(temp & 0b00001111);
	return min;
}
Exemple #9
0
void GetCalenderTime(CalenderTime *ct)
{
	ct->second = (uint8_t)GetSecond();
	ct->minute = (uint8_t)GetMinute();
	ct->hour   = (uint8_t)GetHour();
	ct->date   = (uint8_t)GetDate();
	ct->month  = (uint8_t)GetMonth();
	ct->year   = (uint8_t)GetYear();
}
Exemple #10
0
const Char_t *KVDatime::AsGanacqDateString() const
{
   //Return date and time string with format "29-SEP-2005 09:42:17.00"
   //Copy the string immediately if you want to reuse/keep it
   return Form("%d-%s-%4d %02d:%02d:%02d.00",
               GetDay(),
               ((TObjString *) fmonths->At(GetMonth() - 1))->String().
               Data(), GetYear(), GetHour(), GetMinute(), GetSecond());
}
void UKismetMathLibrary::BreakDateTime(FDateTime InDateTime, int32& Year, int32& Month, int32& Day, int32& Hour, int32& Minute, int32& Second, int32& Millisecond)
{
	Year = GetYear(InDateTime);
	Month = GetMonth(InDateTime);
	Day = GetDay(InDateTime);
	Hour = GetHour(InDateTime);
	Minute = GetMinute(InDateTime);
	Second = GetSecond(InDateTime);
	Millisecond = GetMillisecond(InDateTime);
}
Exemple #12
0
MString MTimeSpan::GetString(bool msec/* = true*/) const
{
    TCHAR sz[256];
    if (msec)
    {
        if (GetTotalDays() > 0)
        {
            ::wsprintf(sz, TEXT("%u days and %02u:%02u:%02u.%03u"),
                static_cast<UINT>(GetTotalDays()),
                static_cast<UINT>(GetHour()),
                static_cast<UINT>(GetMinute()),
                static_cast<UINT>(GetSecond()),
                static_cast<UINT>(GetMilliseconds()));
        }
        else
        {
            ::wsprintf(sz, TEXT("%02u:%02u:%02u.%03u"),
                static_cast<UINT>(GetHour()),
                static_cast<UINT>(GetMinute()),
                static_cast<UINT>(GetSecond()),
                static_cast<UINT>(GetMilliseconds()));
        }
    }
    else
    {
        if (GetTotalDays() > 0)
        {
            ::wsprintf(sz, TEXT("%u days and %02u:%02u:%02u"),
                static_cast<UINT>(GetTotalDays()),
                static_cast<UINT>(GetHour()),
                static_cast<UINT>(GetMinute()),
                static_cast<UINT>(GetSecond()));
        }
        else
        {
            ::wsprintf(sz, TEXT("%02u:%02u:%02u"),
                static_cast<UINT>(GetHour()),
                static_cast<UINT>(GetMinute()),
                static_cast<UINT>(GetSecond()));
        }
    }
    return MString(sz);
}
Exemple #13
0
CTime CDate_std::AsCTime(CTime::ETimeZone tz) const
{
    return CTime(GetYear(),
                 CanGetMonth()  ? GetMonth()  : 1,
                 CanGetDay()    ? GetDay()    : 1,
                 CanGetHour()   ? GetHour()   : 0,
                 CanGetMinute() ? GetMinute() : 0,
                 CanGetSecond() ? GetSecond() : 0,
                 0, // nanoseconds, not supported by CDate_std.
                 tz);
}
Exemple #14
0
void setLastModifTime(directory_entry* e, JAM J){
	//asumsi disimpan dalam big endian
	//TODO tanyakan lagi
	
	uint16_t word = (GetHour(J)<<11) | (GetMinute(J)<<5) | (GetSecond(J)/2);

	e->bytearr[0x16] = (word&0xff00) >> 8;
	e->bytearr[0x17] = (word&0x00ff);
	
	return;
}
Exemple #15
0
/* DEFINE */ 
Expr* EvalDefine(Env* env, Expr* expr, Expr* cont){
  Expr* symbol_expr = GetSecond(expr);
  char* symbol = symbol_expr->u.symbol;

  //  Expr* value_expr = get_third(expr);
  Expr* value_expr = Eval(env, GetThird(expr), cont);
//  int value = value_expr->u.int_value;
  Expr* value = value_expr;
  record_expr(env, symbol, value);
  return value;

}
Exemple #16
0
bool Time::operator<(const Time &t2) const {
  if ((GetHour() == t2.GetHour()) &&
      (GetMinute() == t2.GetMinute()) &&
      (GetSecond() < t2.GetSecond()))
    return true;
  else if ((GetHour() == t2.GetHour()) &&
      (GetMinute() < t2.GetMinute()))
    return true;
  else if ((GetHour() < t2.GetHour()))
    return true;

  return false;
}
Exemple #17
0
Expr* EvalMul(Env* env, Expr* expr, Expr* cont){
  int x ,y; 
  Expr *x_expr, *y_expr;
  x_expr = Eval(env, GetSecond(expr), cont);
  x = x_expr->u.int_value;
  y_expr = Eval(env, GetThird(expr), cont);
  y = y_expr->u.int_value;
  printf("%d\n", x * y);
  Expr *ret_val = malloc(sizeof(Expr));
  ret_val->type = Number_Exp;
  ret_val->u.int_value = x * y;
  return ret_val;
}
Exemple #18
0
Expr* EvalPair(Env* env, Expr* expr, Expr* cont){
    expr = expr->u.list;
    //  expr=expr->next;
  if(strcmp(expr->u.symbol, "+") == 0){
    return EvalPlus(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "-") == 0){
    return EvalMinus(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "*") == 0){
    return EvalMul(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "define") == 0){
    return EvalDefine(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "if") == 0){
    return EvalIf(env, expr, cont); 
  }else if(strcmp(expr->u.symbol, "lambda") == 0){
    return EvalLambda(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "halt") == 0){
    //    return expr; // return Halt expression.
    return Eval(env, GetSecond(expr), cont);
  }else if(strcmp(expr->u.symbol, "car") == 0){
    return EvalCar(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "cdr") == 0){
    return EvalCdr(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "null?") == 0){
    return EvalNullp(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "pair?") == 0){
    return EvalPairp(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "list")== 0){
    //    puts("to EvalList");
    Expr* ret = EvalList(env, expr, cont);
    //    puts("from EvalList");
    return ret;
  }else if(strcmp(expr->u.symbol, "let") == 0){
    puts("go let");
    return EvalLet(env, expr, cont);
  }else if(strcmp(expr->u.symbol, "cons") == 0){
    return EvalCons(env ,expr, cont);
  }else if(strcmp(expr->u.symbol, "append") == 0){
    return EvalAppend(env, expr, cont);
  }else if(strcmp(expr->u.symbol, ">") == 0){
    return EvalGT(env, expr, cont);
  }else{
    //    puts("Eval Function");
    char* funcname = expr->u.symbol;
    //    printf("funcname is %s\n", funcname);
    Expr* ret =  EvalFunction(env, expr,  cont);
    return ret;
    //    printf("funcname %s end\n", funcname);
  }
}
Exemple #19
0
Expr* EvalFunction(Env* env, Expr* expr, Expr* cont){
  Expr *args, *body, *function;
  Env new_env;

  //  PrintExpr(expr);
  init_env(&new_env, env); // tmp env, it exists only while executing this function
  //  puts("DEBUG");
  //  PrintExpr(expr);
  //  puts("");



  function = Eval(env, expr, cont);

  //puts("DEBUG2");
  expr = GetSecond(expr); // get real function argument list
  args = get_expr_element(function); // get imaginary function argument list
  body = GetSecond(function); // get imaginary function body

  while(args != NULL){ // set environment
    //    puts("set arg");
    char *symbol = get_symbol_element(args);
    Expr* val_expr = Eval(env, expr, cont);
    //    int value = val_expr->u.int_value;
    record_expr(new_env, symbol, val_expr);
    args = GetSecond(args);
    expr = GetSecond(expr);
  }
  //  Expr*  tmp =lookup_expr_symbol(&new_env, "x");
  //  printf("x is %d\n", tmp->u.int_value);
  //  printf("BODY\n");
  //    PrintExpr(body);
  //  puts("BODYend");

  return EvalPair(&new_env, body, cont);
}
Exemple #20
0
Time Time::operator-(long seconds) const {
  int hour = 0, minute = 0, second = 0;
  long time_in_seconds = GetHour() * 60 * 60 + GetMinute() * 60 + GetSecond() - seconds;

  if (time_in_seconds > 0) {
    hour = time_in_seconds / (60 * 60);
    time_in_seconds = time_in_seconds - hour * (60 * 60);

    minute = time_in_seconds / 60;
    time_in_seconds = time_in_seconds - minute * 60;

    second = time_in_seconds;
  }

  return Time::Create(hour, minute, second);
}
Exemple #21
0
void
AltitudeInfoPanel::Refresh()
{
  const DerivedInfo &calculated = CommonInterface::Calculated();
  const NMEAInfo &basic = CommonInterface::Basic();
  TCHAR sTmp[32];

  RowFormWidget &first = (RowFormWidget &)GetFirst();
  RowFormWidget &second = (RowFormWidget &)GetSecond();

  if (!calculated.altitude_agl_valid) {
    second.SetText(0, _("N/A"));
  } else {
    // Set Value
    FormatUserAltitude(calculated.altitude_agl, sTmp, ARRAY_SIZE(sTmp));
    second.SetText(0, sTmp);
  }

  if (!basic.baro_altitude_available) {
    first.SetText(1, _("N/A"));
  } else {
    // Set Value
    FormatUserAltitude(basic.baro_altitude, sTmp, ARRAY_SIZE(sTmp));
    first.SetText(1, sTmp);
  }

  if (!basic.gps_altitude_available) {
    first.SetText(0, _("N/A"));
  } else {
    // Set Value
    FormatUserAltitude(basic.gps_altitude, sTmp, ARRAY_SIZE(sTmp));
    first.SetText(0, sTmp);
  }

  if (!calculated.terrain_valid){
    second.SetText(1, _("N/A"));
  } else {
    // Set Value
    FormatUserAltitude(calculated.terrain_altitude,
                              sTmp, ARRAY_SIZE(sTmp));
    second.SetText(1, sTmp);
  }
}
Exemple #22
0
Time Time::operator+(long seconds) const {
  int hour = 23, minute = 59, second = 59;

  if (seconds < 23 * 60 * 60 + 59 * 60 + 59) {
    long time_in_seconds = GetHour() * 60 * 60 + GetMinute() * 60 + GetSecond() + seconds;

    if (time_in_seconds < 23 * 60 * 60 + 59 * 60 + 59) {
      hour = time_in_seconds / (60 * 60);
      time_in_seconds = time_in_seconds - hour * (60 * 60);

      minute = time_in_seconds / 60;
      time_in_seconds = time_in_seconds - minute * 60;

      second = time_in_seconds;
    }
  }

  return Time::Create(hour, minute, second);
}
Exemple #23
0
Expr* EvalNullp(Env* env, Expr* expr, Expr* cont){
  Expr* ret = malloc(sizeof(Expr));
  ret->type = Bool_Exp;
  //  printf("%d", (Eval(env, GetSecond(expr), cont))->type);
  Expr* res = Eval(env, GetSecond(expr), cont);
  printf("val ");
  PrintValue(res);
  if(res == NULL){
    printf("NULL");
    ret->u.int_value = 1;
  }else{
    printf(" type %d ", res->type);
    ret->u.int_value = (res->type == Null_Exp);
    if(ret->type == Pair_Exp){
      ret->u.int_value = (res->u.list->type == Null_Exp);
    }
  }
  puts("");
  ret->next = NullList();
  return ret;
}
Exemple #24
0
FString FDateTime::ToString( const TCHAR* Format ) const
{
	FString Result;

	if (Format != nullptr)
	{
		while (*Format != TCHAR('\0'))
		{
			if ((*Format == TCHAR('%')) && (*(++Format) != TCHAR('\0')))
			{
				switch (*Format)
				{
				case TCHAR('a'): Result += IsMorning() ? TEXT("am") : TEXT("pm"); break;
				case TCHAR('A'): Result += IsMorning() ? TEXT("AM") : TEXT("PM"); break;
				case TCHAR('d'): Result += FString::Printf(TEXT("%02i"), GetDay()); break;
				case TCHAR('D'): Result += FString::Printf(TEXT("%03i"), GetDayOfYear()); break;
				case TCHAR('m'): Result += FString::Printf(TEXT("%02i"), GetMonth()); break;
				case TCHAR('y'): Result += FString::Printf(TEXT("%02i"), GetYear() % 100); break;
				case TCHAR('Y'): Result += FString::Printf(TEXT("%04i"), GetYear()); break;
				case TCHAR('h'): Result += FString::Printf(TEXT("%02i"), GetHour12()); break;
				case TCHAR('H'): Result += FString::Printf(TEXT("%02i"), GetHour()); break;
				case TCHAR('M'): Result += FString::Printf(TEXT("%02i"), GetMinute()); break;
				case TCHAR('S'): Result += FString::Printf(TEXT("%02i"), GetSecond()); break;
				case TCHAR('s'): Result += FString::Printf(TEXT("%03i"), GetMillisecond()); break;
				default:		 Result += *Format;
				}
			}
			else
			{
				Result += *Format;
			}

			// move to the next one
			Format++;
		}
	}

	return Result;
}
Exemple #25
0
Expr* EvalLet(Env* env, Expr* expr, Expr* cont){
  Expr* bindings = expr->next;
  Expr* bind;
  Env* new_env = malloc(sizeof(Env));
  init_env(new_env, env);

  PrintExpr(bindings);
  while(bindings != NULL){
      printf("type is %d\n", bindings->type);
    if(bindings->type == Pair_Exp){

      bind = bindings->u.list->u.list;
      char *symbol = get_symbol_element(bind);
      printf("symbolis %s", symbol);
      printf("type is %d\n", bind->next->type);
      Expr* val_expr = Eval(env,dup( bind->next), cont);
       PrintExpr(val_expr);
       
       puts("Bindings");
       PrintExpr(bindings);
       record_expr(new_env, symbol, val_expr);
       puts("Bindings 2");
       PrintExpr(bindings);
    }
    //    puts("aaa");
    //    printf("bindings->next is %d\n", bindings->next == NULL);
    //    printf("next bind expr's type is %d\n", bindings->type);
    puts("DEBUG");
    PrintExpr(bindings);
   bindings = GetSecond(bindings); 
   PrintExpr(bind->next->next);

  }
  puts("out let");
  return Eval(new_env, expr->next->next, cont);
}
CString CSonTime::get_partV(char b)
{
	CString c;
	char a[255];
	int i;

	switch (b)
	{
	case 'A':
		{
			i = GetDayOfWeek();
			switch (i)
			{
				case 1:
					c = "Sunday";
					break;
				case 4:
					c.Format("%s %s","wday",unit_arr[15]);
					break;
				default:
					{
						c.Format("%s",m_pfnV(_itoa(i,a,10)));
						c = c.Right(c.GetLength()-3); 
						c = "wday " + c;
					}
			}			
		}
			break;
	case 'B':
		{
			i = GetMonth();
			switch (i)
			{
				case 4:
					c.Format("%s %s","month",unit_arr[15]);
					break;
				default:
					{
						c.Format("%s",m_pfnV(_itoa(i,a,10)));
						c = c.Right(c.GetLength()-3); 
						c = "month " + c;
					}
			}			
		}
			break;
	case 'd':
		{
			i = GetDay();
			c.Format("%s",m_pfnV(_itoa(i,a,10)));
			c = c.Right(c.GetLength()-3); 
			if (i<11)
				c = "day mg " + c;
			else
				c = "day " + c;			
		}
			break;
	case 'H':
		{	
			c.Format("%s hour",m_pfnV(_itoa(GetHour(),a,10)));
			c = c.Right(c.GetLength()-3); 
		}
			break;
	case 'M':
		{	
			c.Format("%s minute",m_pfnV(_itoa(GetMinute(),a,10)));
			c = c.Right(c.GetLength()-3) ;
		}
			break;
	case 'S':
		{	
			c.Format("%s second",m_pfnV(_itoa(GetSecond(),a,10)));
			c = c.Right(c.GetLength()-3) ;
		}			
			break;
	case 'y':
		{	
			c.Format("%s",m_pfnV(_itoa(GetYear()%100,a,10)));
			c = c.Right(c.GetLength()-3) ;
			c = "year " + c;
		}
			break;
	case 'Y':
		{	
			c.Format("%s",m_pfnV(_itoa(GetYear(),a,10)));
			c = c.Right(c.GetLength()-3) ;
			c = "year " + c;
		}
			break;
	default:
			c = b;
	}
	return c;	
}
CString CSonTime::get_partE(char b)
{
	CString c;
	char a[255];
	int i;
	funcptr pOE = &VS_OrdinalE;
	funcptr pCE = &VS_CardinalE;

	switch (b)
	{
	case 'A':
		{
			c = Format("%A");
		}
			break;
	case 'B':
		{
			c = Format("%B");			
		}
			break;
	case 'd':
		{
			i = GetDay();
			c.Format("%s",pOE(_itoa(i,a,10)));
			c = c.Right(c.GetLength()-3); 			
			c = "the " + c;
		}
			break;

	case 'H':
		{	
			c.Format("%s",pCE(_itoa(GetHour(),a,10)));
			c = c.Right(c.GetLength()-3); 
		}
			break;
	case 'M':
		{	
			c.Format("%s",pCE(_itoa(GetMinute(),a,10)));
			c = c.Right(c.GetLength()-3) ;
		}
			break;
	case 'S':
		{	
			c.Format("%s second",pCE(_itoa(GetSecond(),a,10)));
			c = c.Right(c.GetLength()-3) ;
		}			
			break;
	case 'y':
		{	
			c.Format("%s",pCE(_itoa(GetYear()%100,a,10)));
			c = c.Right(c.GetLength()-3) ;			
		}
			break;
	case 'Y':
		{	
			if ( (i = GetYear()) < 2000)
			{
				CString c1;
				
				c.Format("%s",pCE(_itoa(i/100,a,10)));
				c = c.Right(c.GetLength()-3) ;			

				
				c1.Format("%s",pCE(_itoa(i%100,a,10)));
				c1 = c1.Right(c1.GetLength()-3) ;			

				c = c + " " + c1;
			}
			else
			{
				c.Format("%s",pCE(_itoa(i,a,10)));
				c = c.Right(c.GetLength()-3) ;	
			}
		}
			break;
	default:
			c = b;
	}
	return c;
}
Exemple #28
0
CDate::ECompare CDate_std::Compare(const CDate_std& date) const
{
    if (GetYear() < date.GetYear()) {
        return CDate::eCompare_before;
    } else if (GetYear() > date.GetYear()) {
        return CDate::eCompare_after;
    }

    if ((CanGetSeason()  ||  date.CanGetSeason())
        && ( !CanGetSeason()  ||  !date.CanGetSeason()
            || GetSeason()  !=  date.GetSeason())) {
        return CDate::eCompare_unknown;
    }

    if (CanGetMonth()  ||  date.CanGetMonth()) {
        if ( !CanGetMonth()  ||  !date.CanGetMonth()) {
            return CDate::eCompare_unknown;
        } else if (GetMonth() < date.GetMonth()) {
            return CDate::eCompare_before;
        } else if (GetMonth() > date.GetMonth()) {
            return CDate::eCompare_after;
        }
    }

    if (CanGetDay()  ||  date.CanGetDay()) {
        if ( !CanGetDay()  ||  !date.CanGetDay()) {
            return CDate::eCompare_unknown;
        } else if (GetDay() < date.GetDay()) {
            return CDate::eCompare_before;
        } else if (GetDay() > date.GetDay()) {
            return CDate::eCompare_after;
        }
    }

    if (CanGetHour()  ||  date.CanGetHour()) {
        if ( !CanGetHour()  ||  !date.CanGetHour()) {
            return CDate::eCompare_unknown;
        } else if (GetHour() < date.GetHour()) {
            return CDate::eCompare_before;
        } else if (GetHour() > date.GetHour()) {
            return CDate::eCompare_after;
        }
    }

    if (CanGetMinute()  ||  date.CanGetMinute()) {
        if ( !CanGetMinute()  ||  !date.CanGetMinute()) {
            return CDate::eCompare_unknown;
        } else if (GetMinute() < date.GetMinute()) {
            return CDate::eCompare_before;
        } else if (GetMinute() > date.GetMinute()) {
            return CDate::eCompare_after;
        }
    }

    if (CanGetSecond()  ||  date.CanGetSecond()) {
        if ( !CanGetSecond()  ||  !date.CanGetSecond()) {
            return CDate::eCompare_unknown;
        } else if (GetSecond() < date.GetSecond()) {
            return CDate::eCompare_before;
        } else if (GetSecond() > date.GetSecond()) {
            return CDate::eCompare_after;
        }
    }

    return CDate::eCompare_same;
}
Exemple #29
0
void CDate_std::GetDate(string* label, const string& format) const
{
    static const char* const kMonths[] = {
        "0", "January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"
    };
    static const int kNumMonths = sizeof (kMonths) / sizeof (char*);

    if (!label) {
        return;
    }
    unsigned int                        depth = 0;
    vector<pair<SIZE_TYPE, SIZE_TYPE> > starts;
    starts.push_back(make_pair(label->size(), (SIZE_TYPE)0));
    ITERATE (string, it, format) {
        if (*it != '%') {
            *label += *it;
            continue;
        }
        if (++it == format.end()) {
            NCBI_THROW2(CGeneralParseException, eFormat,
                        "CDate_std::GetDate(): incomplete % expression",
                        it - format.begin());
        }
        // Check for things that can only immediately follow %
        if (*it == '%') {
            *label += '%';
            continue;
        }
        else if (*it == '{') {
            depth++;
            starts.push_back(make_pair(label->size(),
                                       SIZE_TYPE(it - format.begin())));
            continue;
        } else if (*it == '}') {
            if (depth == 0) {
                NCBI_THROW2(CGeneralParseException, eFormat,
                            "CDate_std::GetDate(): unbalanced %}",
                            it - format.begin());
            }
            depth--;
            starts.pop_back();
            continue;
        } else if (*it == '|') {
            // We survived, so just look for the appropriate %}.
            if (depth == 0) {
                return; // Can ignore rest of format
            }
            unsigned int depth2 = 0;
            for (;;) {
                while (++it != format.end()  &&  *it != '%')
                    ;
                if (it == format.end()  ||  ++it == format.end()) {
                    NCBI_THROW2(CGeneralParseException, eFormat,
                                "CDate_std::GetDate(): unbalanced %{",
                                starts.back().second);
                }
                if (*it == '}') {
                    if (depth2 == 0) {
                        depth--;
                        starts.pop_back();
                        break;
                    } else {
                        depth2--;
                    }
                } else if (*it == '{') {
                    depth2++;
                }
            }
            continue;
        }

        unsigned int length = 0;
        int          value  = -1;
        while (isdigit((unsigned char)(*it))) {
            length = length * 10 + *it - '0';
            if (++it == format.end()) {
                NCBI_THROW2(CGeneralParseException, eFormat,
                            "CDate_std::GetDate(): incomplete % expression",
                            it - format.begin());
            }
        }
        switch (*it) {
        case 'Y': value = GetYear(); break;
        case 'M':
        case 'N': value = CanGetMonth()  ? GetMonth()  : -1; break;
        case 'D': value = CanGetDay()    ? GetDay()    : -1; break;
        case 'S': value = CanGetSeason() ? 1           : -1; break;
        case 'h': value = CanGetHour()   ? GetHour()   : -1; break;
        case 'm': value = CanGetMinute() ? GetMinute() : -1; break;
        case 's': value = CanGetSecond() ? GetSecond() : -1; break;
        default:
            NCBI_THROW2(CGeneralParseException, eFormat,
                        "CDate_std::GetDate(): unrecognized format specifier",
                        it - format.begin());
        }

        if (value >= 0) {
            if (*it == 'N') { // special cases
                const char* name;
                if (value >= kNumMonths) {
                    name = "inv";
                } else {
                    name = kMonths[value];
                }
                if (length > 0) {
                    label->append(name, length);
                } else {
                    *label += name;
                }
            } else if (*it == 'S') {
                if (length > 0) {
                    label->append(GetSeason(), 0, length);
                } else {
                    *label += GetSeason();
                }
            } else { // just a number
                if (length > 0) {
                    // We want exactly <length> digits.
                    CNcbiOstrstream oss;
                    oss << setfill('0') << setw(length) << value;
                    string s = CNcbiOstrstreamToString(oss);
                    label->append(s, s.size() > length ? s.size() - length : 0,
                                  length);
                } else {
                    *label += NStr::IntToString(value);
                }
            }
        } else {
            // missing...roll back label and look for alternatives, or
            // throw if at top level and none found
            label->erase(starts.back().first);
            char         request = *it;
            unsigned int depth2  = 0;
            for (;;) {
                while (++it != format.end()  &&  *it != '%')
                    ;
                if (it == format.end()  ||  ++it == format.end()) {
                    if (depth > 0  ||  depth2 > 0) {
                        NCBI_THROW2(CGeneralParseException, eFormat,
                                    "CDate_std::GetDate(): unbalanced %{",
                                    starts.back().second);
                    } else {
                        NCBI_THROW2(CGeneralParseException, eFormat,
                                   string("CDate_std::GetDate():"
                                          " missing required field %")
                                   + request, it - format.begin() - 1);
                    }
                }
                if (*it == '|'  &&  depth2 == 0) {
                    break;
                } else if (*it == '}') {
                    if (depth2 == 0) {
                        if (depth == 0) {
                            NCBI_THROW2(CGeneralParseException, eFormat,
                                        "CDate_std::GetDate(): unbalanced %}",
                                        it - format.begin());
                        }
                        depth--;
                        starts.pop_back();
                        break;
                    } else {
                        depth2--;
                    }
                } else if (*it == '{') {
                    depth2++;
                }
            }
        }
    }
}
Exemple #30
0
bool Time::operator==(const Time &t2) const {
  return (GetHour() == t2.GetHour()) &&
      (GetMinute() == t2.GetMinute()) &&
      (GetSecond() == t2.GetSecond());
}