Esempio n. 1
0
void LogParser::set_latest_log() {
	DIR *dp;
	struct dirent *dirp;
	set<string> sort;

	if(get_day()==log_file) {
		return;
	}

	if((dp=opendir(log_dir.c_str()))==NULL) {
		logger.SendToLog(1, "set_latest_log;Unable to open the directory. Does not exist.");
		return;
	}

	int log_count=0;
	while ((dirp=readdir(dp))!=NULL) {
		sort.insert(dirp->d_name);
		++log_count;
    }

	if(log_count==0) {
		logger.SendToLog(1, "set_latest_log;There is no log file.");
		return;
	}

	log_file=*(sort.end().operator--());

	if(get_day()!=log_file) {
		logger.SendToLog(0, "set_latest_log;Latest file found does not correspond today.");
	}

	closedir(dp);
}
Esempio n. 2
0
int main()
{
  int day_of_wk, month, year, sum, ii;
  day_of_wk = 1; // Sun == 0, Mon == 1, ...
  month     = 0; // Jan == 0, etc
  year   = 1900;
  sum       = 0; 

  /* We know 1 Jan 1900 was a Monday, so, move the calendar forward a year.
  * Separate loop to streamline the larger loop. */
  for (ii = 0; ii < 12; ii++)
    day_of_wk = get_day(day_of_wk, month, year);
  year = 1901;

  while (year < 2001) {
    day_of_wk = get_day(day_of_wk, month, year);
    month++;
    if (day_of_wk == 0)
      sum++;
    if (month == 12)
    {
      month = 0;
      year ++;
    }
  }
  printf("Number of months starting on Sunday in the 20th century: %d\n", sum);
}
Esempio n. 3
0
/*
Main method for program date. use it like: 
	_ "date" for consult current date
	_ "date MMDDhhmm for set month(MM), day(DD), hh (hours) and minute(mm)"
*/
int 
main(int argc,char *argv[])
{
	int fd;
	struct time time;

	if(argc == 1){
		fd=open("rtc",O_RDWR);
		read(fd,&time,1);
		close(fd);
		printf(1,"%s %s %d %d:%d:%d\n",get_day(time.day_of_week), get_month(time.month), to_binary(time.day_of_month),to_binary(time.hours),to_binary(time.minutes),to_binary(time.seconds));
	}else{ 
			if(argc == 2){
				fd=open("rtc",O_RDWR);
				read(fd,&time,1);																
				if (parse_time(argv[1],&time) == 0){												
					if(is_valid(&time))
						write(fd,&time,1);
					else
						printf(1,"The date isn't valid.\n");
					close(fd);						
				}else					
					printf(1,err_msg);
			}else
				printf(1,err_msg);				
	}
	exit();
}
oldgaa_error_code PRIVATE
oldgaa_evaluate_day_cond(oldgaa_conditions_ptr condition,
                         UNUSED(oldgaa_options_ptr    options))

