Beispiel #1
0
static int cmd_setDate(int argc, char *argv[])
{
	if(argc > 3)
	{
		my_errno = TOO_MANY_ARGUMENTS;
		return 1;
	}
	if(argc < 3 )
	{
		my_errno = TOO_FEW_ARGUMENTS;
		return 1;
	}
	char dest[1024];
	sprintf(dest,"%s %s",argv[1],argv[2]);
	int result = svc_setDateAndTime(dest);
	if(result == 0)
	{
		struct datetime dtime;
		svc_getDateAndTime(&dtime);
		char tempstr[1024];
		sprintf(tempstr,"Current Date and Time : %s %d, %d %02d:%02d:%02d.%d\r\n",
				getMonthName(dtime.month),dtime.day,dtime.year,dtime.hour,
				dtime.minute,dtime.seconds,dtime.msecs);uprintf(tempstr);
	}
	return result;
}
Beispiel #2
0
/**
 * Form the date
 **/
char* setDate() {
	time_t t = time(0);   // get time now
	struct tm * now = localtime(&t);
	char* result = malloc(sizeof(char) * 40 + 1);
	result[40] = '\0';
	// this is not the best possible solution (i can use direclty time.h to format the result)
	char* wday = getWeekDay(now->tm_wday);
	char* month = getMonthName(now->tm_mon + 1);
	sprintf(result, "Date: %s, %d %s %d %d:%d:%d GMT\r\n", wday, now->tm_mday,
			month, now->tm_year + 1900, now->tm_hour, now->tm_min, now->tm_sec);
	return result;
}
Beispiel #3
0
/**
 * Form Last Modified
 **/
char* setModified(struct fileInfo informator) {
	struct stat b;
	char* inf = malloc(sizeof(char) * 100);
	if (!stat(informator.filename, &b)) {
		struct tm *timenfo = localtime(&b.st_mtime);
		char* wday = getWeekDay(timenfo->tm_wday);
		char* month = getMonthName(timenfo->tm_mon + 1);
		sprintf(inf, "Last-Modified: %s, %d %s %d %d:%d:%d GMT \r\n\0", wday,
				timenfo->tm_mday, month, timenfo->tm_year + 1900,
				timenfo->tm_hour, timenfo->tm_min, timenfo->tm_sec);
	}
	return inf;
}
Beispiel #4
0
static int cmd_date(int argc, char *argv[])
/*
*   function definition for date command
*   Parameters:
*       o int argc- number of arguments
*       o char *argv[] - array of arguments  
*   Return : 0 if successful, otherwise 1
*   sets my_errno to TOO_MANY_ARGUMENTS if more than one argument is passed
*/
{
	if(argc > 1)//no arguments allowed, first argument is command name
	{
		my_errno = TOO_MANY_ARGUMENTS;
		return 1;
	}
	struct datetime dtime;
	svc_getDateAndTime(&dtime);
	char tempstr[1024];
	sprintf(tempstr,"%s %d, %d %02d:%02d:%02d.%d\r\n",
			getMonthName(dtime.month),dtime.day,dtime.year,dtime.hour,
			dtime.minute,dtime.seconds,dtime.msecs);uprintf(tempstr);
	return 0;
}
// A function to show menu E.
void showMenuEMonth(int categoryIndex, int yearIndex)
{
	int month;
	int day;
	int expectedRainfallDayListCount;
	
	float expectedRainfall;
	float highestRainfall = 0;
	int highestDay;

	for (month = 0; month < rainfallMonthListGetCapacity(); month++)
	{
		expectedRainfallDayListCount = rainfallDayListCount(categoryIndex, yearIndex, month);

		if (expectedRainfallDayListCount > 0)
		{
			// Algorithm to get the highest rainfall value and its day.
			for (day = 0; day < expectedRainfallDayListCount; day++)
			{
				expectedRainfall = rainfallDayListGetItem(categoryIndex, yearIndex, month, day);

				if (highestRainfall < expectedRainfall)
				{
					highestDay = day + 1;
					highestRainfall = expectedRainfall;
				}
			}

			printf("The highest rainfall for %s is %.1f mm on %d %s.\n", getMonthName(month + 1), highestRainfall, highestDay, getMonthName(month + 1));

			highestRainfall = 0;
			highestDay = 0;
		}
	}

	pause();
}
Beispiel #6
0
/*--------------------------------------------------------------------------
 *
 * Prints the date from a given date/time structure into a string unsign
 * a specific format.
 *
 * Arguments
 * ---------
 *  - buffer  : Pointer to the string to write to.
 *  - format  : Date format to use.
 *  - date    : Structure containing the date to print
 *
 * Returns : The day of week index from 1 to 7. (1=Sunday, 7=Saturday)
 */
uint8_t dateToBuf( char *buffer, uint8_t format, DateTime *date ) {

    uint8_t length;

    switch( format ) {

        case DATE_FORMAT_MMDDYYYY:
            length = sprintf_P( buffer, PSTR( "%02d/%02d/%d" ),
                                date->month(),
                                date->date(),
                                date->year() );
            break;

        case DATE_FORMAT_YYYYMMDD:
            length = sprintf_P( buffer, PSTR( "%d/%02d/%02d" ),
                                date->year(),
                                date->month(),
                                date->date() );
            break;

        case DATE_FORMAT_DDMMMYYYY:
            length = sprintf_P( buffer, PSTR( "%02d-%S-%d" ),
                                date->date(),
                                getMonthName( date->month(), true ),
                                date->year() );
            break;

        case DATE_FORMAT_MMMDDYYYY:
            length = sprintf_P( buffer, PSTR( "%S-%02d-%d" ),
                                getMonthName( date->month(), true ),
                                date->date(),
                                date->year() );
            break;

        case DATE_FORMAT_YYYYMMMDD:
            length = sprintf_P( buffer, PSTR( "%d-%S-%02d" ),
                                date->year(),
                                getMonthName( date->month(), true ),
                                date->date() );
            break;

        case DATE_FORMAT_WDMMMDD:
            length = sprintf_P( buffer, PSTR( "%S, %S %d" ),
                                getDayName( date->dow(), true ),
                                getMonthName( date->month(), true ),
                                date->date() );
            break;

        case DATE_FORMAT_WDMMMDDYYYY:
            length = sprintf_P( buffer, PSTR( "%S, %S %d %d" ),
                                getDayName( date->dow(), true ),
                                getMonthName( date->month(), true ),
                                date->date(),
                                date->year() );
            break;

        /* DATE_FORMAT_DDMMYYYY */
        default:
            length = sprintf_P( buffer, PSTR( "%02d/%02d/%d" ),
                                date->date(),
                                date->month(),
                                date->year() );
            break;
    }

    return length;
}