{
    int            retval, j=0;
    oldgaa_error_code oldgaa_status = OLDGAA_NO;

    char *day = NULL, *str1 = NULL, *str2 = NULL, cond[MAX_COND_LENGTH] = {NUL};
    char *current_day = NULL;
    char *value;

    strcpy(cond, condition->value);

    /* get current day */
    current_day = get_day();
    day = oldgaa_strcopy(current_day, day);
    free(current_day);

    /* get first day delimiter */
    str1 = oldgaa_strcopy(get_value(&j, cond, '-'), str1);

    /* get second day delimiter */
    value = get_value(&j, cond, NUL);
    str2 = oldgaa_strcopy(value, str2);
    free(value);

    retval = check_day(str1, str2, day);

    if(retval == -1) return OLDGAA_MAYBE; /* unsupported day format */

    if(retval == 1) oldgaa_status = OLDGAA_YES;

    return oldgaa_status;
}
Esempio n. 5
0
int		part2(char *dir_path, char *prenom, t_individu **individu)
{
  t_individu	*temp;

  temp = *individu;
  while (temp)
    {
      if (strcmp(temp->prenom, prenom) == 0)
	{
	  printf("%s %s\n", prenom, last_name(dir_path));
	  printf("né le %i %s %i (%i)\n", get_day(temp->date),
		 get_month(temp->date), atoi(&temp->date[6]), temp->cp);
	  if (temp->sexe == 0)
	    printf("de sexe masculin\n");
	  else
	    printf("de sexe feminin\n");
	  printf("%i %s%c%c %i %i\n", temp->sexe + 1, &temp->date[8], temp->date[3],
		 temp->date[4], temp->cp, temp->secu);
	  printf("%s", temp->cv);
	  return (0);
	}
      temp = temp->next;
    }
  fprintf(stderr, "Erreur: Il n'y a pas de %s dans la famille %s!\n",
	  prenom, last_name(dir_path));
  return (1);
}
Esempio n. 6
0
std::string DateTime::to_short_date_string() const
{
	throw_if_null();
	StringFormat format("%1-%2-%3");
	format.set_arg(1, get_year(), 4);
	format.set_arg(2, get_month(), 2);
	format.set_arg(3, get_day(), 2);
	return format.get_result();
}
static int sprd_rtc_set_sec(unsigned long secs)
{
	unsigned sec, min, hour, day;
	unsigned set_mask = 0, int_rsts;
	unsigned long temp;
	int i = 0;

	sec = secs % 60;
	temp = (secs - sec)/60;
	min = temp%60;
	temp = (temp - min)/60;
	hour = temp%24;
	temp = (temp - hour)/24;
	day = temp;


	sci_adi_set(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK);

	if(sec != get_sec()){
		sci_adi_raw_write(ANA_RTC_SEC_UPDATE, sec);
		set_mask |= RTC_SEC_ACK_BIT;
	}
	if(min != get_min()){
		sci_adi_raw_write(ANA_RTC_MIN_UPDATE, min);
		set_mask |= RTC_MIN_ACK_BIT;
	}
	if(hour != get_hour()){
		sci_adi_raw_write(ANA_RTC_HOUR_UPDATE, hour);
		set_mask |= RTC_HOUR_ACK_BIT;
	}
	if(day != get_day()){
		sci_adi_raw_write(ANA_RTC_DAY_UPDATE, day);
		set_mask |= RTC_DAY_ACK_BIT;
	}

	/*
	 * wait till all update done
	 */

	do{
		int_rsts = sci_adi_read(ANA_RTC_INT_RSTS) & RTC_UPD_TIME_MASK;

		if(set_mask == int_rsts)
			break;

		if(i < SPRD_RTC_SET_MAX){
			msleep(1);
			i++;
		}else{
			return 1;
		}
	}while(1);
	sci_adi_set(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK);

	return 0;
}
Esempio n. 8
0
std::string DateTime::to_short_datetime_string() const
{
	throw_if_null();
	// 2008-04-01
	StringFormat format("%1-%2-%3 %4:%5:%6");
	format.set_arg(1, get_year(), 4);
	format.set_arg(2, get_month(), 2);
	format.set_arg(3, get_day(), 2);
	format.set_arg(4, get_hour(), 2);
	format.set_arg(5, get_minutes(), 2);
	format.set_arg(6, get_seconds(), 2);
	return format.get_result();
}
Esempio n. 9
0
int main(int argc, const char * argv[])
{

    // insert code here...
//    printf("Hello, World!\n");
    int n;
    puts("plase input a value in 1-7");
    scanf("%d", &n);
    char * ch = get_day(n);
    puts(ch);
    
    return 0;
}
Esempio n. 10
0
int main(void)
{
	T_DATE *pdate=NULL;
	//pdate=(T_DATE *)malloc(sizeof(T_DATE));	// error: invalid application of ‘sizeof’ to incomplete type ‘T_DATE’
	init_date(&pdate);
	set_date(pdate,10,7,2013);
	printf("%d-%d-%d\n",get_month(pdate),get_day(pdate),get_year(pdate));
	//printf("%d-%d-%d\n",pdate->month,pdate->day,pdate->year);// error: dereferencing pointer to incomplete type
	
	free_date(pdate);
	
	return 0;
}
Esempio n. 11
0
static unsigned long sprd_rtc_get_sec(void)
{
	unsigned sec, min, hour, day;
	unsigned second = 0;

	sec = get_sec();
	min = get_min();
	hour = get_hour();
	day = get_day();

	second = ((((day*24) + hour)*60 + min)*60 + sec);

	return second;
}
Esempio n. 12
0
time_t
Date::get_ctime( const Date::date_t d )
{
    time_t t;
    time( &t );
    struct tm* timeinfo = localtime( &t );
    timeinfo->tm_year = get_year( d ) - 1900;
    timeinfo->tm_mon = get_month( d ) - 1;
    timeinfo->tm_mday = get_day( d );
    timeinfo->tm_hour = 0;
    timeinfo->tm_min = 0;
    timeinfo->tm_sec = 0;

    return( mktime( timeinfo ) );
}
Esempio n. 13
0
static BOOL time_char_to_BCD(DS1390_TIME *time , DS1390_DATA_BUF *data)
{
    data->msec = char_to_BCD(time->msec);
    data->sec = char_to_BCD(time->sec);
    data->min = char_to_BCD(time->min);
    data->hour = char_to_BCD(time->hour);
    data->day = get_day(time);
    data->date = char_to_BCD(time->date);
    data->month = char_to_BCD(time->month);
    data->year = char_to_BCD(time->year%100);

    if (time->year >= 2100)
        data->month |= 0x80;

   return TRUE;
}
Esempio n. 14
0
void date_to_words(Language lang, int day, int date, int month, char* words, size_t buffer_size) {
  size_t remaining = buffer_size;
  memset(words, 0, buffer_size);
  
  const char* stringday = get_day(lang, day);
  const char* stringmonth = get_month(lang, month);
  
  char stringdate[15];
  itoa10(date, stringdate);
  
  remaining -= append_string(words, remaining, stringday);
  remaining -= append_string(words, remaining, "  ");
  remaining -= append_string(words, remaining, stringmonth);
  remaining -= append_string(words, remaining, " ");
  remaining -= append_string(words, remaining, stringdate);
  remaining -= append_string(words, remaining, " ");
}
Esempio n. 15
0
void sprd_rtc_set_sec(unsigned long secs)
{
	unsigned sec, min, hour, day;
    unsigned set_mask = 0, int_rsts;
	unsigned long temp;

	sec = secs % 60;
	temp = (secs - sec)/60;
	min = temp%60;
	temp = (temp - min)/60;
	hour = temp%24;
	temp = (temp - hour)/24;
	day = temp;


    ANA_REG_OR(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK);

    if(sec != get_sec()){
        ANA_REG_SET(ANA_RTC_SEC_UPDATE, sec);
        set_mask |= RTC_SEC_ACK_BIT;
    }
    if(min != get_min()){
        ANA_REG_SET(ANA_RTC_MIN_UPDATE, min);
        set_mask |= RTC_MIN_ACK_BIT;
    }
    if(hour != get_hour()){
        ANA_REG_SET(ANA_RTC_HOUR_UPDATE, hour);
        set_mask |= RTC_HOUR_ACK_BIT;
    }
    if(day != get_day()){
        ANA_REG_SET(ANA_RTC_DAY_UPDATE, day);
        set_mask |= RTC_DAY_ACK_BIT;
    }

    //wait till all update done

    do{
        int_rsts = ANA_REG_GET(ANA_RTC_INT_RSTS) & RTC_UPD_TIME_MASK;

        if(set_mask == int_rsts)
          break;
    }while(1);
    ANA_REG_OR(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK);

	return;
}
Esempio n. 16
0
//------------------------------------------------------------------------------
static BOOL time_BCD_to_char(DS1390_DATA_BUF *data , DS1390_TIME *time)
{

    unsigned char i;
    signed char b;

    for (i =0; i<sizeof(true_mask); i++)
    {
        b = BCD_to_char(*(((unsigned char *)data)+i) & true_mask[i]);
        if (b == -1 || b<true_min[i] || (b>true_max[i]))
            return FALSE;
        *(((unsigned char *)data)+i) = b;
    }

    time->msec = data->msec*10;
    time->sec  = data->sec;
    time->min  = data->min;
    time->hour = data->hour;
    time->day  = data->day;
    time->date = data->date;
    time->month= data->month;
    time->year = data->year;


    if (time->month > 80)
    {
        time->year +=2100;
        time->month -= 80;
    }
    else
        time->year +=2000;


    if (get_day(time) != time->day)
        return FALSE;

    if (time->month == 2 && (time->year % 4 == 0 && time->year % 100 != 0 || time->year % 400 == 0))
    {
        if (time->date > max_date[time->month-1]+1)
            return FALSE;
    }else
        if (time->date > max_date[time->month-1])
            return FALSE;

    return TRUE;
}
Esempio n. 17
0
unsigned long sprd_rtc_get_sec(void)
{
	unsigned sec, min, hour, day;
	unsigned first = 0, second = 0;

	do {
		sec = get_sec();
		min = get_min();
		hour = get_hour();
		day = get_day();

		second = ((((day*24) + hour)*60 + min)*60 + sec);
		if((second - first) == 0)
			break;
		first = second;
	}while(1);
	return first;
}
Esempio n. 18
0
std::string DateTime::to_string() const
{
	throw_if_null();
	// Mon Feb 3 12:32:54 2008
	std::string months[] =
	{
		"Jan",
		"Feb",
		"Mar",
		"Apr",
		"May",
		"Jun",
		"Jul",
		"Aug",
		"Sep",
		"Oct",
		"Nov",
		"Dec"
	};
	
	std::string days[] =
	{
		"Sun",
		"Mon",
		"Tue",
		"Wed",
		"Thu",
		"Fri",
		"Sat"
	};

	StringFormat format("%1 %2 %3 %4:%5:%6 %7");
	format.set_arg(1, days[get_day_of_week()]);
	format.set_arg(2, months[get_month() - 1]);
	format.set_arg(3, get_day());
	format.set_arg(4, get_hour(), 2);
	format.set_arg(5, get_minutes(), 2);
	format.set_arg(6, get_seconds(), 2);
	format.set_arg(7, get_year());
	return format.get_result();
}
//---------------------------------------------------------------------------------------
//Output Date (dd-mm-yy) & Time (hh:mm:ss)
int output_date_time(void){
	// Get the current date and time
	ds1307_read_date_time();
	// Get binary values + convert to ascii string
	bin_to_ascii(get_seconds(), secondASCII);
	bin_to_ascii(get_minutes(), minuteASCII);
	bin_to_ascii(get_hours(), hourASCII);
	bin_to_ascii(get_day(), dayASCII);
	bin_to_ascii(get_month(), monthASCII);
	bin_to_ascii(get_year(), yearASCII);
	// Send to LCD
	lcd_send_cmd(LINE1);
	lcd_printf(hourASCII); lcd_printf(":");
	lcd_printf(minuteASCII); lcd_printf(":");
	lcd_printf(secondASCII);
	lcd_send_cmd(LINE2);
	lcd_printf(dayASCII); lcd_printf("-");
	lcd_printf(monthASCII); lcd_printf("-");
	lcd_printf(yearASCII);
		
	return 0;
}
Esempio n. 20
0
int main(int argc, char* argv[]){

	int year, month, day;

	year = get_year("Please Input the Year: ");
	month = get_month("the Month: ");
	day = get_day("the Day: ", year, month);

	if( is_leap(year) ){
		months[1] = 29;
	}

	int i, days = 0;
	
	for(i = 0; i < month - 1; i++){
		days += months[i];
	}

	days += day;

	printf("%d.%d.%d is the %d days of this year.\n", year, month, day, days);

	return 0;
}
Esempio n. 21
0
Ustring
Date::get_weekday_str() const
{
    // from wikipedia: http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
    const unsigned int year = get_year();
    const unsigned int century = ( year - ( year % 100 ) ) / 100;
    int c = 2 * ( 3 - ( century % 4 ) );
    int y = year % 100;
    y = y + floor( y / 4 );

    static const int t_m[] = { 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 };
    struct tm ti;

    int m = get_month() - 1;
    int d = ( c + y + t_m[ m ] + get_day() );

    if( !( get_year() % 4 ) && m < 2 )  // leap year!
        d += 6;

    ti.tm_wday = ( d % 7 );
    char buf[ 32 ];
    strftime( buf, 32, "%A", &ti );
    return Ustring( buf );
}
Esempio n. 22
0
void interpret(commandline c, Schedule* s) {
	switch (to_command(c.function)) {
		case QUIT:
			std::cout<<"Bye bye !"<<std::endl ;
			break ;
		
		case HELP:
			if (c.args.size() == 0) {
				help(HELP) ;
			} else {
				help(to_command(c.args[0])) ;
			}
			break ;

		case IMPORT:
			if (check_args(c, 2, 0)) {
				std::string schedule = 	c.args[0] ;
				std::string dotations = c.args[1] ;
			 s->import_html(schedule, dotations) ;
			}
			break ;
		case ADDTEACHER:
			for (std::vector<std::string>::iterator it=c.args.begin() ; 
				it!=c.args.end() ; it++) {
			 s->add_teacher(*it) ;
			}
			break ;
		case LISTTEACHER:
			if(check_args(c, 0, 0)) {
			 s->list_teachers() ;
			}
			break ;
		case LISTGROUP:
			if(check_args(c, 0, 0)) {
			 s->list_groups() ;
			}
			break ;
		case DISPLAY:
			if(check_args(c, 1, 1)) {
				std::string name = addspace(c.args[0]) ;
				int semester = handle_options(c.options) ;
                s->display(name, semester) ;
			}
			break ;
		case ASSIGN:
			{
				std::string teacher = addspace(c.args[0]) ;
                c.args.erase(c.args.begin()) ;
				int semester = handle_options(c.options) ;
                s->assign(teacher, c.args, semester) ;
			}
			break ;
		case UNASSIGN:
			if(check_args(c, 1, 1)) {
				std::string group = c.args[0] ;
				int semester = handle_options(c.options) ;
                s->unassign(group, semester) ;
			}
			break ;
		case UNASSIGNED:
			if(check_args(c, 0, 1)) {
				int semester = handle_options(c.options) ;
                s->unassigned_groups(semester) ;
			}
			break ;
		case COMPATIBLE:
			if(check_args(c, 1, 1)) {
				std::string name = addspace(c.args[0]) ;
				int semester = handle_options(c.options) ;
                s->compatible(name, semester) ;
			}
			break ;
		case COMPATIBLE2:
			if(check_args(c, 1, 1)) {
				std::string name = c.args[0] ;
				int semester = handle_options(c.options) ;
                s->compatible2(name, semester) ;
			}
			break ;
		case COMPATIBLEOMSI:
			if(check_args(c, 1, 1)) {
				std::string name = c.args[0] ;
				int semester = handle_options(c.options) ;
                s->compatible_omsi(name, semester) ;
			}
			break ;

		case DELETETEACHER:
			if(check_args(c, 1, 0)) {
				std::string name = c.args[0] ;
			 s->delete_teacher(name) ;
			}
			break ;
		case INDISP:
			if (check_args(c, 4, 1)) {
				std::string name = addspace(c.args[0]) ;
				int day = get_day(c.args[1]) ;
				int h_begin = get_hour(c.args[2]) ;
				int h_end = get_hour(c.args[3]) ;
				int semester = handle_options(c.options) ;
                s->indisp(name, semester, day, h_begin, h_end) ;
			}
			break ;
		case DISP:
			if (check_args(c, 4, 1)) {
				std::string name = c.args[0] ;
				int day = get_day(c.args[1]) ;
				int h_begin = get_hour(c.args[2]) ;
				int h_end = get_hour(c.args[3]) ;
				int semester = handle_options(c.options) ;
                s->disp(name, semester, day, h_begin, h_end) ;
			}
			break ;

		default:
			std::cout<<"Unrecognized command, try again !"<<std::endl ;
	}
}
Esempio n. 23
0
int validate_avg_min_or_max(char * query) {
    char * command;
    command = (char *)calloc(11, sizeof(char));
    char * header;
    header = (char *)calloc(17, sizeof(char));
    char * header_word_2;
    header_word_2 = (char *)calloc(4, sizeof(char));
    char * header_word_3;
    header_word_3 = (char *)calloc(2, sizeof(char));
    char * start_date;
    start_date = (char *)calloc(17, sizeof(char));
    char * end_date;
    end_date = (char *)calloc(19, sizeof(char));
    
    // count whitespace in query to determine if header is multiple words
    int query_length = (int)strlen(query);
    int num_spaces = 0;
    for (int i=0; i<query_length; i++) {
        if (query[i] == ' ') {
            num_spaces++;
        }
    }
    if (num_spaces == 5) {
        sscanf(query, "%s %s %s %s %s %s", command, header, header_word_2, header_word_3, start_date, end_date);
        for (int i=0; i<40; i++) {
            if (header[i] == '\0') {
                header[i] = ' ';
                for (int k=0; k<40; k++) {
                    if (header_word_2[k] != '\0') {
                        header[i+k+1] = header_word_2[k];
                    } else {
                        header[i+k+1] = ' ';
                        header[i+k+2] = header_word_3 [0];
                        header[i+k+3] = '\0';
                        break;
                    }
                }
                break;
            }
        }
    } else if (num_spaces == 4) {
        sscanf(query, "%s %s %s %s %s", command, header, header_word_2, start_date, end_date);
        for (int i=0; i<40; i++) {
            if (header[i] == '\0') {
                header[i] = ' ';
                for (int k=0; k<40; k++) {
                    if (header_word_2[k] != '\0') {
                        header[i+k+1] = header_word_2[k];
                    } else {
                        break;
                    }
                }
                break;
            }
        }
    } else {
        sscanf(query, "%s %s %s %s", command, header, start_date, end_date);
    }
    
    // check if <header> is valid. Must contain numerical values only. Must be a string.
    Type_t data_type;
    data_type = column_type(header);
    if (data_type == UNKNOWN || data_type == STRING || data_type == CHAR) {
        printf("ERROR invalid query: %s\nreason: %s is not valid", query, header);
        return 0;
    }
    
    // check if <start date/time> and <end date/time> are valid. Must be mm/dd/yyyy-hh:mm eg: 02/22/1995-22:57
    if (strlen(start_date) != 16 || get_month(start_date) <= 0 || get_month(start_date) > 12 || get_day(start_date) <= 0 || get_day(start_date) > 31 || get_hour(start_date) < 0 || get_hour(start_date) > 23 || get_minute(start_date) < 0 || get_minute(start_date) > 59) {
        printf("ERROR invalid query: %s\nreason: %s is an invalid start date \n", query, start_date);
        return 0;
    }
    if (strlen(end_date) != 16 || get_month(end_date) <= 0 || get_month(end_date) > 12 || get_day(end_date) <= 0 || get_day(end_date) > 31 || get_hour(end_date) < 0 || get_hour(end_date) > 23 || get_minute(end_date) < 0 || get_minute(end_date) > 59) {
        printf("ERROR invalid query: %s\nreason: %s is an invalid end date \n", query, end_date);
        return 0;
    }
    
    return 1;
}
Esempio n. 24
0
// 0 for no, 1 for yes
int is_in_range(char * start_date_string, char * end_date_string, long * date_column, int * time_column) {
    
    int start_month = get_month(start_date_string);
    int start_day = get_day(start_date_string);
    int start_year = get_year(start_date_string);
    int start_hour = get_hour(start_date_string);
    int start_minute = get_minute(start_date_string);
    
    int end_month = get_month(end_date_string);
    int end_day = get_day(end_date_string);
    int end_year = get_year(end_date_string);
    int end_hour = get_hour(end_date_string);
    int end_minute = get_minute(end_date_string);
    
    int row_year = ((int)*date_column) / 10000;
    int row_month = ((int)*date_column) / 100;
    row_month = row_month % 100;
    int row_day =((int)*date_column) % 100;
    
    if (*time_column > 2359 || *time_column < 0) {
        return -1;
    }
    
    int row_hour = *time_column / 100;
    int row_minute = *time_column % 100;

    if (start_year > end_year) {
        return -1;
    }
    if (start_year == end_year && start_month > end_month) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day > end_day) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour > end_hour) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour == end_hour && start_minute > end_minute) {
        return -1;
    }
    
    // check if measurement was taken after start time, if not return 0
    if (row_year >= start_year) {
        if (row_year == start_year) {
            if (row_month >= start_month) {
                if (row_month == start_month) {
                    if (row_day >= start_day) {
                        if (row_day == start_day) {
                            if (row_hour >= start_hour) {
                                if (row_hour == start_hour) {
                                    if (row_minute >= start_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    if (row_year <= end_year) {
        if (row_year == end_year) {
            if(row_month <= end_month) {
                if (row_month == end_month) {
                    if (row_day <= end_day) {
                        if (row_day == end_day) {
                            if (row_hour <= end_hour) {
                                if (row_hour == end_hour) {
                                    if (row_minute <= end_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    return 1;
}
Esempio n. 25
0
int del_oldest_file_ext_fun()
{
	int i = 0;
	int j = 0;
	int ret = 0;
	int year = 0;
	int month = 0;
	int day = 0;
	int hour = 0;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day, cur_hour;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year = get_year();		//获取当前时间-
	cur_month = get_month();	//获取当前时间-
	cur_day = get_day();		//获取当前时间-
	cur_hour = get_hour();

	do
	{
#ifdef SD_STORAGE
		
#endif

#if 1
		ret = get_oldest_time(&year, &month, &day, &hour);
		if (ret != 0)
		{
			del_file_status = -1;
			break;
		}
#endif		
		printf("the old time: %d %d %d %d\n", year, month, day, hour);
		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 || hour<0 || hour>=24)
		{
			del_file_status = -2;
			break;
		}
		/*
		//
		if (year == cur_year && month == cur_month && day == cur_day && hour == cur_hour)
		{
			del_file_status = -3;
			break;
		}
		*/

#ifdef SD_STORAGE
		for (j=0; j<channel_num; j++)
		{
			sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
			//printf("Delete: %s\n", dir_name);
			delete_dir(dir_name);
		}
#else
		//
		disk_num = get_hard_disk_num();
		
		for (i=0; i<disk_num; i++)
		{
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
				delete_dir(dir_name);
			}
		}
#endif
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	return 0;
}
Esempio n. 26
0
        InputIterator get(
            iter_type b, iter_type e,
            std::ios_base& iob,
            std::ios_base::iostate& err,
            std::tm* tm,
            char fmt, char) const
        {
            err = std::ios_base::goodbit;
            const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(iob.getloc());

            switch (fmt)
            {
            case 'a':
            case 'A':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_weekday(b, e, iob, err, &tm2);
                //tm->tm_wday = tm2.tm_wday;
              }
              break;
            case 'b':
            case 'B':
            case 'h':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_monthname(b, e, iob, err, &tm2);
                //tm->tm_mon = tm2.tm_mon;
              }
              break;
//            case 'c':
//              {
//                const string_type& fm = c();
//                b = get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
            case 'd':
            case 'e':
              get_day(tm->tm_mday, b, e, err, ct);
              break;
            case 'D':
              {
                const char_type fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'F':
              {
                const char_type fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'H':
              get_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'I':
              get_12_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'j':
              get_day_year_num(tm->tm_yday, b, e, err, ct);
              break;
            case 'm':
              get_month(tm->tm_mon, b, e, err, ct);
              break;
            case 'M':
              get_minute(tm->tm_min, b, e, err, ct);
              break;
            case 'n':
            case 't':
              get_white_space(b, e, err, ct);
              break;
//            case 'p':
//              get_am_pm(tm->tm_hour, b, e, err, ct);
//              break;
            case 'r':
              {
                const char_type fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'R':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'S':
              get_second(tm->tm_sec, b, e, err, ct);
              break;
            case 'T':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'w':
              {
                get_weekday(tm->tm_wday, b, e, err, ct);
              }
              break;
            case 'x':
              return that_.get_date(b, e, iob, err, tm);
//            case 'X':
//              return that_.get_time(b, e, iob, err, tm);
//              {
//                const string_type& fm = X();
//                b = that_.get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
//            case 'y':
//              get_year(tm->tm_year, b, e, err, ct);
                break;
            case 'Y':
              get_year4(tm->tm_year, b, e, err, ct);
              break;
            case '%':
              get_percent(b, e, err, ct);
              break;
            default:
                err |= std::ios_base::failbit;
            }
            return b;
        }
Esempio n. 27
0
/******************************************************************************
* 函数名称:del_oldest_file_fun
* 功能描述:以天为单位删除最老的录像文件(线程实现函数)
*
*
*
* 修改记录:
* 其他说明:
********************************************************************************/
int del_oldest_file_fun()
{
	int  i,j;
	int  ret;
	int  year,month,day;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year   = get_year();	//获取当前时间-
	cur_month  = get_month();	//获取当前时间-
	cur_day    = get_day();		//获取当前时间-

	do
	{
		ret = get_oldest_date(&year, &month, &day);
		if (ret != 0)
		{
			printf("get_oldest_date: Failed!\n");
			del_file_status = -1;
			break;
		}

		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 )
		{
			del_file_status = -2;
			break;
		}

		//
		if (year == cur_year && month == cur_month && day == cur_day )
		{
			del_file_status = -3;
			break;
		}

#ifdef SD_STORAGE
		disk_num = 1;
#else
		//
		disk_num = get_hard_disk_num();
#endif
		
		for (i=0; i<disk_num; i++)
		{
#ifdef SD_STORAGE

#else
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}
#endif

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d",i,0,j,year,month,day);
				printf("Delete the oldest file: %s\n", dir_name);
				delete_dir(dir_name);
			}
		}
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	//pthread_exit(NULL);

	return 0;
}